Blog Post

Programmatically Converting and Merging Files Attached to PDF Documents

Clavin Fernandes
Illustration: Programmatically Converting and Merging Files Attached to PDF Documents

One of the cool things you can do when you have a comprehensive PDF Conversion and processing platform such as the Muhimbi PDF Converter Services, is that you can add relatively complex facilities  you didn’t originally envision, with relative ease.

When we originally set out we never thought of converting PDF files to PDF format, why would anyone do that? Well, it turns out there are several good reasons including Converting PDF to PDF/A (or other PDF versions), Changing PDF Viewer preferences or embed strip fonts from a PDF. Starting with version 7.2.1 we are adding another scenario to the mix, which is the ability to convert files attached to PDF Documents.

Similar to emails, a PDF document can have other files attached. Previously we simply ignored these files, but now we actively inspect PDF attachments and offer the option to convert and merge them to the main PDF. Ideal for archiving or printing purposes.

This new facility is accessible from our Web Services interface, see below, as well as SharePoint Designer and Nintex Workflows using our XML Override syntax. Conversion of PDF Attachments can globally be controlled using the Conversion Service’s configuration file by modifying the PDF.ConvertAttachments and PDF.ConvertAttachmentMode keys.

ConverterSpecificSettings_PDF

The syntax is simple. Create a new instance of ConverterSpecificSettings_PDF, set its properties to the appropriate values and assign it to ConversionSettings.ConverterSpecificSettings before kicking off the conversion operation. A brief code example, that can easily be plugged into our standard sample code, can be found below.

ConverterSpecificSettings_PDF csc = new ConverterSpecificSettings_PDF();

csc.ConvertAttachments = true;

csc.ConvertAttachmentMode = PDFConvertAttachmentMode.RemoveSupported;

conversionSettings.ConverterSpecificSettings = csc;

The syntax for Java, Ruby and PHP is similar, but the code needs to be adapted to syntax specific to those environments.

The possible values for ConverterAttachmentMode are as follows:

  • RemoveAll: When a PDF file is processed, all attachments will be converted and merged to the main PDF. All attachments will be removed from the PDF, including those of attachments for which the file type is not recognised by the converter.

  • RemoveSupported: When a PDF file is processed, all attachments will be converted and merged to the main PDF, but only those attachments that are supported by the converter are removed from the PDF, all other attachments remain present in the main file.

Naturally these values are only used when ConvertertAttachments is set to True.

As this behaviour is part of the PDF Conversion Service’s processing pipeline, this new facility can be used in combination with all Merging, Watermarking, OCR, PDF Encryption and PDF/A post processing facilities.

Any questions or feedback? Leave a comment in the section below or contact us, we love talking to our customers.

Author
Clavin Fernandes Developer Relations and Support Services

Clavin is a Microsoft Business Applications MVP who supports 1,000+ high-level enterprise customers with challenges related to PDF conversion in combination with SharePoint on-premises Office 365, Azure, Nintex, K2, and Power Platform mostly no-code solutions.

Explore related topics

Share post
Free trial Ready to get started?
Free trial