parse_into_file_with_images

Function parse_into_file_with_images 

Source
pub fn parse_into_file_with_images(
    markdown: String,
    output_path: &str,
    markdown_path: &Path,
    config: ConfigSource<'_>,
    font_config: Option<&FontConfig>,
) -> Result<(), MdpError>
Expand description

Transforms Markdown content with image support into a styled PDF document and saves it to the specified path.

This is a variant of parse_into_file that supports resolving relative image paths based on the markdown document location. Remote images can also be downloaded if the fetch feature is enabled.

§Arguments

  • markdown - The Markdown content to convert
  • output_path - The output file path for the generated PDF
  • markdown_path - Path to the markdown document (for resolving relative image references)
  • config - Configuration source (Default, File path, or Embedded TOML)
  • font_config - Optional font configuration with custom paths and font overrides

§Returns

  • Ok(()) on successful PDF generation and save
  • Err(MdpError) if errors occur during parsing, image loading, or file operations

§Example

use std::error::Error;
use markdown2pdf::config::ConfigSource;
use std::path::Path;

fn example() -> Result<(), Box<dyn Error>> {
    let markdown = "# Document\n![Image](images/photo.jpg)".to_string();
    markdown2pdf::parse_into_file_with_images(
        markdown,
        "output.pdf",
        Path::new("document.md"),
        ConfigSource::Default,
        None
    )?;
    Ok(())
}