使用 Rust 向 PDF 添加文本
Contents
[
Hide
]
要向现有 PDF 文件添加文本:
- 打开 PDF 文件。
- 使用以下方式将文本添加到 PDF 文档中 page_add_text function.
- 将修改保存到同一文件。
添加文本
以下代码片段展示了如何在现有 PDF 文件中添加文本。
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(())
}