Itext Scaling a Rotated Page

Viewed 25

I am trying to scale a rotated PDF page see following image before rotation Width: 792.0pt Height: 612.0pt Original PDF PageSize

After Rotation here is now the new value Width: 612.0pt Height: 792.0pt see again following image: Rotated PDF PageSize

here is my code:

  PdfFormXObject page = srcDocument.GetPage(3).CopyAsFormXObject(writeDocument);
                new PdfCanvas(pdfPage, true).AddXObject(page, 0, 0);
                if (srcDocument.GetPage(3).GetRotation() != 0)
                    pdfPage.SetRotation(srcDocument.GetPage(3).GetRotation());


                Rectangle crop = new Rectangle(float.Parse("595.266"), float.Parse("765.342"));
                pdfPage.SetMediaBox(crop);
                pdfPage.SetCropBox(crop);


                new PdfCanvas(pdfPage, true).WriteLiteral(string.Format("\nq {0} 0 0 {1} {2} {3} cm\nq\n",  0.75159, 1.2505, 0, 0));
                new PdfCanvas(pdfPage.NewContentStreamBefore(), /*"\nq 1 0 0 1 25 0 cm\nq\n"*/
                 pdfPage.GetResources(), writeDocument).WriteLiteral(string.Format("\nq {0} 0 0 {1} {2} {3} cm\nq\n", 0.75159, 1.2505, 0, 0));

The result I am getting is the Opposite where Width is 765.3 Height is 595.3 where my expected size is Width is 595.3 Height is 765.3 see following image: Scaled PDF Page

0 Answers
Related