Page orientation when concatenating PDF Files

Hi I am try to append pdf pages from one document to another. I did as the following:



// Open the first document
Document pdfDocument1 = new Document(“input.pdf”);
// Open the second document
Document pdfDocument2 = new Document(“input2.pdf”);

// Add pages of second document to the first
pdfDocument1.Pages.Add(pdfDocument2.Pages);

// Save concatenated output file
pdfDocument1.Save(“output.pdf”);


The issues was, there might be some landscape orientation pages in pdf2, and after concatenating, all pages were in portrait orientation, and the images were cropped.

I tried to rotate, but did not work.

foreach(Page p in pdfDocument2.Pages)
{
pdfDocument1.Pages.Add§;
if (p.Rotate != Rotation.None)
pdfDocument1.Pages[pdfDocument1.Pages.Count - 1].Rotate = p.Rotate;
}

Is there an easy way to fix this? Thanks.

Hi Hanwei,


Thanks for using our API’s.

Can you please share the resource PDF files, so that we can test the scenario in our environment. We are sorry for this inconvenience.

Actually, the PDFs are stored in database as blob object. It works fine when I deal with them as physical files. I use memory stream to create instance.


new Aspose.Pdf.Document(new MemoryStream(file.Data))

Does it make difference? I could provide you pdf documents if you think it helps, but I can’t re-create the issue with files.

Hi Hanwei,


Thanks for sharing the details.

I have tested the scenario using following code snippet and as per my observations, the pages in resultant file are in both Landscape and Portrait orientation (as per input files). Can you please share your sample files (save the blob to files), so that we can further look into this matter. We are sorry for this inconvenience.

[C#]

FileStream fs1 = new
FileStream(“c:/pdftest/IN_201510271549-2.pdf”,
FileMode.Open);<o:p></o:p>

FileStream fs2 = new FileStream("c:/pdftest/Discount-Deals-080415.pdf", FileMode.Open);

// Open the first document

Document pdfDocument1 = new Document(fs1);

// Open the second document

Document pdfDocument2 = new Document(fs2);

// Add pages of second document to the first

pdfDocument1.Pages.Add(pdfDocument2.Pages);

// Save concatenated output file

pdfDocument1.Save("c:/pdftest/Concatenated_output.pdf");

fs1.Close();

fs2.Close();