As Muhimbi’s range of PDF Conversion products, including the PDF Converter for SharePoint and the PDF Converter API and Server Platform, now provide the ability to post process any converted document for output in PDF/A format, one obvious use for this brilliant new functionality is to convert regular PDF files to PDF/A format.
In this post we’ll provide a simple .NET sample that invokes our Web Services interface to carry out the conversion from PDF to PDF/A1b. The code is nearly identical to the code to convert and watermark a simple MS-Word file with the following exceptions. You can apply the same changes to the Java sample to make it do the same using that language.
- openOptions.FileExtension is set to pdf.
- conversionSettings.PDFProfile is set to PDFProfile.PDF_A1B.
- converstionSettings.OutputFormatSpecificSettings is set to an instance of OutputFormatSpecificSettings_PDF with the PostProcessFile property set to True.
- The client.ProcessChanges() method is invoked rather than client.Convert().
- All references to watermarks have been removed as they are not part of this sample.
Some minor clean-up has been carried out as well to make the code even shorter. After running the example the resulting file validates perfectly according to Acrobat X Pro.
Listed below is sample code to convert PDF to PDF/A. You can either copy the code from this blog post, download the Visual Studio Project or open the project from the Sample Code folder in the Windows Start Menu.
The sample code expects the path of the PDF file on the command line. If the path is omitted then the first PDF file found in the current directory will be used.
Download and install the Muhimbi PDF Converter API and Server Platform or PDF Converter for SharePoint.
Install the prerequisites as described here. There is no need to make any changes to the configuration file.
Create a new Visual Studio C# Console application named PDFA_Conversion.
Add a Service Reference to the following URL and specify ConversionService as the namespace
Paste the following code into Program.cs.
binding.ReceiveTimeout = TimeSpan.FromMinutes(30);
// ** Set the maximum document size to 50MB
binding.MaxReceivedMessageSize = 50 * 1024 * 1024;
binding.ReaderQuotas.MaxArrayLength = 50 * 1024 * 1024;
binding.ReaderQuotas.MaxStringContentLength = 50 * 1024 * 1024;
// ** Specify an identity (any identity) in order to get it past .net3.5 sp1
EndpointIdentity epi = EndpointIdentity.CreateUpnIdentity("unknown");
EndpointAddress epa = new EndpointAddress(new Uri(address), epi);
client = new DocumentConverterServiceClient(binding, epa);
/// Check if the client is open and then close it.
/// <param name="client">The client to close</param>
public static void CloseService(DocumentConverterServiceClient client)
if (client != null && client.State == CommunicationState.Opened)