Skip to content

Referencia de tipos

Todos los tipos públicos en pdf_oxide, organizados por categoría. Para documentación a nivel de método, consulte la Rust API Reference.


Geometría

Point

pub struct Point {
    pub x: f64,
    pub y: f64,
}

Un punto 2D en el espacio de coordenadas PDF (origen en la esquina inferior izquierda, Y incrementa hacia arriba).

Rect

pub struct Rect {
    pub x0: f64,
    pub y0: f64,
    pub x1: f64,
    pub y1: f64,
}

Un rectángulo alineado con los ejes. (x0, y0) es la esquina inferior izquierda, (x1, y1) es la esquina superior derecha. Todas las coordenadas están en puntos PDF (1 punto = 1/72 pulgada).

Python: Accesible como una tupla (x0, y0, x1, y1).

Matrix

pub struct Matrix {
    pub a: f64,
    pub b: f64,
    pub c: f64,
    pub d: f64,
    pub e: f64,
    pub f: f64,
}

Una matriz de transformación afín de 3x3 en el formato de la especificación PDF:

| a  b  0 |
| c  d  0 |
| e  f  1 |

Usada para posicionamiento de texto, colocación de imágenes y transformaciones de Form XObject.


Texto

TextoSpan

pub struct TextSpan {
    pub text: String,
    pub x: f64,
    pub y: f64,
    pub font_name: String,
    pub font_size: f64,
    pub bbox: Rect,
}

Un tramo de texto con estilo idéntico. Retornado por extract_spans().

TextoChar

pub struct TextChar {
    pub char: char,
    pub x: f64,
    pub y: f64,
    pub font_size: f64,
    pub font_name: String,
    pub bbox: Rect,
}

Un solo carácter con posicionamiento preciso. Retornado por extract_chars().

Campos de Python:

Campo Tipo Descripción
char str El carácter
bbox tuple[float, float, float, float] Cuadro delimitador (x0, y0, x1, y1)
font_name str Nombre de fuente
font_size float Tamaño de fuente en puntos
origin_x float Origen X de la línea base
origin_y float Origen Y de la línea base
rotation_degrees float Ángulo de rotación (0–360)
advance_width float Distancia a la siguiente posición de carácter

FontWeight

pub enum FontWeight {
    Thin,       // 100
    ExtraLight, // 200
    Light,      // 300
    Normal,     // 400
    Medium,     // 500
    SemiBold,   // 600
    Bold,       // 700
    ExtraBold,  // 800
    Black,      // 900
}

Color

pub struct Color {
    pub r: f64,
    pub g: f64,
    pub b: f64,
}

Color RGB con componentes en el rango de 0.0 a 1.0.


Página

PáginaSize

pub enum PageSize {
    Letter,         // 612 x 792 pt (8.5 x 11 in)
    A4,             // 595.28 x 841.89 pt (210 x 297 mm)
    Legal,          // 612 x 1008 pt (8.5 x 14 in)
    A3,             // 841.89 x 1190.55 pt
    A5,             // 419.53 x 595.28 pt
    Custom(f32, f32), // Custom width x height in points
}

Métodos:

Método Retorna Descripción
dimensions() (f32, f32) Ancho y alto en puntos

PáginaInfo

pub struct PageInfo {
    pub width: f64,
    pub height: f64,
    pub rotation: i32,
    pub media_box: Rect,
    pub crop_box: Option<Rect>,
    pub trim_box: Option<Rect>,
    pub bleed_box: Option<Rect>,
    pub art_box: Option<Rect>,
}

PáginaLabelStyle

pub enum PageLabelStyle {
    Decimal,        // 1, 2, 3, ...
    UpperRoman,     // I, II, III, ...
    LowerRoman,     // i, ii, iii, ...
    UpperAlpha,     // A, B, C, ...
    LowerAlpha,     // a, b, c, ...
    None,           // No numbering
}

PáginaLabelRange

pub struct PageLabelRange {
    pub start_page: usize,
    pub style: PageLabelStyle,
    pub prefix: Option<String>,
    pub start_number: Option<usize>,
}

Define un rango de etiquetas de página. Por ejemplo, un rango que comienza en la página 0 con estilo LowerRoman y número inicial 1 etiqueta las páginas como i, ii, iii, y así sucesivamente.


Imágenes

ImageFormat

pub enum ImageFormat {
    Jpeg,
    Png,
    Tiff,
    Bmp,
    Gif,
    Jp2,
    Jbig2,
    Ccitt,
    Raw,
    Unknown,
}

ColorSpace

pub enum ColorSpace {
    DeviceRGB,
    DeviceCMYK,
    DeviceGray,
    ICCBased,
    CalRGB,
    CalGray,
    Lab,
    Indexed,
    Pattern,
    Separation,
    DeviceN,
    Unknown,
}

ImageInfo

pub struct ImageContent {
    pub width: u32,
    pub height: u32,
    pub bits_per_component: u8,
    pub color_space: ColorSpace,
    pub format: ImageFormat,
    pub data: Vec<u8>,
    pub bbox: Rect,
    pub horizontal_dpi: Option<f32>,
    pub vertical_dpi: Option<f32>,
}

