when we concatinate pdf using aspose pdf. The formate of orignal file is getting changed. Here is orignal file
0000800070_Service_Create_V15 (2) (1).pdf (2.1 MB)
and here is file i am geting after concatenation
File after concatination.pdf (1.7 MB)
@apatil03
When concatenating PDF files using Aspose.PDF, changes in the original formatting can occur due to various factors such as differences in page sizes, margins, or embedded fonts. To maintain the original formatting during concatenation, consider the following steps:
-
Check Page Sizes: Ensure that all PDF files being concatenated have the same page size. If they differ, you may need to adjust them before concatenation.
-
Use PdfFileEditor: Utilize the PdfFileEditor
class, which is specifically designed for merging PDF files while preserving their formatting.
Here’s a simple example of how to concatenate PDF files:
using Aspose.Pdf.Facades;
// Create PdfFileEditor object
PdfFileEditor pdfEditor = new PdfFileEditor();
// Concatenate PDF files
pdfEditor.Concatenate("input1.pdf", "input2.pdf", "output.pdf");
- Disable Copying Outlines: If your PDFs contain many outlines, you can disable copying outlines to improve performance and potentially avoid formatting issues:
pdfEditor.CopyOutlines = false;
- Check for Font Issues: If the original PDFs use specific fonts that are not available on the system where the concatenation is performed, it may lead to formatting changes. Ensure that all necessary fonts are embedded in the PDFs or available on the system.
If you continue to experience formatting issues, consult the Aspose documentation for more detailed guidance on handling specific formatting challenges during PDF concatenation.
@apatil03
Attached is the output PDF that we obtained in our environment using below code snippet and the latest version of the API:
// Create PdfFileEditor object
Facades.PdfFileEditor pdfEditor = new Facades.PdfFileEditor();
Document doc = new Document();
doc.Pages.Add();
doc.Save(dataDir + "sampleformerge.pdf");
// Output stream
using (FileStream outputStream = new FileStream(dataDir + "concatenatedPDF.pdf", FileMode.Create))
{
// Array of input streams
using (FileStream inputStream1 = new FileStream(dataDir + "0000800070_Service_Create_V15 (2) (1).pdf", FileMode.Open),
inputStream2 = new FileStream(dataDir + "sampleformerge.pdf", FileMode.Open))
{
// Concatenate files
pdfEditor.Concatenate(new Stream[] { inputStream1, inputStream2 }, outputStream);
}
}
concatenatedPDF.pdf (2.2 MB)
Would you please make sure to use the latest version and if issue still persists, please let us know.