Combining Specific Pages of Each File into a Single PDF

Document Conversion Service

A Document Conversion Service customer in the banking industry recently needed to combine a group of PDF, Word and Excel files into a single PDF file. His key requirement was that for certain files he only wanted specific pages and for others he needed the entire file. He needed to be able to do this from an in-house application that was also being designed and implemented at the time.

Our customer approached us with his requirements and asked us if it could be done. At the time, our current solution to combine files did not have the ability to pass down individual settings for each file in the set.

We at PEERNET listen to the needs of our clients and so quickly saw that this was a feature that would be useful for all our customers. Soon after, we added this feature for the Document Conversion Service 2.0.015 release.

NOTE!This feature is only available from the PNConverter.CombineFiles method of the PEERNET.ConvertUtility.dll. The command line tool, DCSCombineFiles, does not allow for custom settings per file.

Creating the File List with Settings

When combining files, a main profile is used to specify the conversion settings for the resulting combined file. To allow each file to have their own settings in addition to the profile settings, the PNConverter.PNConvertFileInfo class is used to build a collection of files and settings to be passed to the PNConverter.CombineFiles method. The settings passed per file are used in addition to or instead of any settings in the main profile.

Only the following conversion settings can be used for the individual file settings:

In the PNConverter.PNConvertFileInfo object, the path to each file must be a fully qualified path name. The OutputFolder property is ignored when combining files. The collection of settings is set for that file; this collection can be left empty if no custom settings are needed. The files are converted in the order in which they are added to the list.

IList<PNConvertFileInfo> fileInfoList = new List<PNConvertFileInfo>();
IList<PNSetting> filesettings = new List<PNSetting>();

// This file will print all pages and uses only the conversion 
// settings from the profile - we aren't passing any additional settings.
fileInfoList.Add(new PNConvertFileInfo(@"C:\Test\InputFiles\Report.pdf",
                                       String.Empty, null));

// This file only prints the first 3 pages, but also shows all markup
// in the Word document.
filesettings.Add( new PNSetting("PageRange", "1-3"));
filesettings.Add( new PNSetting("Microsoft.Word.Document.PrintOut.Item", 
                                "DocumentAndMarkup") );

fileInfoList.Add(new PNConvertFileInfo(@"C:\Test\InputFiles\Memo.doc",

Combining the List of Files

The code sample below uses the PNConvertFileInfo list created above to append both files into a single multipaged PDF file image containing all the pages of the PDF and the first 3 pages of the Word document with markup displayed. The resulting combined file will be created using the conversion settings from the profile PDF 300dpi OptimizedColor.

PNCombineItem resultsItem = null;
String outputDir = @"C:\Test\CombineOutput";
String outputName = "CombinedInput";
resultsItem = 
    PNConverter.CombineFiles(fileInfoList,         // PNConvertFileInfo collection
                             outputDir,            // output folder
                             baseName,             // name of combined file
                             false,                // overwrite
                             false,                // create results log 
                             "PDF 300dpi OptimizedColor", // profile
                             String.Empty,         // File-ext
                             String.Empty,         // MIME
                             null,                 // user settings
                             String.Empty,         // not using remote conversion (DCOM)
                             String.Empty,         // remote conversion folder
                             String.Empty          // Log path

A handy new feature if you ask us! And we think most of our Document Conversion Service clients would agree. Let us know if you need help setting up this new feature.