Friday, April 22, 2016

CGPDFDocument unable to read pdf

Leave a Comment

I followed the following example to view a pdf in my App (Xamarin.iOS). Everything worked fine until recently I started to notice some pdf files can't be read using this method.

I open and got info on my mac and I noticed the following:

  • if I export the document to pdf using the Mac viewer it can be read just fine, but the size is increase.
  • If I try to open the file as is, nothing is viewable, but a white page.
  • This happens for my iOS app only, the viewer on my Android works just fine.

I can export every file to pdf using the Mac's viewer, but it is an extra step than what I need. What can I do to fix this?

Original encoding: PDFScanLib v1.2.2 in Adobe Acrobat 10.1.16

Export encoding: Mac OS X 10.10.5 Quartz PDFContext


I ran additional tests to the program and I can conclude the issue is with the compression being used on the pdf files. Is there any way CGPDFDocument can remove or ignore the compression so I can view the pdf? I upload the pdf to my mobile backend where I split the pages. I am using Pdfsharp to accomplish this if possible is there a way to clean out the files before being save to the server? (This issue is only affecting the iOS version of my app).


After extra testing I have come accross the following bug: Here It will appear the JBIG2 compression used has a known bug that causes errors when reading a jpg in a pdf. ( I will continue further testing until I can find a solution.)


Corrections: The pdf compression is not JBIG2, but FlateDecode. After testing and reading the binary data I have notice that both the original and the export have the same type of compression. (Will update with more information as I try to figure this out.)

1 Answers

Answers 1

Apple's CoreGraphics rendering library has many limitations - it's unlikely that you can expect a fix for it in a reasonable time frame, as Apple has allocated very few resources in advancing their PDF engine.

We know this because we work in this space since 2011 and offer a commercial PDF viewing and editing library named PSPDFKit. We replaced Apple's renderer in version 5 of our iOS SDK and now ship a custom render engine - the same that we also use to drive our Android SDK.

There are not many competitors in the market who also use a custom render engine - you can look for muPDF as a potential alternative which might also solve your problem (also commercial). Most other products are just shims on top of CGPDF which would not solve your problem. Feel free to evaluate some products and let me know if you have any further questions. (Reach me at peter at pspdfkit.com)

We also offer complete wrappers for Xamarin for both platforms to make integration easy.

If You Enjoyed This, Take 5 Seconds To Share It

0 comments:

Post a Comment