How to downsample images in a pdf (iOS)?

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.



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.

Need Your Help

find inactive gameobject by tag in unity3d

c# unity3d

I have a gameobject which I wish to activate given a certain condition. I gave it a unique tag and I tried using GameObject.FindObjectWithTag("Tag name"). From what I can tell, this method will onl...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.