In the Rotate90Degrees example, PdfReader is used to get an instance of the document, and then the /Rotate
value is changed in each dictionary of pages. If there is no such record, the /Rotate
record with the value 90
added:
final PdfReader reader = new PdfReader(source); final int pagesCount = reader.getNumberOfPages(); for (int n = 1; n <= pagesCount; n++) { final PdfDictionary page = reader.getPageN(n); final PdfNumber rotate = page.getAsNumber(PdfName.ROTATE); final int rotation = rotate == null ? 90 : (rotate.intValue() + 90) % 360; page.put(PdfName.ROTATE, new PdfNumber(rotation)); }
Once this is done, we use PdfStamper
to save the change:
PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(dest)); stamper.close(); reader.close();
This is for iText Java. For iTextSharp, porting Java to C # is easy because the terminology is identical. Change some lowercase to upper regions as follows:
PdfDictionary page = reader.GetPageN(1); page.Put(PdfName.ROTATE, new PdfNumber(90));
On the question side of this post, a more or less identical piece of code: How do I rotate a PDF page using iTextSharp without causing an error in ghostscript?
source share