Operacje na plikach PDF

PdfFileEditor

PdfFileEditor zapewnia metody do zaawansowanej manipulacji plikami PDF: łączenie dokumentów, wyodrębnianie podzbiorów stron, dzielenie na pojedyncze strony oraz wstawianie stron.

PdfFileEditor editor = new PdfFileEditor();
editor.concatenate("first.pdf", "second.pdf", "merged.pdf");
editor.extract("source.pdf", 2, 5, "pages2to5.pdf");
editor.splitToPages("document.pdf", "output/");

Zmiana rozmiaru zawartości

Użyj ContentsResizeParameters wraz z ContentsResizeValue, aby skalować zawartość strony w ramach istniejących granic strony. Konstruktor przyjmujący sześć argumentów przyjmuje wartości w następującej kolejności: leftMargin, contentsWidth, rightMargin, topMargin, contentsHeight, bottomMargin.

ContentsResizeParameters params = new ContentsResizeParameters(
    ContentsResizeValue.percents(5),
    ContentsResizeValue.percents(90),
    ContentsResizeValue.percents(5),
    ContentsResizeValue.percents(5),
    ContentsResizeValue.percents(90),
    ContentsResizeValue.percents(5)
);
PdfFileEditor editor = new PdfFileEditor();
editor.resizeContents(doc, params);

Obsługa dużych plików

W przypadku dużych dokumentów włącz buforowanie na dysku, aby uniknąć wyczerpania pamięci sterty:

PdfFileEditor editor = new PdfFileEditor();
editor.setUseDiskBuffer(true);
editor.concatenate(inputFiles, "output.pdf");

Powiązane interfejsy API

Zobacz także: PdfPageEditor, ContentsResizeParameters, Document.

Zobacz także

 Polski