Bearbeitungsübersicht
PDF Oxide bietet zwei API-Ebenen zum Bearbeiten vorhandener PDFs: die empfohlene High-Level-Klasse Pdf und den Low-Level-DocumentEditor. Beide ermöglichen das Öffnen eines PDFs, das Ändern von Inhalt und Metadaten, das Verfolgen von Änderungen und das Speichern des Ergebnisses.
Binding-Abdeckung für die Bearbeitung. Die umfangreichste Bearbeitungsfunktionalität bieten Python, Rust und WASM — sie unterstützen Seitenoperationen, Text-/Bildbearbeitung, Annotationsverarbeitung, Verschlüsselung und Schwärzung. Go bietet eine umfangreiche Editor-API (Metadaten, Seiten drehen/verschieben/löschen, Bereich löschen, Formular ausfüllen/abflachen, zuschneiden, zusammenführen, verschlüsselt speichern). C# unterstützt derzeit Metadaten-Bearbeitung (
Title/Author/Subject), Formularausfüllung (SetFormFieldValue),FlattenFormsundSave/SaveAsyncaufDocumentEditor; Operationen auf Seitenebene, Verschlüsselung, Schwärzung und Text-/Bildbearbeitung sind in der öffentlichen C#-API noch nicht verfügbar — verwenden Sie für diese Aufgaben CLI, Go, Python oder Rust.
PDF zum Bearbeiten öffnen
Python
from pdf_oxide import PdfDocument
doc = PdfDocument("input.pdf")
Der Editor wird beim ersten Änderungsaufruf lazy initialisiert. Sie können sofort mit dem Lesen beginnen; der Editor wird aktiviert, wenn Sie eine schreibende Methode wie set_title() oder page() aufrufen.
WASM
import { WasmPdfDocument } from "pdf-oxide-wasm";
const bytes = new Uint8Array(/* file bytes */);
const doc = new WasmPdfDocument(bytes);
Rust
Verwenden Sie die einheitliche Pdf-API:
use pdf_oxide::api::Pdf;
let mut doc = Pdf::open("input.pdf")?;
Oder verwenden Sie DocumentEditor direkt für mehr Kontrolle auf niedrigerer Ebene:
use pdf_oxide::editor::DocumentEditor;
let mut editor = DocumentEditor::open("input.pdf")?;
Go
package main
import (
"log"
pdfoxide "github.com/yfedoseev/pdf_oxide/go"
)
func main() {
editor, err := pdfoxide.OpenEditor("input.pdf")
if err != nil { log.Fatal(err) }
defer editor.Close()
}
C#
using PdfOxide;
using var editor = DocumentEditor.Open("input.pdf");
Java
import fyi.oxide.pdf.DocumentEditor;
import java.nio.file.Path;
try (DocumentEditor editor = DocumentEditor.open(Path.of("input.pdf"))) {
// ...
}
Kotlin
import fyi.oxide.pdf.DocumentEditor
import java.nio.file.Path
DocumentEditor.open(Path.of("input.pdf")).use { editor ->
// ...
}
Scala
import fyi.oxide.pdf.DocumentEditor
import scala.util.Using
Using.resource(DocumentEditor.open("input.pdf")) { editor =>
// ...
}
Clojure
(require '[pdf-oxide.core :as pdf])
(with-open [editor (pdf/editor "input.pdf")]
;; ...
)
Ruby
require 'pdf_oxide'
PdfOxide::DocumentEditor.open('input.pdf') do |editor|
# ...
end
PHP
use PdfOxide\DocumentEditor;
$editor = DocumentEditor::open('input.pdf');
C++
#include <pdf_oxide/pdf_oxide.hpp>
auto editor = pdf_oxide::DocumentEditor::open("input.pdf");
Swift
import PdfOxide
let editor = try DocumentEditor.open("input.pdf")
Dart
import 'package:pdf_oxide/pdf_oxide.dart';
final editor = DocumentEditor.open('input.pdf');
R
library(pdfoxide)
editor <- pdf_editor_open("input.pdf")
Julia
using PdfOxide
editor = open_editor("input.pdf")
Zig
const pdf_oxide = @import("pdf_oxide");
var editor = try pdf_oxide.DocumentEditor.open("input.pdf");
defer editor.deinit();
Objective-C
#import "POXPdfOxide.h"
NSError *err = nil;
POXDocumentEditor *editor = [POXDocumentEditor openEditor:@"input.pdf" error:&err];
Elixir
{:ok, editor} = PdfOxide.open_editor("input.pdf")
Änderungen prüfen
Vor dem Speichern können Sie prüfen, ob Änderungen vorgenommen wurden:
Python
doc = PdfDocument("input.pdf")
print(doc.is_modified) # False -- no changes yet
doc.set_title("Updated Title")
print(doc.is_modified) # True
Rust
let mut doc = Pdf::open("input.pdf")?;
assert!(!doc.is_modified());
doc.editor().unwrap().set_title("Updated Title");
assert!(doc.is_modified());
Go
editor, _ := pdfoxide.OpenEditor("input.pdf")
defer editor.Close()
modified, _ := editor.IsModified()
fmt.Println(modified) // false
_ = editor.SetTitle("Updated Title")
modified, _ = editor.IsModified()
fmt.Println(modified) // true
C#
using var editor = DocumentEditor.Open("input.pdf");
Console.WriteLine(editor.IsModified); // false
editor.Title = "Updated Title";
Console.WriteLine(editor.IsModified); // true
PHP
$editor = DocumentEditor::open('input.pdf');
var_dump($editor->isModified()); // false
$editor->setProducer('pdf_oxide');
var_dump($editor->isModified()); // true
C++
auto editor = pdf_oxide::DocumentEditor::open("input.pdf");
bool before = editor.is_modified(); // false
editor.set_producer("pdf_oxide");
bool after = editor.is_modified(); // true
Swift
let editor = try DocumentEditor.open("input.pdf")
try editor.isModified() // false
try editor.setProducer("pdf_oxide")
try editor.isModified() // true
Dart
final editor = DocumentEditor.open('input.pdf');
editor.isModified(); // false
editor.setProducer('pdf_oxide');
editor.isModified(); // true
R
editor <- pdf_editor_open("input.pdf")
pdf_editor_is_modified(editor) # FALSE
pdf_editor_set_producer(editor, "pdf_oxide")
pdf_editor_is_modified(editor) # TRUE
Julia
editor = open_editor("input.pdf")
is_modified(editor) # false
set_producer(editor, "pdf_oxide")
is_modified(editor) # true
Zig
var editor = try pdf_oxide.DocumentEditor.open("input.pdf");
defer editor.deinit();
_ = editor.isModified(); // false
try editor.setProducer("pdf_oxide");
_ = editor.isModified(); // true
Objective-C
NSError *err = nil;
POXDocumentEditor *editor = [POXDocumentEditor openEditor:@"input.pdf" error:&err];
[editor isModified]; // NO
[editor setProducer:@"pdf_oxide" error:&err];
[editor isModified]; // YES
Elixir
{:ok, editor} = PdfOxide.open_editor("input.pdf")
PdfOxide.editor_modified?(editor) # false
PdfOxide.set_producer(editor, "pdf_oxide")
PdfOxide.editor_modified?(editor) # true
Speichern
Python
doc = PdfDocument("input.pdf")
doc.set_title("New Title")
doc.save("output.pdf")
WASM
import { WasmPdfDocument } from "pdf-oxide-wasm";
const bytes = new Uint8Array(/* file bytes */);
const doc = new WasmPdfDocument(bytes);
doc.setTitle("New Title");
const output = doc.save();
doc.free();
Rust
let mut doc = Pdf::open("input.pdf")?;
doc.editor().unwrap().set_title("New Title");
doc.save("output.pdf")?;
// Or save to a new path
doc.save_as("copy.pdf")?;
Go
editor, _ := pdfoxide.OpenEditor("input.pdf")
defer editor.Close()
_ = editor.SetTitle("New Title")
_ = editor.Save("output.pdf")
C#
using var editor = DocumentEditor.Open("input.pdf");
editor.Title = "New Title";
editor.Save("output.pdf");
PHP
$editor = DocumentEditor::open('input.pdf');
$editor->setProducer('pdf_oxide');
$editor->saveTo('output.pdf');
C++
auto editor = pdf_oxide::DocumentEditor::open("input.pdf");
editor.set_producer("pdf_oxide");
editor.save("output.pdf");
Swift
let editor = try DocumentEditor.open("input.pdf")
try editor.setProducer("pdf_oxide")
try editor.save("output.pdf")
Dart
final editor = DocumentEditor.open('input.pdf');
editor.setProducer('pdf_oxide');
editor.save('output.pdf');
R
editor <- pdf_editor_open("input.pdf")
pdf_editor_set_producer(editor, "pdf_oxide")
pdf_editor_save(editor, "output.pdf")
Julia
editor = open_editor("input.pdf")
set_producer(editor, "pdf_oxide")
save(editor, "output.pdf")
Zig
var editor = try pdf_oxide.DocumentEditor.open("input.pdf");
defer editor.deinit();
try editor.setProducer("pdf_oxide");
try editor.save("output.pdf");
Objective-C
NSError *err = nil;
POXDocumentEditor *editor = [POXDocumentEditor openEditor:@"input.pdf" error:&err];
[editor setProducer:@"pdf_oxide" error:&err];
[editor saveToPath:@"output.pdf" error:&err];
Elixir
{:ok, editor} = PdfOxide.open_editor("input.pdf")
PdfOxide.set_producer(editor, "pdf_oxide")
PdfOxide.editor_save(editor, "output.pdf")
Die Methode save() führt standardmäßig eine vollständige Neuschreibung des PDFs durch. Erweiterte Speicheroptionen (inkrementelle Updates, Verschlüsselung) finden Sie unter Verschlüsselung und Sicherheit.
Dokumentmetadaten
Lesen und schreiben Sie die Standard-PDF-Metadatenfelder: Titel, Autor, Betreff und Stichwörter.
Python
from pdf_oxide import PdfDocument
doc = PdfDocument("input.pdf")
# Set metadata
doc.set_title("Quarterly Report")
doc.set_author("Jane Smith")
doc.set_subject("Q4 2025 Financial Results")
doc.set_keywords("finance, quarterly, 2025")
doc.save("output.pdf")
WASM
import { WasmPdfDocument } from "pdf-oxide-wasm";
const bytes = new Uint8Array(/* file bytes */);
const doc = new WasmPdfDocument(bytes);
// Set metadata
doc.setTitle("Quarterly Report");
doc.setAuthor("Jane Smith");
doc.setSubject("Q4 2025 Financial Results");
doc.setKeywords("finance, quarterly, 2025");
const output = doc.save();
doc.free();
Rust
use pdf_oxide::editor::DocumentEditor;
let mut editor = DocumentEditor::open("input.pdf")?;
// Read metadata
if let Some(title) = editor.title()? {
println!("Current title: {}", title);
}
if let Some(author) = editor.author()? {
println!("Current author: {}", author);
}
if let Some(subject) = editor.subject()? {
println!("Current subject: {}", subject);
}
if let Some(keywords) = editor.keywords()? {
println!("Current keywords: {}", keywords);
}
// Set metadata
editor.set_title("Quarterly Report");
editor.set_author("Jane Smith");
editor.set_subject("Q4 2025 Financial Results");
editor.set_keywords("finance, quarterly, 2025");
editor.save("output.pdf")?;
Go
editor, _ := pdfoxide.OpenEditor("input.pdf")
defer editor.Close()
if t, err := editor.Title(); err == nil { fmt.Println("Current title:", t) }
if a, err := editor.Author(); err == nil { fmt.Println("Current author:", a) }
_ = editor.SetTitle("Quarterly Report")
_ = editor.SetAuthor("Jane Smith")
_ = editor.SetSubject("Q4 2025 Financial Results")
_ = editor.Save("output.pdf")
C#
using var editor = DocumentEditor.Open("input.pdf");
if (editor.Title is { } t) Console.WriteLine($"Current title: {t}");
if (editor.Author is { } a) Console.WriteLine($"Current author: {a}");
if (editor.Subject is { } s) Console.WriteLine($"Current subject: {s}");
editor.Title = "Quarterly Report";
editor.Author = "Jane Smith";
editor.Subject = "Q4 2025 Financial Results";
editor.Save("output.pdf");
Dokumentinformationen
Quellpfad und Version
use pdf_oxide::editor::DocumentEditor;
let editor = DocumentEditor::open("input.pdf")?;
// Path to the original file
println!("Source: {}", editor.source_path());
// PDF version as (major, minor)
let (major, minor) = editor.version();
println!("PDF version: {}.{}", major, minor);
// Number of pages
println!("Pages: {}", editor.current_page_count());
Vollständige API-Referenz
DocumentEditor
| Methode | Rückgabewert | Beschreibung |
|---|---|---|
open(path) |
Result<DocumentEditor> |
PDF zum Bearbeiten öffnen |
is_modified() |
bool |
Prüfen, ob Änderungen vorliegen |
source_path() |
&str |
Pfad zum Quell-PDF |
source() |
&PdfDocument |
Schreibgeschützter Zugriff auf das Quelldokument |
version() |
(u8, u8) |
PDF-Version (Major, Minor) |
current_page_count() |
usize |
Anzahl der Seiten im Dokument |
title() |
Result<Option<String>> |
Dokumenttitel abrufen |
set_title(title) |
() |
Dokumenttitel setzen |
author() |
Result<Option<String>> |
Dokumentautor abrufen |
set_author(author) |
() |
Dokumentautor setzen |
subject() |
Result<Option<String>> |
Dokumentbetreff abrufen |
set_subject(subject) |
() |
Dokumentbetreff setzen |
keywords() |
Result<Option<String>> |
Dokumentstichwörter abrufen |
set_keywords(keywords) |
() |
Dokumentstichwörter setzen |
save(path) |
Result<()> |
Mit vollständiger Neuschreibung speichern |
save_with_options(path, options) |
Result<()> |
Mit benutzerdefinierten Optionen speichern |
Pdf (Einheitliche API)
| Methode | Rückgabewert | Beschreibung |
|---|---|---|
Pdf::open(path) |
Result<Pdf> |
PDF zum Bearbeiten öffnen |
Pdf::open_editor(path) |
Result<DocumentEditor> |
Direkt als DocumentEditor öffnen |
is_modified() |
bool |
Prüfen, ob Änderungen vorliegen |
save(path) |
Result<()> |
Dokument speichern |
save_as(path) |
Result<()> |
Unter neuem Pfad speichern |
page(index) |
Result<PdfPage> |
Seite für DOM-Bearbeitung abrufen |
save_page(page) |
Result<()> |
Geänderte Seite zurückschreiben |
editor() |
Option<&mut DocumentEditor> |
Auf den zugrunde liegenden Editor zugreifen |
Trait EditableDocument
Das Trait EditableDocument definiert den Kern-Bearbeitungsvertrag:
pub trait EditableDocument {
fn get_info(&mut self) -> Result<DocumentInfo>;
fn set_info(&mut self, info: DocumentInfo) -> Result<()>;
fn page_count(&mut self) -> Result<usize>;
fn get_page_info(&mut self, index: usize) -> Result<PageInfo>;
fn remove_page(&mut self, index: usize) -> Result<()>;
fn move_page(&mut self, from: usize, to: usize) -> Result<()>;
fn duplicate_page(&mut self, index: usize) -> Result<usize>;
fn save(&mut self, path: impl AsRef<Path>) -> Result<()>;
fn save_with_options(&mut self, path: impl AsRef<Path>, options: SaveOptions) -> Result<()>;
}
Vollständige DocumentEditor-Methodenübersicht
Die folgenden Tabellen listen alle öffentlichen Methoden der DocumentEditor / Pdf-Editor-Schnittstelle in Rust auf. Jede Zeile verlinkt bei Bedarf auf die Detailanleitung. Die Binding-Verfügbarkeit ist angegeben; Go- / C#-Beispiele finden Sie auf den jeweiligen Seiten.
Metadaten
| Methode | Rust | Python | WASM | Go | C# | Seite |
|---|---|---|---|---|---|---|
title / set_title |
✓ | ✓ | ✓ | ✓ | ✓ | Übersicht |
author / set_author |
✓ | ✓ | ✓ | ✓ | ✓ | Übersicht |
subject / set_subject |
✓ | ✓ | ✓ | ✓ | ✓ | Übersicht |
keywords / set_keywords |
✓ | ✓ | ✓ | ✓ | — | Übersicht |
producer / set_producer |
✓ | ✓ | — | ✓ | — | Übersicht |
creation_date / set_creation_date |
✓ | ✓ | — | ✓ | — | Übersicht |
apply_metadata(info) |
✓ | ✓ | — | ✓ | — | Übersicht |
Seitenoperationen
| Methode | Rust | Python | WASM | Go | C# | Seite |
|---|---|---|---|---|---|---|
remove_page / delete_page |
✓ | ✓ | ✓ | ✓ | — | Seiten |
move_page(from, to) |
✓ | ✓ | — | ✓ | — | Seiten |
duplicate_page(i) |
✓ | ✓ | — | — | — | Seiten |
get_page_rotation / set_page_rotation |
✓ | ✓ | ✓ | ✓ | — | Seiten |
rotate_page_by(i, deg) |
✓ | ✓ | — | — | — | Seiten |
rotate_all_pages(deg) |
✓ | ✓ | ✓ | — | — | Seiten |
get_page_media_box / set_page_media_box |
✓ | ✓ | ✓ | — | — | Seiten |
get_page_crop_box / set_page_crop_box |
✓ | ✓ | ✓ | — | — | Seiten |
crop_margins(l, r, t, b) |
✓ | ✓ | ✓ | ✓ | — | Seiten |
erase_region(page, rect) |
✓ | ✓ | ✓ | ✓ | — | Seiten |
erase_regions(page, rects) |
✓ | ✓ | ✓ | — | — | Seiten |
clear_erase_regions(page) |
✓ | ✓ | — | — | — | Seiten |
Zusammenführen / Aufteilen
| Methode | Rust | Python | WASM | Go | C# | Seite |
|---|---|---|---|---|---|---|
merge_from(path) |
✓ | ✓ | — | ✓ | — | Zusammenführen & Aufteilen |
merge_pages_from(path, pages) |
✓ | ✓ | — | — | — | Zusammenführen & Aufteilen |
extract_pages(pages, output) |
✓ | ✓ | ✓ | — | — | Zusammenführen & Aufteilen |
Merge([]paths) oberste Ebene |
— | — | — | ✓ | — | Zusammenführen & Aufteilen |
Formulare
| Methode | Rust | Python | WASM | Go | C# | Seite |
|---|---|---|---|---|---|---|
get_form_fields() |
✓ | ✓ | ✓ | ✓ | ✓ | Formulare |
get_form_field_value(name) |
✓ | ✓ | ✓ | — | — | Formulare |
has_form_field(name) |
✓ | ✓ | — | — | — | Formulare |
set_form_field_value(name, value) |
✓ | ✓ | ✓ | ✓ | ✓ | Formulare |
add_form_field(widget, page) |
✓ | — | — | — | — | Formulare erstellen |
add_parent_field / add_child_field |
✓ | — | — | — | — | Formulare erstellen |
remove_form_field(name) |
✓ | ✓ | — | — | — | Formulare |
set_form_field_* (readonly, required, tooltip, rect, max_length, alignment, colors, flags) |
✓ | ✓ | — | — | — | Formulare |
flatten_forms_on_page(page) |
✓ | ✓ | ✓ | ✓ | — | Formulare |
flatten_forms() |
✓ | ✓ | ✓ | ✓ | ✓ | Formulare |
export_form_data_fdf(path) |
✓ | ✓ | ✓ | — | — | Formulare |
export_form_data_xfdf(path) |
✓ | ✓ | ✓ | — | — | Formulare |
Annotationen
| Methode | Rust | Python | WASM | Go | C# | Seite |
|---|---|---|---|---|---|---|
flatten_page_annotations(page) |
✓ | ✓ | ✓ | ✓ | — | Annotationen |
flatten_all_annotations() |
✓ | ✓ | ✓ | ✓ | — | Annotationen |
is_page_marked_for_annotation_flatten(page) |
✓ | ✓ | — | — | — | Annotationen |
unmark_page_for_annotation_flatten(page) |
✓ | ✓ | — | — | — | Annotationen |
Schwärzung
| Methode | Rust | Python | WASM | Go | C# | Seite |
|---|---|---|---|---|---|---|
apply_page_redactions(page) |
✓ | ✓ | ✓ | — | — | Schwärzung |
apply_all_redactions() |
✓ | ✓ | ✓ | — | — | Schwärzung |
is_page_marked_for_redaction(page) |
✓ | ✓ | — | — | — | Schwärzung |
unmark_page_for_redaction(page) |
✓ | ✓ | — | — | — | Schwärzung |
XFA
| Methode | Rust | Python | WASM | Go | C# | Seite |
|---|---|---|---|---|---|---|
has_xfa() |
✓ | ✓ | ✓ | ✓ | ✓ | XFA-Formulare |
analyze_xfa() |
✓ | ✓ | — | — | — | XFA-Formulare |
convert_xfa_to_acroform(opts) |
✓ | — | — | — | — | XFA-Formulare |
Speichern
| Methode | Rust | Python | WASM | Go | C# | Seite |
|---|---|---|---|---|---|---|
save(path) |
✓ | ✓ | ✓ | ✓ | ✓ | Übersicht |
save_with_options(path, opts) |
✓ | ✓ | — | — | — | Verschlüsselung |
save_encrypted(path, user, owner) |
✓ | ✓ | ✓ | ✓ | — | Verschlüsselung |
save_with_encryption(path, cfg) |
✓ | ✓ | — | — | — | Verschlüsselung |
save_async / SaveAsync |
— | — | — | — | ✓ | Async |
Hilfsmethoden (Go-Komfortfunktionen)
Als DocumentEditor-Methoden in Go verfügbare Methoden; in Rust über editor.source() zugänglich:
| Methode | Rust | Python | WASM | Go | C# |
|---|---|---|---|---|---|
IsModified |
is_modified() |
is_modified |
— | IsModified() |
IsModified |
SourcePath |
source_path() |
source_path |
— | SourcePath() |
SourcePath |
Version |
version() |
version() |
— | Version() |
— |
PageCount |
current_page_count() |
page_count() |
pageCount() |
PageCount() |
PageCount |
RemoveHeaders / RemoveFooters / RemoveArtifacts |
✓ | ✓ | — | ✓ | ✓ |
Close / Dispose |
Drop |
context manager | free() |
Close() |
Dispose() |
Vollständiger Bearbeitungs-Workflow
Dieses Beispiel zeigt eine vollständige Bearbeitungssitzung: Öffnen, Prüfen, Metadaten ändern, Inhalt bearbeiten und speichern.
Python
from pdf_oxide import PdfDocument
# Open the document
doc = PdfDocument("report.pdf")
print(f"Pages: {doc.page_count()}")
# Update metadata
doc.set_title("Annual Report 2025")
doc.set_author("Finance Team")
# Edit text on page 0
page = doc.page(0)
for text in page.find_text_containing("DRAFT"):
page.set_text(text.id, "FINAL")
doc.save_page(page)
# Save
doc.save("report-final.pdf")
Rust
use pdf_oxide::api::Pdf;
let mut doc = Pdf::open("report.pdf")?;
println!("Pages: {}", doc.page_count()?);
// Update metadata
{
let editor = doc.editor().unwrap();
editor.set_title("Annual Report 2025");
editor.set_author("Finance Team");
}
// Edit text on page 0
let mut page = doc.page(0)?;
let drafts = page.find_text_containing("DRAFT");
for t in &drafts {
page.set_text(t.id(), "FINAL")?;
}
doc.save_page(page)?;
// Save
doc.save("report-final.pdf")?;
Verwandte Seiten
- Textbearbeitung – Text suchen und ersetzen, Schriftarten und Positionierung ändern
- Seitenoperationen – Drehen, Zuschneiden, Zusammenführen und Seiten extrahieren
- Formularfelder bearbeiten – Formularfelder ausfüllen, hinzufügen und abflachen
- Verschlüsselung und Sicherheit – Passwortschutz und Berechtigungen setzen