PDF 是一種廣泛使用的文檔格式,用於在個人和不同組織之間交換文檔。它是一種標准文檔格式,但有時它並不是某些情況下的理想格式。如今,很多人都在智能手機或平板電腦等移動設備上消費內容。在這種情況下,SVG 是一個不錯的選擇。 SVG 可以縮放到不同的屏幕尺寸而不會降低質量,是網站最常用的格式。網頁還可以使用 CSS 樣式來顯示 SVG 內容。為此,您需要將 PDF 文件轉換為 SVG。在本文中,您將學習如何使用 C++ 將 PDF 文件轉換為 SVG 格式。

C++ PDF 到 SVG 轉換器 API – 免費下載

Aspose.PDF for C++ API 提供了很多處理 PDF 文件的功能。 API 允許您在不使用 Adobe Acrobat 的情況下創建、閱讀、轉換和操作 PDF 文檔。要將 PDF 文件轉換為 SVG,首先,您需要下載 API。首先從 官方網站 免費下載 API 或使用 NuGet 包。

PDF 到 SVG C++ 轉換

以下是將 PDF 文檔轉換為 SVG 格式需要遵循的步驟:

以下代碼片段顯示了使用 C++ 將 PDF 轉換為 SVG。

// 加載PDF文件
auto doc = MakeObject<Document>(u"input.pdf");

// 實例化一個 SvgSaveOptions 的對象
SharedPtr<SvgSaveOptions> options = MakeObject<SvgSaveOptions>();

// 將 PDF 另存為 SVG 文件
doc->Save(u"input_out.svg", options);

使用其他選項將 PDF 轉換為 SVG

SvgSaveOptions 類提供了額外的選項來自定義 PDF 到 SVG 的轉換。以下是 SvgSaveOptions 類提供的選項。

  • CompressOutputToZipArchive: Use this option to create one zip-archive output file.
  • CustomStrategyOfEmbeddedImagesSaving: Use this option to specify the custom strategy for embedding external images to SVG. That strategy must process the resources and return a string URI of the saved resource.
  • ScaleToPixels: This option specifies whether to scale the output from typographic points to pixels.
  • TreatTargetFileNameAsDirectory: Set this option to true to save the output file in the directory with the same name as the output file.

您可以按照下面給出的步驟使用其他選項將 PDF 轉換為 SVG:

以下代碼片段演示了使用其他選項將 PDF 轉換為 SVG。

// 加載PDF文件
auto doc = MakeObject<Document>(u"input.pdf");

// 實例化一個 SvgSaveOptions 的對象
SharedPtr<SvgSaveOptions> options = MakeObject<SvgSaveOptions>();

// 將輸出文件放在同名文件夾中
options->TreatTargetFileNameAsDirectory = true;

// 將 PDF 另存為 SVG 文件
doc->Save(u"input_out.svg", options);

獲得免費許可證

您可以通過申請 免費的臨時許可證 來試用沒有評估限制的 API。

結論

在本文中,您了解瞭如何將 PDF 直接轉換為 SVG 或通過提供其他選項來自定義轉換。此外,您可以使用 官方文檔 詳細探索 Aspose.PDF for C++ API。

也可以看看