I'm writing an application that adds a watermark to PDF pages.
I'm using a test document that has the following pages:
A4 portrait
A3 landscape
A4 landscape
A3 portrait
The pages register correctly once loaded, in that the code objects have the correct sizes and orientation in memory .
However, once saved to a new file, all the pages revert to portrait orientation without affecting the content (i.e. the content is truncated width-wise, and there is a blank section at the bottom of each page).
This behaviour happens even if the pages are not altered in any way.
Steps to replicate the problem:
Create a PDF with any number of pages or sizes, but with at least one landscape page, call it 'testFile.pdf'
Create a new VS C# project, Console application
Add a Reference to the PDFSharp DLL
Add the following code to the void Main:
Code:
PdfSharp.Pdf.PdfDocument PDFDoc = PdfSharp.Pdf.IO.PdfReader.Open("testFile.pdf");
PDFDoc.Save("resultFile.PDF");
Set the working directory and ensure the testFile.pdf is in that directory
Compile and run.
the output file will contain pages of the right size, but all portrait orientation.
This has been tested on a PDF with a single A4 landscape page, and the output was still portrait.
I notice that PdfPage objects are created by default with portrait orientation. I'm not familiar enough with the code base to work out where this would get overriden by the actual size and orientation.