I am testing your library in my application to add an image to PDF document pages. Every time the file pages correctly loaded. But all the pages are reverted in orientation once i try to save to a new PDF file. All the content on each page keeps original, as well as page sizes, but a blank section displays at the bottom of each page. I did nothing on the pages except for adding an image.
I'm not familiar enough with the code base on this issue. So, would you please tell me a simple way to solve this problem. Thanks a lot. :)
This article on XsPDF.com is what you looking for, check out: Create and Save PDF in C#.
Answers
To help us locate the problem, would you please send us a copy of your PDF document. Do not worry. We guarantee that this copy will keeps confidential and it will be used for testing purposes only.
Thank you for providing the sample. We did further tests on your file and found a workaround. These are what we did. Creating a new blank PDF document and import the existing pages to the new document, and save the document. In this way, orientations are preserved.
So, please do as suggested.
- Create a PDF document with any number of pages and sizes. Please note, this PDF should contain at least one landscape page.
- Create a new Visual Studio project (in C#), like a Console Application.
- Add the project reference to our library dll and copy the following sample code to the void Main.
- Run the project. Please make sure that the sample .pdf file is in the working directory.
PdfDocument PDFDoc = PdfReader.Open("testFile.pdf", PdfDocumentOpenMode.Import); PdfDocument PDFNewDoc = new PdfDocument(); for (int Pg = 0; Pg < PDFDoc.Pages.Count; Pg++) { PDFNewDoc.AddPage(PDFDoc.Pages[Pg]); } PDFNewDoc.Save("resultFile.PDF");
If you have additional questions on evaluating our product, please send email to us.
Thanks for your quick response. The solution is great! This saved me a lot of hours and a big headaches.