แปลง Word เป็น PowerPoint Presentation โดยใช้ Node.js

แปลง Word เป็น PowerPoint Presentation โดยใช้ Node.js

แปลง Word เป็น PowerPoint PPT หรือ PPTX โดยทางโปรแกรมบนคลาวด์ ในฐานะนักพัฒนา Node.js คุณสามารถแปลง Word เป็น PowerPoint PPTX ทางออนไลน์ได้อย่างง่ายดายในแอปพลิเคชัน Node.js ของคุณ ในบทความนี้ เราจะสาธิตวิธีการแปลง Word เป็น PowerPoint Presentation โดยใช้ Node.js

หัวข้อต่อไปนี้จะครอบคลุมในบทความนี้:

Word เป็น PowerPoint Conversion REST API และ Node.js SDK

ฉันจะใช้ Node.js SDK ของ GroupDocs.Conversion Cloud API สำหรับการแปลง DOCX เป็น PPTX/PPTX API ช่วยให้คุณสามารถแปลงเอกสารเป็นรูปแบบใดก็ได้ที่คุณต้องการ รองรับการแปลงเอกสารและรูปภาพมากกว่า 50 ประเภท เช่น Word, Excel, PowerPoint, PDF, HTML, JPG, PNG, CAD นอกจากนี้ยังมี .NET, Java, PHP, Ruby, Android และ Python SDK เป็น สมาชิกตระกูลการแปลงเอกสาร สำหรับ Cloud API

คุณสามารถติดตั้ง GroupDocs.Conversion Cloud ลงในแอปพลิเคชัน Node.js ของคุณโดยใช้คำสั่งต่อไปนี้ในคอนโซล:

npm install groupdocs-conversion-cloud

โปรดรับรหัสไคลเอ็นต์และรหัสลับไคลเอ็นต์ของคุณจาก แดชบอร์ด ก่อนที่คุณจะเริ่มทำตามขั้นตอนและตัวอย่างโค้ดที่มีอยู่ เมื่อคุณมี ID และรหัสลับของคุณแล้ว ให้เพิ่มรหัสตามที่แสดงด้านล่าง:

# นำเข้า Node.js SDK ในแอปพลิเคชันโหนดของคุณจาก http://api.groupdocs.cloud
global.groupdocs_conversion_cloud = require("groupdocs-conversion-cloud");
global.fs = require("fs");

// รับ clientId และ clientSecret จาก https://dashboard.groupdocs.cloud (ต้องลงทะเบียนฟรี)
global.clientId = "xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx";
global.clientSecret = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
global.myStorage = "test-internal-storage";
const config = new groupdocs_conversion_cloud.Configuration(clientId, clientSecret);
config.apiBaseUrl = "https://api.groupdocs.cloud";

วิธีแปลงรูปแบบไฟล์ Word เป็น PowerPoint โดยใช้ Node.js API

คุณสามารถแปลงไฟล์ word เป็นไฟล์ ppt หรือ pptx โดยทำตามขั้นตอนง่าย ๆ ด้านล่าง:

  1. อัปโหลด ไฟล์ PowerPoint ไปยังคลาวด์
  2. แปลง DOCX เป็น PPTX ออนไลน์ใน Node.js
  3. ดาวน์โหลด ไฟล์ PowerPoint ที่แปลงแล้ว

อัปโหลดไฟล์

ขั้นแรก อัปโหลดไฟล์ Word ไปยัง Cloud โดยใช้ตัวอย่างโค้ดต่อไปนี้:

// เปิดไฟล์ใน IOStream จากไดรฟ์ระบบของคุณ
var resourcesFolder = 'H:\\groupdocs-cloud-data\\sample-file.docx';
// อ่านไฟล์
fs.readFile(resourcesFolder, (err, fileStream) => {
  // สร้าง FileApi
  var fileApi = groupdocs_conversion_cloud.FileApi.fromConfig(config);
  // สร้างคำขออัปโหลดไฟล์
  var request = new groupdocs_conversion_cloud.UploadFileRequest("sample-file.docx", fileStream, myStorage);
  // อัพโหลดไฟล์
  fileApi.uploadFile(request)
    .then(function (response) {
      console.log("Expected response type is FilesUploadResult: " + response.uploaded.length);
    })
    .catch(function (error) {
      console.log("Error: " + error.message);
    });
});

