Add Text to PDF using Rust
Contents
[
Hide
]
To add text to existing PDF file:
- Open a PDF file.
- Add the text to the PDF document with page_add_text function.
- 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(())
}