0

My question is similar to this one except that, rather than java or command line, I want to do it in iOS.

Given: I have a pdf file read-in from my bundle (or Documents dir or wherever.)

  • Does it contain images?
  • If so, what resolution are they?
  • If > myMaxResolution, how do I create a PDF-view with those images rendered at myMaxResolution?

For example: if the pdf is a bunch of pages scanned at 300dpi, and I want to display them at 72dpi, my goal being to get the 17x speedup.

Thanks!

Community
  • 1
  • 1
Olie
  • 24,597
  • 18
  • 99
  • 131

1 Answers1

0

I assume you want to define a target resolution to support documents that contain images too large to load into iOS device memory (as required to display the PDF page)?

Check out the Apple sample code project Large Image Downsizing. You can modify that sample to render a PDF page (instead of an image), yet benefit from the same incremental down sampling. You can define a target resolution, and the entire source document is never attempted to be loaded into memory all at once. Instead, the destination PDF rendering is 'assembled' in an incremental fashion, at the target resolution defined by you. You can do this regardless of what the source resolution actually is.

Incremental image decoding only works in iOS for TIFF, JPEG, PNG. However, BMP, GIF, interlaced images are not supported. In your context, that only means if your PDF contains images of the latter type, they will be decoded in-full into memory, so hopefully those are relatively small and the large images in your PDF are of the former format.

As mentioned in the sample ReadMe, the source PDF can exist in the app bundle, photo roll, or somewhere else (such as downloaded OTA).

In addition, I modified the sample to support PDF. You can download it here. In my tests, the destination PDF is rendered at the proper target resolution, including any text, glyph or vector elements as you'd expect.

Bobjt
  • 4,040
  • 1
  • 29
  • 29
  • I'll have a look at your example, thanks! The issue isn't "too large to load into iOS device memory" but, rather, "takes too long for CGPDFPageRender() (or whatever it's called) to operate. I'm trying to get the page to render in a reasonable amount of time (I have some that take several seconds per page.) – Olie May 03 '12 at 16:53
  • Ah, I see. The sample may not help in your case then, as it probably takes even longer to assemble the new document. Have you checked out CGImageSourceCreateThumbnailAtIndex? the reference states: "If the image source is a PDF, this function creates a 72 dpi image of the PDF page specified by the index that you pass." I don't know if it'll be faster than CGPDF functions since I believe those are backed by ImageIO (CGImageSource, etc.) under the covers, but it's worth a shot I suppose. – Bobjt May 03 '12 at 17:44