Orientación Vertical & Horizontal
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
Orientación Vertical & Horizontal

Orientación Vertical & Horizontal

IronPDF for Python admite tanto la orientación de página horizontal como vertical para nuevos PDFs y proporciona control de rotación por página para documentos existentes.

Empezando

Para nuevos PDFs, configure RenderingOptions.PaperOrientation antes de llamar a cualquier método de renderizado. Para PDFs existentes, utilice SetPageRotation o SetAllPageRotations en un PdfDocument cargado para rotar páginas individuales o todo el documento.

Entender el código

Nuevos PDFs

  • PaperOrientation = PdfPaperOrientation.Landscape: Renderiza el PDF en orientación horizontal. Use Portrait para volver al diseño vertical predeterminado.
  • Funciona con RenderHtmlAsPdf, RenderHtmlFileAsPdf y RenderUrlAsPdf.

PDFs existentes

  • PdfDocument.FromFile(path): Carga un archivo PDF existente.
  • Pages[0].PageRotation: Lee la rotación actual de la primera página (índice basado en cero).
  • SetPageRotation(PageIndex, Rotation): Rota una sola página al ángulo especificado.
  • SetAllPageRotations(Rotation): Aplica la misma rotación a cada página del documento.

Valores de Rotación

El enumerador PdfPageRotation ofrece cuatro opciones:

ValorGrados
None0°
Clockwise9090°
Clockwise180180°
Clockwise270270°
¡Aprende a personalizar el diseño de PDF con IronPDF for Python!

¿Listo para empezar?

Versión:2026.11recién publicada