Métodos:

Método Retorna Descripción
resolution() Option<(f32, f32)> DPI como (horizontal, vertical)
is_high_resolution() bool DPI >= 300
is_medium_resolution() bool DPI 150–299
is_low_resolution() bool DPI < 150
calculate_dpi() Option<(f32, f32)> Calcular desde dimensiones de píxel y bbox

Trazados

PathContent

pub struct PathContent {
    pub operations: Vec<PathOperation>,
    pub stroke_color: Option<Color>,
    pub fill_color: Option<Color>,
    pub stroke_width: f32,
    pub line_cap: LineCap,
    pub line_join: LineJoin,
    pub bbox: Rect,
}

PathOperation

pub enum PathOperation {
    MoveTo { x: f64, y: f64 },
    LineTo { x: f64, y: f64 },
    CurveTo { x1: f64, y1: f64, x2: f64, y2: f64, x3: f64, y3: f64 },
    ClosePath,
    Rect { x: f64, y: f64, width: f64, height: f64 },
}

LineCap

pub enum LineCap {
    Butt,    // Square end at endpoint (default)
    Round,   // Semicircle at endpoint
    Square,  // Square extends half line width past endpoint
}

LineJoin

pub enum LineJoin {
    Miter,   // Sharp corner (default)
    Round,   // Rounded corner
    Bevel,   // Flat corner
}

BlendMode

pub enum BlendMode {
    Normal,
    Multiply,
    Screen,
    Overlay,
    Darken,
    Lighten,
    ColorDodge,
    ColorBurn,
    HardLight,
    SoftLight,
    Difference,
    Exclusion,
}

Usado en el estado de gráficos para composición de transparencia. Establecido vía ExtGState o la API de gráficos.


Elementos de contenido

ContenidoElement

El tipo unión para todos los elementos de contenido de página:

pub enum ContentElement {
    Text(TextContent),
    Image(ImageContent),
    Path(PathContent),
    Table(TableContent),
    Structure(StructureElement),
}

TextoContent

pub struct TextContent {
    pub text: String,
    pub font_name: String,
    pub font_size: f64,
    pub font_weight: FontWeight,
    pub font_style: FontStyle,
    pub color: Color,
    pub bbox: Rect,
}

FontStyle

pub enum FontStyle {
    Normal,
    Italic,
    Oblique,
}

TextoStyle

pub struct TextStyle {
    pub font_name: String,
    pub font_size: f64,
    pub font_weight: FontWeight,
    pub font_style: FontStyle,
    pub color: Color,
}

TableContent

pub struct TableContent {
    pub rows: Vec<TableRowContent>,
    pub column_count: usize,
    pub has_header: bool,
    pub caption: Option<String>,
    pub style: Option<TableContentStyle>,
    pub source: TableSource,
    pub bbox: Rect,
}

TableRowContent

pub struct TableRowContent {
    pub cells: Vec<TableCellContent>,
    pub is_header: bool,
}

TableCellContent

pub struct TableCellContent {
    pub text: String,
    pub row_span: usize,
    pub col_span: usize,
    pub alignment: TableCellAlign,
    pub vertical_alignment: TableCellVAlign,
    pub bbox: Rect,
}

TableCellAlign / TableCellVAlign

pub enum TableCellAlign {
    Left,
    Center,
    Right,
}

pub enum TableCellVAlign {
    Top,
    Middle,
    Bottom,
}

TableSource

pub enum TableSource {
    StructureTree,    // From tagged PDF structure
    Geometric,        // Detected from layout analysis
    Manual,           // User-created
}

EstructuraElement

pub struct StructureElement {
    pub structure_type: String,
    pub children: Vec<ContentElement>,
    pub alt_text: Option<String>,
    pub actual_text: Option<String>,
    pub language: Option<String>,
}

Anotaciones

AnnotationType

pub enum AnnotationSubtype {
    Text,
    Link,
    FreeText,
    Line,
    Square,
    Circle,
    Polygon,
    PolyLine,
    Highlight,
    Underline,
    Squiggly,
    StrikeOut,
    Stamp,
    Caret,
    Ink,
    Popup,
    FileAttachment,
    Sound,
    Movie,
    Screen,
    Widget,
    PrinterMark,
    TrapNet,
    Watermark,
    ThreeD,
    Redact,
    RichMedia,
    Unknown,
}

TextoAnnotationIcon

pub enum TextAnnotationIcon {
    Comment,
    Key,
    Note,
    Help,
    NewParagraph,
    Paragraph,
    Insert,
    Check,
    Circle,
    Cross,
    RightArrow,
    RightPointer,
    Star,
    UpArrow,
    UpLeftArrow,
}

StampType

pub enum StampType {
    Approved,
    Experimental,
    NotApproved,
    AsIs,
    Expired,
    NotForPublicRelease,
    Confidential,
    Final,
    Sold,
    Departmental,
    ForComment,
    TopSecret,
    Draft,
    ForPublicRelease,
}

Códigos de barras

BarcodeType

Requiere la bandera de característica barcodes.

pub enum BarcodeType {
    QrCode,
    Code128,
    Ean13,
    UpcA,
    Code39,
    Itf,
}

