11

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.)

poupou
  • 43,413
  • 6
  • 77
  • 174
ScarletMerlin
  • 465
  • 4
  • 24
  • This sounds like an iOS bug (or limitation) and unrelated to Xamarin. I edited the tags so more people will see it (and you should get a better change to have answers). – poupou Apr 14 '16 at 15:43
  • I assumed it was a limitation of porting the code to Xamarin, but you might be right. I am using 5 different ways to read the pdf (pdfsharp to split, chrome to view, safari to view and heck even the normal mail in in iPhone is working for the original). I don't know what the actual bug is related to. – ScarletMerlin Apr 14 '16 at 16:05

1 Answers1

8

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.

steipete
  • 7,581
  • 5
  • 47
  • 81
  • I would like to avoid commercial licenses if possible. Did you guys ever figured out the exact nature of this error? At worse I guess I could create completely new pdf files; It seems I would have to run extensive test to find the perfect formatting to make it 100% compatible with iOS Core Graphics. – ScarletMerlin Apr 16 '16 at 19:17