News for hackers. Stuff that matters.
Re:PDF to Text, a Challenging Problem by protocolture on Tuesday May 13, 2025 @11:47PM (#43980591)
Behold a Bitmap.

But for real, thats a pretty easy set of hurdles. Really the barrier is the psychological fallacy that PDF's are immutable.

Re:PDF to Text, a Challenging Problem by theamk on Wednesday May 14, 2025 @12:09AM (#43980708)
[delayed]
Re:PDF to Text, a Challenging Problem by protocolture on Wednesday May 14, 2025 @12:33AM (#43980842)
Word can edit pretty much any pdf these days, the issue is that it will often garble the attempt.
Re:PDF to Text, a Challenging Problem by imtringued on Wednesday May 14, 2025 @05:34AM (#43982603)
PDFs are not really immutable. I use Okular all the time to write my "notes" (it's just text that you can place anywhere) on top of a PDF form and then print out a new completely filled out PDF. The only thing I do by hand is sign the physical paper.
Re:PDF to Text, a Challenging Problem by iLemming on Wednesday May 14, 2025 @09:54PM (#43991100)
Your understanding of immutability feels skewed here. Every time you annotate the PDF, it creates a new version. Even when you overwrite the same file, the structure of the original document changes, therefore creating a new document, ultimately making it "the ship of Theseus.pdf"

Sure, someone may try using the same argument, applying it to .doc and .txt documents, yet there is a general consensus saying that pdfs were designed to "resist the change". You can probably self-illustrate the point by making changes to a .txt document and then removing your changes - the md5 of the file would remain the same.

Re:PDF to Text, a Challenging Problem by me-vs-cat on Thursday May 15, 2025 @08:57PM (#44000833)
Have you ever used Acrobat? Not "Acrobat Reader", but regular Acrobat, the most popular PDF editor. It's from Adobe, and it definitely does not "resist" edits.
Re:PDF to Text, a Challenging Problem by iLemming on Thursday May 15, 2025 @09:39PM (#44001063)
I got what you're saying the first time, and you still seem to be entirely missing the point. Immutability means that an object cannot be modified after it's created, and any changes result in a new object rather than altering the original.

You're saying "well, look, I can modify this pdf and I can even undo my changes...", what I'm saying is that whenever you modify a PDF, you're essentially creating a new file rather than truly "undoing" changes in the original. PDFs have complex internal structures with metadata, object references, and possibly compression that make bit-perfect restoration challenging.

Unlike plain text files where changes can be precisely tracked and reversed at the character level, PDFs don't easily support this kind of granular reversibility. Even "undoing" in PDF editors often means generating yet another variant rather than returning to the exact binary state of the original.

Take a look at how Git stores PDFs - when the delta approach doesn't work efficiently since even small logical changes can result in significantly different binary files with completely different checksums, it stores EVERY version of the same document in a separate blob object.

When you annotate a pdf and then later change your mind, undo all the annotations and save it — only to your eyes it may look the same as the original — in digital reality, it will be a different file.

Re:PDF to Text, a Challenging Problem by protocolture on Thursday May 15, 2025 @09:58PM (#44001184)
The people who act as if PDFs are legally immutable are not performing MD5 comparisons.

Also, that isnt even an intention of the file format as far as I can see, its mostly a byproduct of cruft and backwards compatibility.

No one would call .doc immutable because its very difficult to move an image and then restore that image to the original location.

In this context, people will save something out as pdf and store it because they dont think it cannot be modified.

But as has been rightly pointed out, thats not the case.

Re:PDF to Text, a Challenging Problem by iLemming on Thursday May 15, 2025 @10:27PM (#44001307)
I feel like I'm talking to a toddler, sigh. Let me try again.

Immutability doesn't mean that an "object cannot be modified", it means that in order to modify an object, you must create a new (clone) object. That's all what I meant to say. Sure, you can get pedantic or otherwise and say "yes, pdfs are immutable; or no, pdfs aren't immutable in some contexts", etc., and depending on the point of view, both of these claims could be correct — I'm not arguing about the specifics.

I'm just saying that your explanation of why you think pdfs are not immutable hinges on an incorrect idea of what immutability actually is.

There's a rigorous definition for "immutability" in computer science, e.g., strings in many programming languages are immutable, but that doesn't mean you can't manipulate them, it just means that operations that appear to modify strings actually create new string objects.

The greatest illustration for immutability is imbued in programming languages with immutability-by-default, e.g., Clojure. Once someone groks the basics, it becomes really clear what that thing is about.

Re:PDF to Text, a Challenging Problem by me-vs-cat on Friday May 16, 2025 @05:58PM (#44010138)
> I feel like I'm talking to a toddler, sigh.

Me too, but I'm done. Have fun!

Re:PDF to Text, a Challenging Problem by me-vs-cat on Friday May 16, 2025 @06:07PM (#44010198)
> I got what you're saying the first time,

That wasn't me. Multiple people were taking the time to help you understand.

Re:PDF to Text, a Challenging Problem by harshreality on Wednesday May 14, 2025 @06:07AM (#43982758)
What's immutable, without tools to decompress and possibly perform further de-obfuscation of text streams, is the typical way publishing software encodes text into streams inside PDFs.

It remains possible to have a pdf with text that is easily mutable with any text editor.

Even if text inside a pdf is annoyingly encoded, you can always just replace the appropriate object/text streams... if you can identify the right one(s). You can extract and edit and re-insert, or simply replace, embedded images as well.

I don't think "this format promotes, as the norm, so much obfuscation of basic text objects that it becomes impractical to edit them in situ without wholesale replacement" is the win you think it is.

"Looks good on paper" has to do with the rendering engine (largely high-DPI and good font handling/spacing/kerning), not PDF as a content layout/presentation format. A high-quality software rasterizer (for postscript or PDF, often embedded in the printer)—not the PDF file format—has been the magic sauce.

Today, some large portion of end-user interaction with PDFs is via rendering into a web browser DOM via javascript. Text in PDFs is rendered as text in the browser. Perhaps nothing else demonstrates more clearly that the "PDF is superior" argument is invalid.

Re:PDF to Text, a Challenging Problem by me-vs-cat on Wednesday May 14, 2025 @12:00PM (#43986093)
> you can always just replace the appropriate object/text streams

Or right-click and select Edit. Works in several PDF editors, on both text and image content.

Re:PDF to Text, a Challenging Problem by me-vs-cat on Wednesday May 14, 2025 @11:54AM (#43986015)
PDFs are not immutable.