matto3 - 2014-01-05

Hi,

I am trying to open an existing PDF file and add attachments to it, which users can view using the "Paperclip" icon in Acrobat Reader.

I can get the files to embed in the document, but they do not show up on the paperclip.

When I compare the file generated by Clown and one where I attach using a different method, I see the following difference

Clown Generated:

31 0 obj
<</Type /Filespec /F (MYFILENAME.jpg) /EF <</F 30 0 R >> >>
endobj
32 0 obj
<</Names [(MYFILENAME.jpg) 31 0 R ] /Limits [(MYFILENAME.jpg) (MYFILENAME.jpg) ] >>
endobj

Working File:

31 0 obj
<</Type /Filespec /F (MYFILENAME.jpg) /EF <</F 30 0 R >> >>
endobj
32 0 obj
<</Names [(MYFILENAME.jpg) 31 0 R ] >>
endobj

You can see that there is nothing past "/Limits" in the working file. Likewise, if I edit the file manually and change it to "<</Names>[(MYFILENAME.jpg) 31 0 R ] /Limits [] >>" it works fine as well.

Here is the relevant code I am using to attach the file:

// memoryStream is a .NET MemoryStream containing the contents of the PDF file
using (var pdfStream = new org.pdfclown.bytes.Stream(memoryStream))
{
    File pdf = new File(pdfStream);

        // attachmentFileInfo as a FileInfo object pointing to the MYFILENAME.jpg file
    using (var attachmentSystemStream = attachmentFileInfo.OpenRead())
    {
        using (var pdfAttachmentStream = new org.pdfclown.bytes.Stream(attachmentSystemStream))
        {
            // create the attachment
            EmbeddedFile attachment = EmbeddedFile.Get(pdf.Document, pdfAttachmentStream);
            pdf.Document.Names.EmbeddedFiles.Add(
                new PdfString("MYFILENAME.jpg"),
                FileSpecification.Get(attachment, "MYFILENAME.jpg"));
        }
    }
}

Any suggestions about something I can do differently to get attachments to show up in Acrobat?

Thanks!