
#region Create new pdfReader and load into it data from temporary file and then rotate pages to required position #endregion Create temporary file to rotate page without content rotation and shrink content Page.Put(PdfName.ROTATE, new PdfNumber(rotation)) Stamper.RotateContents = true //this line leave content of page not rotated Int rotation = rotate = null ? 270 : (rotate.IntValue + 270) % 360

PdfNumber rotate = page.GetAsNumber(PdfName.ROTATE) PdfDictionary page = pdfReader.GetPageN(pageNumber) New FileStream(temporaryFilePath, FileMode.Create, FileAccess.Write, FileShare.None)) TemporaryFilePath = System.IO.Path.Combine(pdfInputsDirectoryPath, temporaryFileName) String temporaryFileName = "Temporary_" + Path.GetFileNameWithoutExtension(inputPdfFilePath) + into pdf stream didn't find other solution which set content in Portrait orienation page into required horizontal
#ROTATE PDF PAGE BY PAGE CODE#
this part of code is created because without saving rotated to Landscape orientatio pdf file and reading it again #region Create temporary file to rotate page without content rotation and shrink content After the first step code opens temporary file, rotates pdf content to Portrait orientation (which is the required content position) and save the result to file. In this solution is used temporary file in which is saved shrunk and rotated to Landscape orientation pdf page content. In the attached images are initial and required result.

I look at the question iText - Rotate page content while creating PDF, but didn't find solution to my code from this question until now. Code to rotate only content of pdf page 90 or 270 degrees leaving page Stamper.GetUnderContent(pageNumber).SetLiteral("\nq 0.53 0 0 0.53 10 25 cm\nq\n") Shrink original page contents for the purpose to fit into required area PdfStamper stamper = new PdfStamper(pdfReader, outputPdfStream) įor (int pageNumber = 1 pageNumber <= pagesAmount pageNumber++) New FileStream(resultFilePath, FileMode.Create, FileAccess.Write, FileShare.None)) String resultFilePath = System.IO.Path.Combine(pdfInputsDirectoryPath, resultFileName) String resultFileName = "Output_" + Path.GetFileNameWithoutExtension(inputPdfFilePath) + String pdfInputsDirectoryPath = System.IO.Path.GetDirectoryName(inputPdfFilePath) Int pagesAmount = pdfReader.NumberOfPages PdfReader pdfReader = new PdfReader(inputPdfStream) Using (Stream inputPdfStream = new FileStream(inputPdfFilePath, FileMode.Open, FileAccess.Read, FileShare.Read)) OpenFileDialog ofd = new OpenFileDialog()


I need proposals what code block must be after comment in code - //Code to rotate only content of pdf page 90 or 270 degrees leaving page in Portrait orientation? I tried to use PdfDictionary class and tested a lot of code variations but the content wasn't rotated as required. Page must leave in Portrait orientation, but the shrunk content must be rotated. Then the next requirement is to rotate content of the page 90 or 270 degrees without rotating the page. For this reason I use PDFStamper class which in the code below successfully shrinks the content. I need to shrink the existing content of every page and then add additional information into every page. I have pdf file in which are lot of post labels pages that have Portrait orientation.