ด้วยเหตุนี้ ไฟล์คำที่อัปโหลดจะอยู่ใน ส่วนไฟล์ ของแดชบอร์ดของคุณบนระบบคลาวด์

แปลง Word เป็น PowerPoint โดยใช้ Node.js

โปรดทำตามขั้นตอนด้านล่างเพื่อแปลงไฟล์ Word เป็น PPTX โดยทางโปรแกรม:

  • สร้างอินสแตนซ์ของ ConvertApi
  • สร้างอินสแตนซ์ ConvertSettings
  • ระบุชื่อที่เก็บข้อมูลของคุณ
  • กำหนดเส้นทางไฟล์คำ
  • กำหนด “pptx” เป็นรูปแบบ
  • ระบุเส้นทางไฟล์เอาต์พุต
  • สร้าง ConvertDocumentRequest
  • รับผลลัพธ์โดยเรียกเมธอด ConvertApi.convertDocument()

ตัวอย่างโค้ดต่อไปนี้แสดงวิธีแปลงรูปแบบ Word เป็น PowerPoint โดยใช้ REST API ใน Node.js:

// วิธีแปลงรูปแบบไฟล์ Word เป็น PowerPoint โดยใช้ Node.js API
const convert = async () => {
  const convertApi = groupdocs_conversion_cloud.ConvertApi.fromKeys(clientId, clientSecret);

  const settings = new groupdocs_conversion_cloud.ConvertSettings();
  settings.storageName = myStorage;
  settings.filePath = "nodejs-testing/sample-file.docx";
  settings.format = "pptx";
  settings.outputPath = "nodejs-testing/sample-file.pptx";

  try {
    // สร้างคำขอแปลงเอกสาร
    const request = new groupdocs_conversion_cloud.ConvertDocumentRequest(settings);
    await convertApi.convertDocument(request);
  }
  catch (err) {
    throw err;
  }
}

convert()
.then(() => {
  console.log("Successfully converted DOCX to PowerPoint file format.");
})
.catch((err) => {
  console.log("Error occurred while converting the Word file:", err);
})
วิธีแปลง Word เป็น PowerPoint โดยใช้ Node.js

แปลง Word เป็น PowerPoint โดยใช้ Node.js

ดาวน์โหลดไฟล์ที่แปลงแล้ว

ตัวอย่างโค้ดด้านบนจะบันทึกไฟล์ PowerPoint ที่แปลงแล้วบนคลาวด์ คุณสามารถดาวน์โหลดได้โดยใช้ตัวอย่างโค้ดต่อไปนี้:

// สร้าง FileApi เพื่อดาวน์โหลดไฟล์ที่แปลงแล้ว
var fileApi = groupdocs_conversion_cloud.FileApi.fromConfig(config);
// สร้างคำขอไฟล์ donwload
let request = new groupdocs_conversion_cloud.DownloadFileRequest("nodejs-testing/sample-file.pptx", myStorage);
// ดาวน์โหลดไฟล์และตอบกลับประเภท Stream
fileApi.downloadFile(request)
    .then(function (response) {
        // บันทึกไฟล์ในไดเร็กทอรีระบบของคุณ
        fs.writeFile("H:\\groupdocs-cloud-data\\sample-file.pptx", response, "binary", function (err) { });
        console.log("Expected response type is Stream: " + response.length);
    })
    .catch(function (error) {
        console.log("Error: " + error.message);
    });

แปลง Word DOCX เป็น PowerPoint ใน Node.js โดยใช้ตัวเลือกขั้นสูง

