Add Text to PDF using Rust

Contents
[ ]

To add text to existing PDF file:

  1. Open a PDF file.
  2. Add the text to the PDF document with page_add_text function.
  3. Saves the modifications to the same file.

Adding Text

The following code snippet shows you how to add text in an existing PDF file.


    use asposepdf::Document;

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

        // Add text on page
        pdf.page_add_text(1, "added text")?;

        // Save the previously opened PDF-document
        pdf.save()?;

        Ok(())
    }