Skip to main content

HtmlConverter

Struct HtmlConverter 

Source
pub struct HtmlConverter;
👎Deprecated since 0.2.0:

Use pdf_oxide::pipeline::converters::HtmlOutputConverter instead. The new converter is part of the unified TextPipeline architecture and provides better feature support and maintainability.

Expand description

Converter for PDF to HTML format.

Supports both semantic HTML generation and layout-preserved HTML with CSS positioning.

§Examples

use pdf_oxide::PdfDocument;
use pdf_oxide::converters::{HtmlConverter, ConversionOptions};

let mut doc = PdfDocument::open("paper.pdf")?;
let chars = doc.extract_spans(0)?;

let converter = HtmlConverter::new();

// Semantic HTML
let options = ConversionOptions::default();
let html = converter.convert_page(&chars, &options)?;

// Layout-preserved HTML
let layout_options = ConversionOptions {
    preserve_layout: true,
    ..Default::default()
};
let layout_html = converter.convert_page(&chars, &layout_options)?;

Implementations§

Source§

impl HtmlConverter

Source

pub fn new() -> Self

Create a new HTML converter.

§Examples
use pdf_oxide::converters::HtmlConverter;

let converter = HtmlConverter::new();
Source

pub fn convert_page_from_spans( &self, spans: &[TextSpan], options: &ConversionOptions, ) -> Result<String>

Convert a page to HTML format from text spans (PDF spec compliant - RECOMMENDED).

This is the recommended method that uses PDF-native text spans instead of character-based extraction. Routes to either semantic or layout-preserved HTML based on the preserve_layout option.

Benefits over character-based conversion:

  • PDF spec compliant (ISO 32000-1:2008, Section 9.4.4 NOTE 6)
  • No character splitting issues
  • Preserves PDF’s text positioning intent
  • Much faster (no DBSCAN clustering needed)
  • More robust for complex layouts
§Arguments
  • spans - The text spans extracted from the page via extract_spans()
  • options - Conversion options controlling the output
§Returns

A string containing the HTML representation of the page.

§Errors

Returns an error if conversion fails.

Source

pub fn convert_page_semantic_from_spans( &self, spans: &[TextSpan], _options: &ConversionOptions, ) -> Result<String>

Convert a page to semantic HTML from text spans (PDF spec compliant - RECOMMENDED).

Generates clean HTML with proper semantic tags (h1, h2, h3, p) from PDF text spans.

§Arguments
  • spans - The text spans extracted from the page
  • options - Conversion options controlling the output
§Returns

A string containing semantic HTML.

§Errors

Returns an error if conversion fails.

Source

pub fn convert_page_preserve_layout_from_spans( &self, spans: &[TextSpan], _options: &ConversionOptions, ) -> Result<String>

Convert a page to layout-preserved HTML from text spans (PDF spec compliant - RECOMMENDED).

Generates HTML with absolute positioning to match the PDF layout exactly. Each text span is wrapped in a div with CSS positioning.

§Arguments
  • spans - The text spans extracted from the page
  • options - Conversion options controlling the output
§Returns

A string containing HTML with CSS positioning.

§Errors

Returns an error if conversion fails.

Source

pub fn convert_page( &self, chars: &[TextChar], options: &ConversionOptions, ) -> Result<String>

Convert a page to HTML format (character-based - DEPRECATED).

Routes to either semantic or layout-preserved conversion based on options.

§Arguments
  • chars - The text characters extracted from the page
  • options - Conversion options controlling the output
§Returns

A string containing the HTML representation of the page.

§Errors

Returns an error if clustering or conversion fails.

Source

pub fn convert_page_semantic( &self, chars: &[TextChar], options: &ConversionOptions, ) -> Result<String>

Convert a page to semantic HTML.

Generates clean HTML with proper semantic tags (h1, h2, h3, p).

§Arguments
  • chars - The text characters extracted from the page
  • options - Conversion options controlling the output
§Returns

A string containing semantic HTML.

§Errors

Returns an error if clustering or conversion fails.

Source

pub fn convert_page_preserve_layout( &self, chars: &[TextChar], _options: &ConversionOptions, ) -> Result<String>

Convert a page to layout-preserved HTML.

Generates HTML with absolute positioning to match the PDF layout exactly. Each text element is wrapped in a div with CSS positioning.

§Arguments
  • chars - The text characters extracted from the page
  • options - Conversion options controlling the output
§Returns

A string containing HTML with CSS positioning.

§Errors

Returns an error if clustering or conversion fails.

Trait Implementations§

Source§

impl Debug for HtmlConverter

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for HtmlConverter

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

Source§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

Source§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

Source§

fn implicit( self, class: Class, constructed: bool, tag: u32, ) -> TaggedParser<'a, Implicit, Self, E>

Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<R, P> ReadPrimitive<R> for P
where R: Read + ReadEndian<P>, P: Default,

Source§

fn read_from_little_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_little_endian().
Source§

fn read_from_big_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_big_endian().
Source§

fn read_from_native_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_native_endian().
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<U, T> ToOwnedObj<U> for T
where U: FromObjRef<T>,

Source§

fn to_owned_obj(&self, data: FontData<'_>) -> U

Convert this type into T, using the provided data to resolve any offsets.
Source§

impl<U, T> ToOwnedTable<U> for T
where U: FromTableRef<T>,

Source§

fn to_owned_table(&self) -> U

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> Ungil for T
where T: Send,