Reputation: 6362
So, I have a program which is kind of a text editor. I need it's output format to be pdf, yet again I need to be able to edit that PDF again. Since my programs output is never very complicated, and since my program is the one who creates the PDF, I could read directly from created PDF, but I thought it would be easier to just attach another file to PDF which will be easier to read.
However, I don't want the user to see that a file is attached to the PDF.
I have read once somewhere that you can trick PDF readers by changing /EmbeddedFiles
to /Embeddedfiles
. That way they will not detect there are files attached to PDF they are processing.
The question is, how can I read the PDF in order to do that change and then again prior to editing to revert it back?
I don't think PDF libraries would help me here, since I'm trying to "corrupt" the PDF. I guess I should parse it as somekind of string and then look for the substring I want to change. But I'm too unfamiliar with the PDF format to know if it's really that simple or is there a specific way to do that...
Upvotes: 1
Views: 1779
Reputation: 10418
If you just one to create your own version of a binary format and just call it PDF, then you can try adding a "custom" entry to any dictonary object of your PDF file, and associate a data stream to that entry. Since the entry will be outside the PDF spec, all (well implemented) readers should be able to ignore it.
You can probably do this with iText using PdfDictionary.put, and you could add your non-stanard data to the Catalog dictionary for example.
Upvotes: 1
Reputation: 1577
PDF isn't a format meant for editing and tacking on an attachment (hidden or not which I'm not even sure will work) is kind of iffy. Assuming your trick works:
Is this a valid PDF? You may want to trick readers, but you'd be creating invalid PDFs, which worries me more than the method you're trying to use.
What if a PDF reader updates its functionality to support invalid syntax? That would mean all of a sudden your file is visible, defeating your intentions.
The best way would be:
Let the user create its document. Store the text in a program folder. Create a PDF. When editing, just load the text document (or whatever) based on the PDF's title. Once again, PDF is not an editing format.
Or use Jonathan's solution. Which works around storing the text locally.
Either way, corrupting a PDF file is not desirable.
Upvotes: 2