โปรดทำตามขั้นตอนที่กล่าวถึงด้านล่างโดยใช้ word เป็น PowerPoint ตัวแปลง API ออนไลน์พร้อมการตั้งค่าขั้นสูง:

  • สร้างอินสแตนซ์ของ ConvertApi
  • สร้างอินสแตนซ์ ConvertSettings
  • ระบุชื่อที่เก็บข้อมูลของคุณ
  • กำหนดเส้นทางไฟล์คำ
  • กำหนด “pptx” เป็นรูปแบบ
  • สร้างอินสแตนซ์ DocxLoadOptions
  • ตั้งค่า HideWordTrackedChanges และค่า defaultFont
  • ตอนนี้ กำหนด PptxConvertOptions
  • ตั้งค่าการแปลงต่างๆ เช่น จากหน้า, หน้านับ และซูม เป็นต้น
  • กำหนด loadOptions และ converterOptions
  • ถัดไป ระบุเส้นทางไฟล์เอาต์พุต
  • สร้าง ConvertDocumentRequest
  • รับผลลัพธ์โดยเรียกเมธอด ConvertApi.convertDocument()

ตัวอย่างโค้ดต่อไปนี้แสดงวิธีแปลงไฟล์ word เป็น ppt/pptx ทางออนไลน์โดยใช้ตัวเลือกการแปลงขั้นสูง:

// วิธีแปลง Word DOCX เป็น PowerPoint ใน Node.js โดยใช้ตัวเลือกขั้นสูง
const convert_options = async () => {
  const convertApi = groupdocs_conversion_cloud.ConvertApi.fromKeys(clientId, clientSecret);

  const settings = new groupdocs_conversion_cloud.ConvertSettings();
  settings.storageName = myStorage;
  settings.filePath = "nodejs-testing/sample-file.docx";
  settings.format = "pptx";
  
  const loadOptions = new groupdocs_conversion_cloud.DocxLoadOptions();
  loadOptions.hideWordTrackedChanges = true;
  loadOptions.defaultFont = "Arial";

  const convertOptions = new groupdocs_conversion_cloud.PptxConvertOptions();
  convertOptions.fromPage = 1;
  convertOptions.pagesCount = 1;
  convertOptions.zoom = 1;

  settings.loadOptions = loadOptions;
  settings.convertOptions = convertOptions;
  settings.outputPath = "nodejs-testing/sample-file.pptx";

  try {
    // สร้างคำขอแปลงเอกสาร
    const request = new groupdocs_conversion_cloud.ConvertDocumentRequest(settings);
    await convertApi.convertDocument(request);
  }
  catch (err) {
    throw err;
  }
}

convert_options()
.then(() => {
  console.log("Converted DOCX to PPTX file using advanced options.");
})
.catch((err) => {
  console.log("Error occurred while converting the Word file:", err);
})

โปรแกรมแปลง Word เป็น PowerPoint ออนไลน์ฟรี

วิธีใช้ตัวแปลง word เป็น pptx ออนไลน์ฟรี โปรดลองใช้ ตัวแปลง word เป็น pptx ฟรีทางออนไลน์ ซึ่งพัฒนาโดยใช้ API ด้านบน

บทสรุป

ในบทความนี้ คุณได้เรียนรู้:

  • วิธีแปลงคำเป็นรูปแบบ PowerPoint บนคลาวด์
  • อัปโหลดไฟล์ docx จากนั้นดาวน์โหลดไฟล์ PowerPoint ที่แปลงแล้วจากคลาวด์
  • วิธีแปลงคำเป็น PowerPoint โดยใช้ตัวเลือกขั้นสูง

คุณสามารถเรียนรู้เพิ่มเติมเกี่ยวกับ GroupDocs.Conversion Cloud API โดยใช้ เอกสารประกอบ เรายังมีส่วน API Reference ที่ช่วยให้คุณแสดงภาพและโต้ตอบกับ API ของเราได้โดยตรงผ่านเบราว์เซอร์

ถามคำถาม

คุณสามารถถามคำถามเกี่ยวกับวิธีแปลงงานนำเสนอ Word เป็น PowerPoint ผ่านทาง ฟอรัมสนับสนุนฟรี

ดูสิ่งนี้ด้วย