A step-by-step guide for replacing Apryse (PDFTron) with PDFluent. Covers dependency setup, license initialization, text extraction, form filling, and saving.
cargo add pdfluentApryse ships a native C++ DLL (PDFNetC.dll on Windows, libPDFNetC.so on Linux) alongside the managed wrapper. Remove both and add pdfluent to Cargo.toml.
<!-- .csproj -->
<PackageReference Include="PDFTron.NET" Version="10.4.0" />
<!-- Also requires PDFNetC.dll in your output directory --># Cargo.toml
[dependencies]
pdfluent = "0.9"Apryse requires calling PDFNet.Initialize() with a license key before any API use. PDFluent reads the license from an environment variable or config file.
using Apryse;
// Must call before any Apryse API
PDFNet.Initialize("YOUR_LICENSE_KEY_HERE");// Set PDFLUENT_LICENSE env var, or configure in pdfluent.toml
// No explicit initialization call requiredApryse uses PDFDoc plus TextExtractor. PDFluent uses Document::open and page.extract_text().
using Apryse;
using var doc = new PDFDoc("invoice.pdf");
doc.InitSecurityHandler();
var page = doc.GetPage(1);
var extractor = new TextExtractor();
extractor.Begin(page);
string text = extractor.GetAsText();
Console.WriteLine(text);use pdfluent::Document;
let doc = Document::open("invoice.pdf")?;
let text = doc.page(0)?.extract_text()?;
println!("{}", text);Apryse uses doc.GetField() to retrieve and set individual field values. PDFluent uses an acroform handle.
using var doc = new PDFDoc("form.pdf");
doc.InitSecurityHandler();
var field = doc.GetField("company_name");
field.SetValue("Acme Corp");
var dateField = doc.GetField("contract_date");
dateField.SetValue("2024-04-14");
doc.Save("form_filled.pdf", SDFDoc.SaveOptions.e_linearized);
PDFNet.Terminate();let mut doc = Document::open("form.pdf")?;
let mut form = doc.acroform()?;
form.set_field("company_name", "Acme Corp")?;
form.set_field("contract_date", "2024-04-14")?;
doc.save("form_filled.pdf")?;Apryse Save() takes a SaveOptions flags enum. PDFluent save() writes to the output path with sane defaults.
doc.Save("output.pdf", SDFDoc.SaveOptions.e_linearized);
PDFNet.Terminate(); // must clean updoc.save("output.pdf")?;
// Rust drops doc automatically