Orientação retrato e paisagem
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)
pip install ironpdf
Orientação retrato e paisagem

Orientação retrato e paisagem

IronPDF for Python oferece suporte tanto para orientação de página Paisagem quanto Retrato para novos PDFs e fornece controle de rotação por página para documentos existentes.

Começando

Para novos PDFs, defina RenderingOptions.PaperOrientation antes de chamar qualquer método de renderização. Para PDFs existentes, use SetPageRotation ou SetAllPageRotations em um PdfDocument carregado para rotacionar páginas individuais ou todo o documento.

Entendendo o código

Novos PDFs

  • PaperOrientation = PdfPaperOrientation.Landscape: Renderiza o PDF em orientação paisagem. Use Portrait para retornar ao layout padrão vertical.
  • Funciona com RenderHtmlAsPdf, RenderHtmlFileAsPdf e RenderUrlAsPdf.

PDFs Existentes

  • PdfDocument.FromFile(path): Carrega um arquivo PDF existente.
  • Pages[0].PageRotation: Lê a rotação atual da primeira página (índice baseado em zero).
  • SetPageRotation(PageIndex, Rotation): Gira uma única página para o ângulo especificado.
  • SetAllPageRotations(Rotation): Aplica a mesma rotação a cada página do documento.

Valores de Rotação

O enum PdfPageRotation fornece quatro opções:

ValorGraus
None0°
Clockwise9090°
Clockwise180180°
Clockwise270270°
Aprenda a personalizar o layout do PDF com IronPDF for Python!

Pronto para começar?

Versão:2026.11recém-lançado