[ 
https://issues.apache.org/jira/browse/PDFBOX-5927?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17907155#comment-17907155
 ] 

Tilman Hausherr edited comment on PDFBOX-5927 at 12/20/24 4:18 AM:
-------------------------------------------------------------------

I think I understand most of it now. "Sì" is an indirect object in the source 
file as the value of /DV, this is unusual, but allowed:
!screenshot-3.png!

In {{COSWriterObjectStream.writeObject()}} there is this:
{code:java}
if (!topLevel && this.compressionPool.contains(base))
{
    COSObjectKey key = this.compressionPool.getKey(base);
    if (key == null)
    {
        throw new IOException(
                "Error: Adding unknown object reference to object stream:" + 
object);
    }
    writeObjectReference(output, key);
    return;
}
{code}
Because the key is also an object, the method will be called and will produce 
an indirect object.

Two possible solutions:

1) add {{&& !(base instanceof COSName)}} to the "if"
2) in {{writeCOSDictionary}} write the key with the "topLevel" parameter true 
(but I'm not sure about what the intention of the parameter is, but in practice 
when true no indirect writing occurs)


was (Author: tilman):
I think I understand most of it now. "Sì" is an indirect object in the source 
file:
!screenshot-3.png!

In {{COSWriterObjectStream.writeObject()}} there is this:
{code:java}
if (!topLevel && this.compressionPool.contains(base))
{
    COSObjectKey key = this.compressionPool.getKey(base);
    if (key == null)
    {
        throw new IOException(
                "Error: Adding unknown object reference to object stream:" + 
object);
    }
    writeObjectReference(output, key);
    return;
}
{code}
Because the key is also an object, the method will be called and will produce 
an indirect object.

Two possible solutions:

1) add {{&& !(base instanceof COSName)}} to the "if"
2) in {{writeCOSDictionary}} write the key with the "topLevel" parameter true 
(but I'm not sure about what the intention of the parameter is)

> Saved file has "Invalid dictionary" when reloading
> --------------------------------------------------
>
>                 Key: PDFBOX-5927
>                 URL: https://issues.apache.org/jira/browse/PDFBOX-5927
>             Project: PDFBox
>          Issue Type: Bug
>          Components: Writing
>    Affects Versions: 3.0.3 PDFBox, 4.0.0
>            Reporter: Tilman Hausherr
>            Priority: Major
>         Attachments: ObjStm.txt, SO79293670-saved.pdf, SO79293670.pdf, 
> screenshot-1.png, screenshot-2.png, screenshot-3.png
>
>
> {code:java}
> try (PDDocument doc = Loader.loadPDF(new File("SO79293670.pdf")))
> {
>     doc.save(new File("SO79293670-saved.pdf")); //, 
> CompressParameters.NO_COMPRESSION);
> }
> try (PDDocument doc = Loader.loadPDF(new File("SO79293670-saved.pdf")))
> {
>     PDAcroForm acroForm = doc.getDocumentCatalog().getAcroForm();
>     PDCheckBox cb = (PDCheckBox) acroForm.getField("chkPrivacy1");
>     System.out.println(cb.isChecked()); // should be true
> }
> {code}
> The output:
> {noformat}
> 19.12.2024 16:48:15 WARN  pdfparser.BaseParser.parseCOSDictionary:308 - 
> Invalid dictionary, found: '3' but expected: '/' at offset 12814
> 19.12.2024 16:48:15 WARN  pdfparser.BaseParser.parseCOSDictionary:308 - 
> Invalid dictionary, found: '3' but expected: '/' at offset 12851
> false
> {noformat}
> The offsets are in the object stream.
> When opening the modified file with Adobe Reader, I get
> !screenshot-1.png! 
> And after clicking CTRL-RETURN I get
> !screenshot-2.png!
> The problem does not happen when saving with compression disabled.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@pdfbox.apache.org
For additional commands, e-mail: dev-h...@pdfbox.apache.org

Reply via email to