Convert PDF to EPUB, TeX, Text, XPS in Rust

Convert PDF to EPUB

EPUB is a free and open e-book standard from the International Digital Publishing Forum (IDPF). Files have the extension .epub. EPUB is designed for reflowable content, meaning that an EPUB reader can optimize text for a particular display device. EPUB also supports fixed-layout content. The format is intended as a single format that publishers and conversion houses can use in-house, as well as for distribution and sale. It supersedes the Open eBook standard.

The provided Rust code snippet demonstrates how to convert a PDF document into a EPUB using the Aspose.PDF library:

  1. Open a PDF document.
  2. Convert a PDF file to EPUB using save_epub function.

  use asposepdf::Document;

  fn main() -> Result<(), Box<dyn std::error::Error>> {
      // Open a PDF-document with filename
      let pdf = Document::open("sample.pdf")?;

      // Convert and save the previously opened PDF-document as Epub-document
      pdf.save_epub("sample.epub")?;

      Ok(())
  }

Convert PDF to TeX

Aspose.PDF for Rust support converting PDF to TeX. The LaTeX file format is a text file format with the special markup and used in TeX-based document preparation system for high-quality typesetting.

The provided Rust code snippet demonstrates how to convert a PDF document into a TeX using the Aspose.PDF library:

  1. Open a PDF document.
  2. Convert a PDF file to TeX using save_tex function.

  use asposepdf::Document;

  fn main() -> Result<(), Box<dyn std::error::Error>> {
      // Open a PDF-document with filename
      let pdf = Document::open("sample.pdf")?;

      // Convert and save the previously opened PDF-document as TeX-document
      pdf.save_tex("sample.tex")?;

      Ok(())
  }

Convert PDF to TXT

The provided Rust code snippet demonstrates how to convert a PDF document into a TXT using the Aspose.PDF library:

  1. Open a PDF document.
  2. Convert a PDF file to TXT using save_txt function.

  use asposepdf::Document;

  fn main() -> Result<(), Box<dyn std::error::Error>> {
      // Open a PDF-document with filename
      let pdf = Document::open("sample.pdf")?;

      // Convert and save the previously opened PDF-document as Txt-document
      pdf.save_txt("sample.txt")?;

      Ok(())
  }

Convert PDF to XPS

The XPS file type is primarily associated with the XML Paper Specification by Microsoft Corporation. The XML Paper Specification (XPS), formerly codenamed Metro and subsuming the Next Generation Print Path (NGPP) marketing concept, is Microsoft’s initiative to integrate document creation and viewing into the Windows operating system.

Aspose.PDF for Rust gives a possibility to convert PDF files to XPS format. Let try to use the presented code snippet for converting PDF files to XPS format with Rust.

The provided Rust code snippet demonstrates how to convert a PDF document into a XPS using the Aspose.PDF library:

  1. Open a PDF document.
  2. Convert a PDF file to XPS using save_xps function.

  use asposepdf::Document;

  fn main() -> Result<(), Box<dyn std::error::Error>> {
      // Open a PDF-document with filename
      let pdf = Document::open("sample.pdf")?;

      // Convert and save the previously opened PDF-document as Xps-document
      pdf.save_xps("sample.xps")?;

      Ok(())
  }

Convert PDF to Grayscale PDF

The provided Rust code snippet demonstrates how to convert the first page of a PDF document into a Grayscale PDF using the Aspose.PDF library:

  1. Open a PDF document.
  2. Convert a PDF Page to Grayscale PDF using page_grayscale function.

This example converts a specific page of your PDF to Grayscale:


  use asposepdf::Document;

  fn main() -> Result<(), Box<dyn std::error::Error>> {
      // Open a PDF-document from file
      let pdf = Document::open("sample.pdf")?;

      // Convert page to black and white
      pdf.page_grayscale(1)?;

      // Save the previously opened PDF-document with new filename
      pdf.save_as("sample_page1_grayscale.pdf")?;

      Ok(())
  }