Writing Vector Graphics to PDF
Starting in 12.0, you can write SVG and WMF/EMF vector graphics into PDF via VectorGraphics. The module opens the target PDF, writes content, and saves it internally; application code only needs to pass the PDF path and vector file path, and does not need to open the same document with PDFDoc first.
For a complete runnable sample, see examples/simple_demo/vectorgraphics in the product package. See the API Reference for class and method details.
System requirements
- Platforms: Win32, Win64, Linux64, Mac (Linux x86 / Linux ARM and Mac ARM are not supported)
- Languages: C, C++, Java, C#, Python, Objective-C, Node.js, Go
- License: The license key used with
Library::Initializemust include theConversionmodule - Runtime dependency: Vector graphics engine library
fxvectorgraphics(loaded by full file path viaVectorGraphics::Initialize(library_path))
Basic workflow
Library::Initialize(sn, key)(license must includeConversion)VectorGraphics::Initialize(library_path)(library_path= full path tofxvectorgraphics)- Call
InsertSVGToPDF/InsertSVGToPage/InsertWMFToPDF/InsertWMFToPage VectorGraphics::Release, thenLibrary::Release
Insert SVG
InsertSVGToPDF: Inserts a new page at the specified position and draws the SVG; ifpdf_pathis empty or does not exist, a new PDF is created atout_pdf_path. Parameters include page width/height (pt) and DPI.InsertSVGToPage: Draws the SVG into a rectangle on an existing page (lower-left coordinatesx/y, plus width, height, and DPI). The source PDF path must not be empty.
c++
using namespace foxit;
using namespace foxit::common;
using namespace foxit::addon::vectorgraphics;
// 1) Initialize PDF SDK (license must include the Conversion module).
Library::Initialize(sn, key);
// 2) Load the vector graphics engine: pass the full path to fxvectorgraphics (must not be empty).
WString library_path = L"C:/path/to/fxvectorgraphics.dll"; // Linux: .../libfxvectorgraphics.so
VectorGraphics::Initialize(library_path);
// Create a new PDF and insert the SVG as a new A4 page (595 x 842 pt), dpi = 96.
VectorGraphics::InsertSVGToPDF(L"", svg_path, out_pdf_new, 0, 595.f, 842.f, 96);
// Draw into a rectangle on page 0 of an existing PDF.
VectorGraphics::InsertSVGToPage(pdf_path, svg_path, out_pdf_page, 0, 50.f, 50.f, 200.f, 200.f, 96);
VectorGraphics::Release();
Library::Release();C
FSDK_Library_Initialize(sn, key);
const wchar_t* library_path = L"C:/path/to/fxvectorgraphics.dll";
FSDK_VectorGraphics_Initialize(library_path);
FSDK_VectorGraphics_InsertSVGToPDF(L"", svg_path, out_pdf_new, 0, 595.f, 842.f, 96);
FSDK_VectorGraphics_InsertSVGToPage(pdf_path, svg_path, out_pdf_page, 0, 50.f, 50.f, 200.f, 200.f, 96);
FSDK_VectorGraphics_Release();
FSDK_Library_Release();java
Library.initialize(sn, key);
String libraryPath = "C:/path/to/fxvectorgraphics.dll";
VectorGraphics.initialize(libraryPath);
VectorGraphics.insertSVGToPDF("", svgPath, outPdfNew, 0, 595.f, 842.f, 96);
VectorGraphics.insertSVGToPage(pdfPath, svgPath, outPdfPage, 0, 50.f, 50.f, 200.f, 200.f, 96);
VectorGraphics.release();
Library.release();py
Library.Initialize(sn, key)
library_path = "C:/path/to/fxvectorgraphics.dll"
VectorGraphics.Initialize(library_path)
VectorGraphics.InsertSVGToPDF("", svg_path, out_pdf_new, 0, 595.0, 842.0, 96)
VectorGraphics.InsertSVGToPage(pdf_path, svg_path, out_pdf_page, 0, 50.0, 50.0, 200.0, 200.0, 96)
VectorGraphics.Release()
Library.Release()objc
[FSLibrary initialize:sn key:key];
NSString* libraryPath = @"/path/to/libfxvectorgraphics.dylib";
[FSVectorGraphics initialize:libraryPath];
[FSVectorGraphics insertSVGToPDF:@"" svg_path:svgPath out_pdf_path:outPdfNew
page_index:0 page_width_pt:595.0f page_height_pt:842.0f dpi:96];
[FSVectorGraphics insertSVGToPage:pdfPath svg_path:svgPath out_pdf_path:outPdfPage
page_index:0 x:50.0f y:50.0f width:200.0f height:200.0f dpi:96];
[FSVectorGraphics destroy];
[FSLibrary destroy];js
const FSDK = require("@foxitsoftware/foxit-pdf-sdk-node");
FSDK.Library.Initialize(sn, key);
let library_path = "C:/path/to/fxvectorgraphics.dll";
FSDK.VectorGraphics.Initialize(library_path);
FSDK.VectorGraphics.InsertSVGToPDF("", svg_path, out_pdf_new, 0, 595.0, 842.0, 96);
FSDK.VectorGraphics.InsertSVGToPage(pdf_path, svg_path, out_pdf_page, 0, 50.0, 50.0, 200.0, 200.0, 96);
FSDK.VectorGraphics.Release();
FSDK.Library.Release();csharp
Library.Initialize(sn, key);
string library_path = @"C:\path\to\fxvectorgraphics.dll";
VectorGraphics.Initialize(library_path);
VectorGraphics.InsertSVGToPDF("", svg_path, out_pdf_new, 0, 595.0f, 842.0f, 96);
VectorGraphics.InsertSVGToPage(pdf_path, svg_path, out_pdf_page, 0, 50.0f, 50.0f, 200.0f, 200.0f, 96);
VectorGraphics.Release();
Library.Release();go
fsdk.LibraryInitialize(sn, key)
libraryPath := "/path/to/libfxvectorgraphics.so"
fsdk.VectorGraphicsInitialize(libraryPath)
fsdk.VectorGraphicsInsertSVGToPDF("", svgPath, outPdfNew, 0, 595.0, 842.0, 96)
fsdk.VectorGraphicsInsertSVGToPage(pdfPath, svgPath, outPdfPage, 0, 50.0, 50.0, 200.0, 200.0, 96)
fsdk.VectorGraphicsRelease()
fsdk.LibraryRelease()Insert WMF / EMF
InsertWMFToPDF / InsertWMFToPage use the same parameter shape as the corresponding SVG APIs. The WMF path in the samples may also point to an EMF file. Call these only after completing Library::Initialize and VectorGraphics::Initialize as in the previous section.
c++
VectorGraphics::InsertWMFToPDF(L"", wmf_path, out_pdf_new, 0, 595.f, 842.f, 96);
VectorGraphics::InsertWMFToPage(pdf_path, wmf_path, out_pdf_page, 0, 50.f, 50.f, 200.f, 200.f, 96);C
FSDK_VectorGraphics_InsertWMFToPDF(L"", wmf_path, out_pdf_new, 0, 595.f, 842.f, 96);
FSDK_VectorGraphics_InsertWMFToPage(pdf_path, wmf_path, out_pdf_page, 0, 50.f, 50.f, 200.f, 200.f, 96);java
VectorGraphics.insertWMFToPDF("", wmfPath, outPdfNew, 0, 595.f, 842.f, 96);
VectorGraphics.insertWMFToPage(pdfPath, wmfPath, outPdfPage, 0, 50.f, 50.f, 200.f, 200.f, 96);py
VectorGraphics.InsertWMFToPDF("", wmf_path, out_pdf_new, 0, 595.0, 842.0, 96)
VectorGraphics.InsertWMFToPage(pdf_path, wmf_path, out_pdf_page, 0, 50.0, 50.0, 200.0, 200.0, 96)objc
[FSVectorGraphics insertWMFToPDF:@"" wmf_path:wmfPath out_pdf_path:outPdfNew
page_index:0 page_width_pt:595.0f page_height_pt:842.0f dpi:96];
[FSVectorGraphics insertWMFToPage:pdfPath wmf_path:wmfPath out_pdf_path:outPdfPage
page_index:0 x:50.0f y:50.0f width:200.0f height:200.0f dpi:96];js
FSDK.VectorGraphics.InsertWMFToPDF("", wmf_path, out_pdf_new, 0, 595.0, 842.0, 96);
FSDK.VectorGraphics.InsertWMFToPage(pdf_path, wmf_path, out_pdf_page, 0, 50.0, 50.0, 200.0, 200.0, 96);csharp
VectorGraphics.InsertWMFToPDF("", wmf_path, out_pdf_new, 0, 595.0f, 842.0f, 96);
VectorGraphics.InsertWMFToPage(pdf_path, wmf_path, out_pdf_page, 0, 50.0f, 50.0f, 200.0f, 200.0f, 96);go
fsdk.VectorGraphicsInsertWMFToPDF("", wmfPath, outPdfNew, 0, 595.0, 842.0, 96)
fsdk.VectorGraphicsInsertWMFToPage(pdfPath, wmfPath, outPdfPage, 0, 50.0, 50.0, 200.0, 200.0, 96)