0

I'm trying to figure out how to rotate a PDF 90 degrees in iTextSharp, but all I can find is how to rotate it 180 degrees, like so:

PdfContentByte pcb = writer.DirectContentUnder;
int page_count = pdf_reader.NumberOfPages;
for (int z = 1; z <= page_count; z++)
{
    PdfImportedPage pdf_page = writer.GetImportedPage(pdf_reader, z);
    double pdfWidth = pdf_page.Width;
    double pdfHeight = pdf_page.Height;

    if (pdfWidth > pageWidth)
    {
        pcb.AddTemplate(pdf_page, -1f, 0, 0, -1f, pdfWidth, pdfHeight);
    }

    [...]
}

That pcb.AddTemplate line at the end is where the rotation is happening. I've tried changing the parameters, but all I've been able to do is either make the pdf page half its size, or disappear completely.

I'm running out of time to get this resolved; any assistance would be greatly appreaciated.

bmurrell30
  • 565
  • 8
  • 23
  • [Under what circumstances may I add “urgent” or other similar phrases to my question, in order to obtain faster answers?](https://meta.stackoverflow.com/questions/326569/under-what-circumstances-may-i-add-urgent-or-other-similar-phrases-to-my-quest) – Eser Feb 15 '18 at 22:09
  • 1
    The easiest way to rotate a pdf viewer's output by 90° is to change the page rotation value accordingly, not messing around with the content streams. – mkl Feb 16 '18 at 08:05
  • 1
    It's so frustrating to hear people saying they are running out of time, while the information they need is just available on the official web site: https://developers.itextpdf.com/question/how-rotate-page-90-degrees I googled for the keywords "site:itextpdf.com rotate page" and the first hit was the one I needed. I have spent many hours creating all of those pages. Not using that information feels like a lack of respect for the work I've done. – Bruno Lowagie Feb 16 '18 at 11:21

0 Answers0