pub struct HtmlConverter;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
impl HtmlConverter
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new HTML converter.
§Examples
use pdf_oxide::converters::HtmlConverter;
let converter = HtmlConverter::new();Sourcepub fn convert_page_from_spans(
&self,
spans: &[TextSpan],
options: &ConversionOptions,
) -> Result<String>
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 viaextract_spans()options- Conversion options controlling the output
§Returns
A string containing the HTML representation of the page.
§Errors
Returns an error if conversion fails.
Sourcepub fn convert_page_semantic_from_spans(
&self,
spans: &[TextSpan],
_options: &ConversionOptions,
) -> Result<String>
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 pageoptions- Conversion options controlling the output
§Returns
A string containing semantic HTML.
§Errors
Returns an error if conversion fails.
Sourcepub fn convert_page_preserve_layout_from_spans(
&self,
spans: &[TextSpan],
_options: &ConversionOptions,
) -> Result<String>
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 pageoptions- Conversion options controlling the output
§Returns
A string containing HTML with CSS positioning.
§Errors
Returns an error if conversion fails.
Sourcepub fn convert_page(
&self,
chars: &[TextChar],
options: &ConversionOptions,
) -> Result<String>
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 pageoptions- Conversion options controlling the output
§Returns
A string containing the HTML representation of the page.
§Errors
Returns an error if clustering or conversion fails.
Sourcepub fn convert_page_semantic(
&self,
chars: &[TextChar],
options: &ConversionOptions,
) -> Result<String>
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 pageoptions- Conversion options controlling the output
§Returns
A string containing semantic HTML.
§Errors
Returns an error if clustering or conversion fails.
Sourcepub fn convert_page_preserve_layout(
&self,
chars: &[TextChar],
_options: &ConversionOptions,
) -> Result<String>
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 pageoptions- 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
impl Debug for HtmlConverter
Auto Trait Implementations§
impl Freeze for HtmlConverter
impl RefUnwindSafe for HtmlConverter
impl Send for HtmlConverter
impl Sync for HtmlConverter
impl Unpin for HtmlConverter
impl UnsafeUnpin for HtmlConverter
impl UnwindSafe for HtmlConverter
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
ReadEndian::read_from_little_endian().Source§impl<U, T> ToOwnedObj<U> for Twhere
U: FromObjRef<T>,
impl<U, T> ToOwnedObj<U> for Twhere
U: FromObjRef<T>,
Source§fn to_owned_obj(&self, data: FontData<'_>) -> U
fn to_owned_obj(&self, data: FontData<'_>) -> U
T, using the provided data to resolve any offsets.