I had a feeling of hacking/flow state today after a long time. When loading a PDF file, I got a cryptic error in Briss JAR (it’s a PDF cropping tool). Other PDFs had no issue. The error was:
WARNING: Illegal reflective access by com.itextpdf.text.pdf.MappedRandomAccessFile$1 (file:/home/puneet/Downloads/briss-0.9/itextpdf-5.2.0.jar) to method java.nio.DirectByteBuffer.cleaner()
WARNING: Please consider reporting this to the maintainers of com.itextpdf.text.pdf.MappedRandomAccessFile$1
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
com.itextpdf.text.exceptions.InvalidPdfException: Unknown encryption type R = 6
at com.itextpdf.text.pdf.PdfReader.readPdf(PdfReader.java:515)
at com.itextpdf.text.pdf.PdfReader.<init>(PdfReader.java:169)
at com.itextpdf.text.pdf.PdfReader.<init>(PdfReader.java:158)
I don't know reflection in Java, and a Google search did not give a solution. But I know that reflection happens at runtime. So, I updated the Java version from 11 to 21, thinking that maybe that would solve the error. But the error remained.
So, I tried to get a newer version for Briss JAR. I did not find it, but somebody had made a new GUI for it, and I used that. Now I got the same error, but it changed the error output to:
com.itextpdf.text.exceptions.InvalidPdfException: Unknown encryption type R = 6.
While writing this article, I noticed that this line was also there in the first error. However, I was so confused and frustrated when it happened that I did not even read the whole error message. I just searched for the complete error message and trimmed it until I could get a response in the search engine. So when I searched for this error, I got an article by itextpdf itself that it is related to a newer standard of PDF, namely PDF 2.0, and it is caused by AES256 encryption. And itextpdf version 7 and above has the fix. So I searched for the newer itextpdf JAR (which was also one of the files in the Briss directory where the Briss JAR is), but now it’s closed source, and the last open source version is v5.something. So I tried to use the last open-source version and found that I have to rename it to the version I am replacing because it is referenced by name somehow. Renaming it worked to start Briss, but the error was still there. So, I read a bit more in other articles about the error and found out how to decrypt the PDF, but I could not find a non-programmatic solution. Then I ran the file
shell command on this PDF, which was giving the error, and another PDF which was loading without any problem.
<aside>
<img src="/icons/command-line_gray.svg" alt="/icons/command-line_gray.svg" width="40px" /> Problem PDF: PDF document, version 1.7 (zip deflate encoded)
Non-problem PDF: PDF document, version 1.6, 442 pages
</aside>
Then I did more searching and found on some desktop app's forum that someone was exporting a PDF from that app. They had the same problem with the exported PDF. To solve it, they unlocked the PDF with a web app. I think itextpdf thinks that this PDF is password protected. Maybe, not sure. I Googled for such web apps, found one, and used it. Then, I ran the file
command again. This time, the output was:
<aside>
<img src="/icons/command-line_gray.svg" alt="/icons/command-line_gray.svg" width="40px" /> PDF document, version 1.7
</aside>
I could load the PDF successfully, and it felt really good. I felt like a hacker or my imagination of what a hacker is. This state is also known as flow. It was a fruitful real-life debugging session, and you feel really good when that happens.
I did this quite a bit while working to start my programming institute in 2011-12. Because, essentially, an entrepreneur is a problem solver. I remember a similar incident that happened in 2011. I was preparing courses for my soon-to-be-opened programming institute and really needed a C++ book (it was supposed to be the C++ course book). It was not available in India, and I could not find it online for free. Amazon.com had a digital version, but it was too costly for me then. Then, I found a website that was giving a free sample of that book for around a week. It was in PDF format. And it had a Windows desktop app. I found a 3rd party tool for the same app that scrolled the whole book, took screenshots, and gave a PDF as output. It worked, but the PDF was not clear enough, as it was just a series of low-resolution images. It was legible but quite inferior in quality to a normal PDF. It was image -> PDF, after all. Then, I thought I would find the download folder for the app. And try to retrieve the actual PDF file from there. I Googled the path and found that it is in Program Files
somewhere and found the file. But it was not opening in a normal PDF reader because of something called DRM, which I did not know then. So, I searched for a solution and found a tool to de-DRM it, which worked. And when I double-clicked the file, it opened, and it was beautiful. Crystal clear PDF.
That moment and the whole process of reaching there are etched in my memory. I learned that if you keep trying and applying yourself, even if you don't know everything or, worse, anything about the solution to the problem in front of you, but if you just keep at it, there is a possibility that you might get what you are looking for. Another thing I learned was that the Internet and the Web are great enablers. Now, you don't have to be in the US to get the books or devices you want. You might have to pay extra, but you will get it. I got the projector for my institute from the US as it was cheaper than the cheapest one I was getting here. And sometimes you don't have to pay at all. Technology is very close to magic, and I feel fortunate to have some knowledge about it to navigate this digital world. It gives me a little bit of a headstart over somebody who does not have that knowledge. But again, as I said, if you keep at it, you will know what is required to take you there.
May 19, 2024
Bangalore
<aside> 🔔 To discuss anything or say hi, you can email at [email protected]. You can get updates via *WhatsApp* or email*.*
</aside>