從 Word 文件中提取 PowerPoint 圖像 - 圖像提取器

如果您需要從 Word 文件中提取嵌入的圖像以進行存檔、自動化或圖像識別,那麼我們的 Node.js REST API 提供了一個穩健且基於雲的解決方案,可以從 .doc.docx 文件中提取圖像,而無需安裝 Microsoft Word。

圖像提取的需求可能也會出現,如果我們需要:

  • 捕捉報告中嵌入的圖形、圖表和照片。
  • 自動化從掃描文件或範本中提取資料。
  • 從文檔庫建立圖像數據集。
  • Preprocess content for OCR or AI tasks.

讓我們更詳細地探討以下主題:

Word Document Image Extraction API

The GroupDocs.Parser Cloud SDK for Node.js is a REST based solution offering the capabilities to parse MS Word documents for content manipulation. Not only Word document, but it also offers the support for content extraction from almost all the common business document formats including (PPTX, Excel, PDF, ZIP, etc.).

先決條件

npm install groupdocs-parser-cloud
  • 若要獲得有關客戶端憑證的更多資訊,請參閱這篇 article

如何使用 Node.js 提取 Word 中的圖片

按照以下步驟開發一個簡單而穩健的應用程序,以使用 Node.js API 從 MS Word 文檔中提取圖像:

步驟 1:初始化配置。

const { ParserApi, Configuration, ImagesRequest, FileInfo, ImagesOptions } = require("groupdocs-parser-cloud");

const config = new Configuration("YOUR_CLIENT_ID", "YOUR_CLIENT_SECRET");
const parserApi = new ParserApi(config);

步驟 2:設置檔案資訊和圖像選項。 初始化一個 ImagesRequest 類別的物件,並傳遞 ImagesOptions 類別的實例。

const fileInfo = new FileInfo();
// path to your PowerPoint file
fileInfo.filePath = "input.docx";

const options = new ImagesOptions();
options.fileInfo = fileInfo;

const request = new ImagesRequest(options);

步驟 3:從 Word 文件中提取圖片。 調用 images 方法從線上 Word 文件中提取圖像。

parserApi.images(request).then((response) => {
    console.log("The Word document Images extracted successfully.");
    console.log(response.images);
}).catch((err) => {
    console.error("Failed to extract images:", err);
});
// 如需更多範例,請訪問 https://github.com/groupdocs-parser-cloud/groupdocs-parser-cloud-node
const { Configuration, ParserApi, TextOptions, TextRequest, FileInfo } = require("groupdocs-parser-cloud");

const config = new Configuration("YOUR_CLIENT_ID", "YOUR_CLIENT_SECRET");
const parserApi = new ParserApi(config);

const fileInfo = new FileInfo();
// path of word document
fileInfo.filePath = "sample.docx";

const options = new TextOptions();
options.fileInfo = fileInfo;

const request = new TextRequest(options);

parserApi.images(request).then((response) => {
  console.log("The Word document Images extracted successfully.");
  console.log(response.images);
}).catch(err => {
    console.error("Failed to extract images:", err);
});

您可以在下方圖片中查看上述代碼示例的輸出:

使用 Node.js API 從 Word 文檔提取圖片的預覽

透過 cURL 擷取 Word 中的圖片

如果您更喜歡使用命令行方法透過 cURL 命令提取 Word 文檔圖片,那麼 GroupDocs.Parser Cloud 支持這些功能。讓我們進一步探索這個特性,以簡化如何使用 cURL 命令從 Word 文檔獲取圖片的要求。

步驟 1 – 生成訪問令牌:

curl -X POST "https://api.groupdocs.cloud/connect/token" \
-d "grant_type=client_credentials&client_id=YOUR_CLIENT_ID&client_secret=YOUR_CLIENT_SECRET" \
-H "Content-Type: application/x-www-form-urlencoded"

步驟 2 – 從 Word 檔案中提取圖片:

curl -v -X POST "https://api.groupdocs.cloud/v1.0/parser/images" \
-H  "accept: application/json" \
-H  "authorization: Bearer {ACCESS_TOKEN}" \
-H  "Content-Type: application/json" \
-d "{  
        \"FileInfo\": {
            \"FilePath\": \"input.docx\",
            \"StorageName\": \"internal\"
            },
            \"OutputPath\": \"internal\",
            \"StartPageNumber\": 1,
            \"CountPagesToExtract\": 2
    }"
  • 🔐 將 更換為你生成的那個。
  • 如果您需要從整個文檔中提取圖像,只需忽略參數 StartPageNumberCountPagesToExtract

嘗試免費的文字圖像提取器 在線

如果您更喜歡基於用戶界面的方式來提取 Word 文檔中的圖片,那麼您可以考慮使用我們免費的在線 Word Document Image Extractor,由 GroupDocs.Parser Cloud 提供支持。

免費圖片提取器

結論

使用 GroupDocs.Parser Cloud SDK for Node.js,從 Word 文件中提取圖像變得快速且可擴展。無論您需要處理合同、報告還是掃描表單 — 此 API 使您完全控制 Word 文檔的圖像提取。

📚 附加資源

常見問題 – FAQs

Can I extract images from specific pages in a Word document?

  • 是的。您可以定義 StartPageNumberCountPagesToExtract 參數。

圖像是否以原始格式和解析度提取?

  • 是的。API 會如文件中所示返回嵌入的圖片。

我需要安裝 Microsoft Word 嗎?

  • 不。這是一個基於雲端的解決方案,並且獨立於 MS Office 運作。

是否有免費試用?

  • 是的。您可以每月獲得 150 次免費 API 調用,當您使用試用帳戶時。欲了解更多信息,請訪問 pricing guide

相關文章