Page Rotation Issue

I seem to be encountering an issue that I am not sure how to resolve. I have a set of image files that I receive from a client and need to review them The initial documents can be PDF, TIFF, JPEG, Word. I convert all of the images to single page PDF and create different documents from those single pages. On output I need merge the single page PDFs into the documents and some of the single page PDFs need to be rotated.

I use this code to handle merging and rotating the images:

public static byte[] MergePdfs(List<byte[]> pdfs)

{

var streams = new Stream[pdfs.Count];

var i = 0;

foreach (var pdf in pdfs)

streams[i++] = new MemoryStream(pdf);

using (var ms = new MemoryStream())

{

var fileEditor = new Aspose.Pdf.Facades.PdfFileEditor { OptimizeSize = true };

fileEditor.Concatenate(streams, ms);

foreach (var stream in streams)

stream.Dispose();

fileEditor = null;

return ms.ToArray();

}

public static byte[] MergeAndRotatePdfs(List<byte[]> pdfs, Dictionary<int, int> rotationList)

{

using (var ms = new MemoryStream())

{

var mergedPdf = MergePdfs(pdfs);

var pdfDocument = new Aspose.Pdf.Document(new MemoryStream(mergedPdf));

var pageCollection = pdfDocument.Pages;

for (var i = 0; i < rotationList.Keys.Count; i++)

{

switch (rotationList[i])

{

case 90:

pageCollection[i + 1].Rotate = Aspose.Pdf.Rotation.on90;

break;

case 180:

pageCollection[i + 1].Rotate = Aspose.Pdf.Rotation.on180;

break;

case 270:

pageCollection[i + 1].Rotate = Aspose.Pdf.Rotation.on270;

break;

}

}

pdfDocument.Save(ms);

return ms.ToArray();

}

}

My issue is that there seems to be some single page PDFs that don't rotate the way I want. An example, I open one of the documents in Adobe and the image is displaying as landscape (11 x 8.5) but should rotated to be portrait. In this case the top of the image is on the left. I set the rotation to 90 and nothing happens. I set it to 270 and the top of the image is now on the right. Using 180, the image is now upside down.

This behavior is inconsistent and only seems to happen for some of the single page PDFs. Can someone look through my code and see if I am missing anything obvious?

Are there properties in the single page PDF that I should look at that may be affecting the rotation behavior?

I saw in the forum that the pdfPageEditor should be utilized. I tried that and it seemed to have no effect on the document I was working with at all.

Thanks for your help.

Hi John,


Thanks for using our products.

I have gone through the problem description and have also gone through the code snippet which you have shared. The code seems to be correct and as per my understanding, the problem seems to be occurring for few PDF files. So can you please share the PDF documents causing this issue so that we can test the scenario at our end. We are sorry for this inconvenience.