This is the code used for merging:
private void MergeDifferentDocumentsPagesWithFixed()
{
string[] documentsToMerge =
{
"14301-STOCK_Proforma.pdf",
"14302-STOCK_Proforma.pdf",
"14303-STOCK_Proforma.pdf",
"14304-STOCK_Proforma.pdf",
"14305-STOCK_Proforma.pdf",
"14330-STOCK_Proforma.pdf"
};
RadFixedDocument doc = new RadFixedDocument();
PdfFormatProvider provider = new PdfFormatProvider();
foreach (string current_item in documentsToMerge)
{
string path = @"..\..\Samples\" + current_item;
RadFixedDocument docToMerge;
if (!File.Exists(path))
{
continue;
}
using (Stream stream = File.OpenRead(path))
{
docToMerge = provider.Import(stream);
}
doc.Merge(docToMerge);
}
string outputFilePath = @"..\..\mergedFixed.pdf";
File.Delete(outputFilePath);
using (Stream output = File.OpenWrite(outputFilePath))
{
provider.Export(doc, output);
}
Process.Start(new ProcessStartInfo() { FileName = outputFilePath, UseShellExecute = true });
}
Workaround:
private void MergeDifferentDocumentsPages(string resultFileName)
{
string[] documentsToMerge =
{
"14301-STOCK_Proforma.pdf",
"14302-STOCK_Proforma.pdf",
"14303-STOCK_Proforma.pdf",
"14304-STOCK_Proforma.pdf",
"14305-STOCK_Proforma.pdf",
"14330-STOCK_Proforma.pdf"
};
File.Delete(resultFileName);
using (PdfStreamWriter fileWriter = new PdfStreamWriter(File.OpenWrite(resultFileName)))
{
foreach (string documentName in documentsToMerge)
{
string path = @"..\..\Samples\" + documentName;
using (PdfFileSource fileToMerge = new PdfFileSource(File.OpenRead(path)))
{
foreach (PdfPageSource pageToMerge in fileToMerge.Pages)
{
fileWriter.WritePage(pageToMerge);
}
}
}
}
Process.Start(new ProcessStartInfo() { FileName = resultFileName, UseShellExecute = true });
}