For the complete documentation index, see llms.txt. This page is also available as Markdown.

Convert Image to PDF on Server/Desktop

Many image types can be converted to PDF Documents using PDF.Convert.ToPDF method. For a complete list of formats supported, please refer to Desktop/Server image formats or Web image formats. Some of the formats such as HEIC and PSD formats require an additional plugin called the Advanced Imaging Module. More information about the module and download links can be found in the advanced imaging module guide.

// Start with a PDFDoc (the conversion destination)
PDFDoc doc = new PDFDoc();

// perform the conversion with no optional parameters
Convert.ToPdf(doc, filename);
// Start with a PDFDoc (the conversion destination)
PDFDoc doc;

// perform the conversion with no optional parameters
Convert::ToPdf(doc, filename);
// Start with a PDFDoc (the conversion destination)
PDFDoc doc = new PDFDoc();

// perform the conversion with no optional parameters
Convert.toPdf(doc, filename);
const doc = await PDFNet.PDFDoc.create();

// perform the conversion with no optional parameters
await PDFNet.Convert.toPdf(doc, filename);
# Start with a PDFDoc (the conversion destination)
doc = PDFDoc()

# perform the conversion with no optional parameters
Convert.ToPdf(doc, filename)

For the image formats that are exclusively supported by Advanced Imaging module, the path containing the module should be added using PDFNet.AddResourceSearchPath prior to invoking the PDF.Convert.ToPDF method. The following snippets demonstrate how this can be done.

// Use a try-catch block here to catch PDFNetException
PDFNet.AddResourceSearchPath('relative/path/to/Lib/');
using (PDFDoc pdfdoc = new PDFDoc())
{
    pdftron.PDF.Convert.ToPdf(pdfdoc, input_path + input_file);
	pdfdoc.Save(output_path + output_file_name, SDFDoc.SaveOptions.e_remove_unused);
}
// Use a try-catch block here to catch PDFNetException
PDFNet::AddResourceSearchPath('relative/path/to/Lib/');
PDFDoc pdfdoc;
Convert::ToPdf(pdfdoc, input_path + input_file);
pdfdoc.Save(outputPath + outputFile, SDF::SDFDoc::e_linearized, NULL);
// Use a try-catch block here to catch PDFNetException
PDFNet.addResourceSearchPath('relative/path/to/Lib/');
PDFDoc doc = new PDFDoc();
Convert.toPdf(doc, input_path + input_file);
doc.save(outputFile, SDFDoc.SaveMode.LINEARIZED, null);
const main = async () => {
	// Use a try-catch block here to catch PDFNetException
	await PDFNet.addResourceSearchPath('relative/path/to/Lib/');
	const doc = await PDFNet.PDFDoc.create();
    await PDFNet.Convert.toPdf(doc, inputPath + input_file);
	await doc.save(outputPath + output_file_name, PDFNet.SDFDoc.SaveOptions.e_linearized);
};
PDFNet.runWithCleanup(main).then(function(){ PDFNet.shutdown(); });

Sample

For a complete working sample that uses the Advanced Imaging Module and pdftron.PDF.Convert.ToPdf to convert formats such as HEIC and PSD to PDF, see the AdvancedImagingTest sample . This same code can be used to integrate the module into your application or project.

Last updated

Was this helpful?