Python: Barcode types are passed as strings: "code128", "ean13", "upca", "code39", "ean8", "itf".


Formularios

FieldType / FormFieldType

pub enum FormFieldType {
    Text,
    Button,
    Choice,
    Signature,
}

FormField

pub struct FormField {
    pub name: String,
    pub field_type: FormFieldType,
    pub value: FormFieldValue,
    pub rect: Option<Rect>,
    pub page_index: Option<usize>,
    pub readonly: bool,
    pub required: bool,
}

FormFieldValue

pub enum FormFieldValue {
    None,
    Text(String),
    Boolean(bool),
    Choice(String),
    MultiChoice(Vec<String>),
}

Métodos:

Método Retorna Descripción
is_none() bool Verificar si el valor es None
as_text() Option<&str> Obtener valor de texto
as_bool() Option<bool> Obtener valor booleano
as_choice() Option<&str> Obtener valor de selección
as_multi_choice() Option<&[String]> Obtener valores de selección múltiple

Búsqueda

SearchOptions

pub struct SearchOptions {
    pub case_sensitive: bool,
    pub literal: bool,
    pub whole_word: bool,
    pub max_results: Option<usize>,
    pub page_range: Option<(usize, usize)>,
}

SearchResult

pub struct SearchResult {
    pub page_index: usize,
    pub text: String,
    pub bbox: Rect,
    pub context: Option<String>,
}

Retornado por Pdf::search() y PdfDocument::search(). Cada resultado incluye la página donde se encontró la coincidencia, el texto coincidente, las coordenadas de su cuadro delimitador y contexto circundante opcional.


Configuración

ConversiónOptions

pub struct ConversionOptions {
    pub preserve_layout: bool,
    pub detect_headings: bool,
    pub extract_tables: bool,
    pub include_images: bool,
    pub image_output_dir: Option<String>,
    pub embed_images: bool,
    // ... additional fields
}

TextoConfig

pub struct TextConfig {
    pub detect_headings: bool,
    pub detect_lists: bool,
    pub detect_tables: bool,
    pub merge_spans: bool,
}

RenderOptions

Requiere la bandera de característica rendering.

pub struct RenderOptions {
    pub dpi: f32,
    pub background_color: Option<Color>,
    pub format: ImageFormat,
}

EncryptionConfig

pub struct EncryptionConfig {
    pub user_password: String,
    pub owner_password: String,
    pub algorithm: EncryptionAlgorithm,
    pub permissions: Permissions,
}

Constructor:

EncryptionConfig::new("user_pass", "owner_pass")
    .with_algorithm(EncryptionAlgorithm::Aes256)
    .with_permissions(Permissions::read_only())

EncryptionAlgorithm

pub enum EncryptionAlgorithm {
    Rc4_40,     // V=1, R=2, 40-bit (legacy)
    Rc4_128,    // V=2, R=3, 128-bit (legacy)
    Aes128,     // V=4, R=4, 128-bit
    Aes256,     // V=5, R=6, 256-bit (default, recommended)
}

Permisos

pub struct Permissions {
    pub print: bool,
    pub copy: bool,
    pub modify: bool,
    pub annotate: bool,
    pub fill_forms: bool,
    pub extract: bool,
}

Métodos de fábrica:

Método Descripción
Permissions::all() Todos los permisos habilitados
Permissions::read_only() Solo visualización permitida

PdfConfig

pub struct PdfConfig {
    pub page_size: PageSize,
    pub margins: (f32, f32, f32, f32),  // left, right, top, bottom
    pub font_size: f32,
    pub line_height: f32,
    pub title: Option<String>,
    pub author: Option<String>,
    pub subject: Option<String>,
    pub keywords: Option<String>,
}

Texto Layout

TextoAlign

pub enum TextAlign {
    Left,
    Center,
    Right,
    Justify,
}

RectFilterMode

Para extracción de texto espacial:

pub enum RectFilterMode {
    Intersects,             // Any overlap (default)
    FullyContained,         // Completely within bounds
    MinOverlap(f32),        // Minimum overlap fraction (0.0-1.0)
}

Tipos de cumplimiento

Consulte las páginas de PDF/A, PDF/UA y PDF/X para la documentación completa de cumplimiento.

PdfALevel

pub enum PdfALevel {
    A1a, A1b,
    A2a, A2b, A2u,
    A3a, A3b, A3u,
}

PdfUaLevel

pub enum PdfUaLevel {
    UA1,
    UA2,
}

PdfXLevel

pub enum PdfXLevel {
    X1a2001, X1a2003,
    X3_2002, X3_2003,
    X4, X4p,
    X5g, X5n, X5pg,
    X6, X6n, X6p,
}

Tipos de error

PdfError

pub enum PdfError {
    Io(std::io::Error),
    Parse(String),
    Password,
    PageOutOfRange { index: usize, count: usize },
}
Variante Descripción
Io Fallo de sistema de archivos o E/S
Parse Estructura PDF malformada
Password El documento está encriptado y no se proporcionó contraseña
PageOutOfRange El índice de página solicitado excede el conteo de páginas

Próximos pasos