from ironpdf import * # For NEW PDF Documents use PdfPaperOrientation # PdfPaperOrientation: To choose Landscape or Portrait Orientation in a new PDF document renderer = ChromePdfRenderer() renderer.RenderingOptions.PaperOrientation = PdfPaperOrientation.Landscape new_pdf_from_html = renderer.RenderHtmlAsPdf("<h1> Hello World! </h1>") new_pdf_from_html_file = renderer.RenderHtmlFileAsPdf("example.html") new_pdf_from_url = renderer.RenderUrlAsPdf("https://ironpdf.com") # For EXISTING PDFs use PageRotation # PageRotation: To rotate a PDF page and all of its contents existing_pdf = PdfDocument.FromFile("old_report.pdf") # Get rotation value get_rotation_first_page = existing_pdf.Pages[0].PageRotation # Rotate specified page existing_pdf.SetPageRotation(PageIndex=0, Rotation=PdfPageRotation.Clockwise90) # Rotate ALL pages existing_pdf.SetAllPageRotations(PdfPageRotation.Clockwise270)
纵向和横向方向