0
votes

I am hit with a Microsoft Edge bug that has been around for a long time, and doesn't seem to get any attention: Microsoft Edge doesn’t open some PDF files if they have data for screen readers

I have an application that generates a PDF, which is then printed. To support Microsoft Edge and workaround the bug, I am thinking to open and strip out any data that gives Edge trouble using PDFBox. However, the issue is slim on details, and I can't find any info on what specifically triggers the problem for Edge. Does anyone have experience with this and can suggest what specifically I should be stripping out to make a PDF open in Edge?

[Edit]: Just to add, currently if I download the PDF and open the PDF in Edge, it still wouldn't open even though if I open the same local PDF in Chrome, IE11 or Firefox, it works fine.

1
Please upload a sample PDF and ping me.Tilman Hausherr
Thank you so much, @TilmanHausherr -- here's a link to the file: dl.dropboxusercontent.com/u/76888092/myfile.pdfAdrian Pang

1 Answers

0
votes

The file has some weirdness, if you open it with NOTEPAD++ it will show that there is some data ater %%EOF. Anyway, try this code, which removes some unneeded stuff.

PDDocument doc = PDDocument.load(new File("myfile.pdf"));
PDDocumentCatalog cat = doc.getDocumentCatalog();
cat.getCOSObject().removeItem(COSName.PAGE_MODE);
cat.getCOSObject().removeItem(COSName.VIEWER_PREFERENCES);
PDPageTree pageTree = cat.getPages();
pageTree.getCOSObject().removeItem(COSName.PARENT);
doc.save("myfile2.pdf");

It is possible that the three "removeItem" calls are not needed, or only some of them, I can't test it myself.

If it still doesn't work, please ping me again and I'll try another idea (setting the mediabox at the page level).