[FIXED] PDFBOX-Importseite als Formular rendern versteckte optionale Inhaltsgruppe

Ausgabe

In der letzten Version von PDFbox 2.0.27 und früheren Versionen werden alle deaktivierten optionalen Inhaltsgruppen wieder angezeigt, wenn ein Stream ein PDFormXObject zeichnet.

Dieser Fehlerblock funktioniert alle mit mehrschichtigem PDF. Gibt es eine Möglichkeit, ocg vollständig zu entfernen? Haben sie eine Idee ?

Bearbeiten: In einem neuen PDocument füge ich dieses PDF mit mehreren OCG hinzu.

https://www.pdfill.com/example/pdf_layer_new.pdf

Ergebnis mit allen sichtbaren OCGs (WeTransfer-Datei verfügbar 7 Tage):

https://wetransfer.com/downloads/6550dcb45764d65fe96945b36e5d5b7220221010104929/2f07fd

PDDocument tmpPDFDocument = PDDocument.load(server.pdf());
LayerUtility utility = new LayerUtility(tmpPDFDocument);
PDFormXObject mapPDF = utility.importPageAsForm(tmpPDFDocument, 0);
stream.drawForm(form);

Bearbeiten 2:

Ich versuche, meinen Code maximal zu bereinigen, und nachdem ich es viele Male mit 2.0.27 versucht habe, ist es vielleicht meine Schuld, sehen Sie hier einen Fehler?

Ergebnis:
https://wetransfer.com/downloads/8d8f27f182c5b47bc7226acd5595dff620221011134625/97ea54

    public void createFile2(File output, LayoutPage layoutPage, LocalServer server) throws IOException {
        // Creation du fichier de sortie
        if (!output.exists() && !output.createNewFile())
            throw new IOException();
        // initialise le format de la page pdf
        PDRectangle box = new PDRectangle(0f, 0f, 3000, 3000);
        PDPage page = new PDPage(box);
        // creation du document pdf avec la page, le document doit rester ouvert
        // pendant toute l'impression (ignore sonar recommendation)
        PDDocument document = new PDDocument();
        document.addPage(page);
        // initialise le context
        PDPageContentStream stream = new PDPageContentStream(document, page, PDPageContentStream.AppendMode.OVERWRITE, true, true);
        PDDocument tmpPDFDocument = PDDocument.load(server.pdf()); // file url to import here
        LayerUtility utility = new LayerUtility(tmpPDFDocument);
        utility.wrapInSaveRestore(tmpPDFDocument.getPage(0));

        PDFormXObject mapPDF = utility.importPageAsForm(tmpPDFDocument, 0);
        stream.drawForm(mapPDF);
        stream.close();
        document.save(output);
        document.close();
    }
    ```

Lösung

Richtig

LayerUtility utility = new LayerUtility(tmpPDFDocument);

zu

LayerUtility utility = new LayerUtility(document);

LayerUtility muss mit dem zu ändernden Dokument initialisiert werden.


Beantwortet von –
Tilman Hausherr


Antwort geprüft von –
Katrina (FixError Volunteer)

0 Shares:
Leave a Reply

Your email address will not be published. Required fields are marked *

You May Also Like