• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Playing with iOS UIPrintInteractionController to generate PDF output
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Playing with iOS UIPrintInteractionController to generate PDF output


  • Subject: Playing with iOS UIPrintInteractionController to generate PDF output
  • From: Fernando Caprio <email@hidden>
  • Date: Wed, 15 Dec 2010 14:04:46 -0200

Hi All,

I've been playing with iOS 4.2 print functions for a while. Wondering
if I could use it to solve a limitation I have in my app.

One of the features I need in my iPhone app is to get PDF output from
an UIWebView. Until 4.2 was released, my approach was to render the
PDF manually by rendering the UIWebView viewable layer with
_renderInContext_. I had to do pagination with javascript
(stringByEvaluatingJavaScriptFromString) and the main issue is that
since I'm rendering images to PDF the size gets
a little bit bloated, and I could end up cutting images / text in the
middle from one page to the other.

By reading the documentation from the new classes introduced in 4.2 I
saw a light in the end of this tunnel. The UIWebView now returns a
_viewPrintFormatter_. This UIPrintFormatter can be used with
UIPrintPageRenderer to generate output in the CurrentContext. I've
been trying to do this for a while, but I still can't figure out if
it's possible. If I get the shared instance from
UIPrintInteractionController and set the print context, it allows me
to print with AirPrint - but I could not figure out a way to get the
output that this print controller generates with my print formatter.
I've tried to get the PrintFormatter myself, and set it in a
UIPrintPageRender. The problem, however, is that calling
_prepareForDrawingPages_ and _drawPageAtIndex_ still return nil for
UIGraphicsGetCurrentContext(). I can't figure out a way to use those
components to get the rendered content from memory.

Does anybody know if there is a way for me to get PDF / Bitmap output
from the webView printformatter using apple code?

My last attempt:

UIPrintInteractionController *pic = [UIPrintInteractionController
sharedPrintController];
pic.delegate = self;

UIPrintInfo *printInfo = [UIPrintInfo printInfo];
printInfo.outputType = UIPrintInfoOutputGeneral;
printInfo.jobName = @"myFile.pdf";
pic.printInfo = printInfo;
pic.printFormatter = [webView viewPrintFormatter];

* in this case [pic printingItem] is nil, printingItems is a 0 object
array. Although it prints just fine with AirPrint if I call [pic
presentAnimated...].

I've also tried to create a renderer myself:

	UIPrintPageRenderer *render = pic.printPageRenderer;
	//[render setPrintFormatters:[NSArray arrayWithObject:[webView
viewPrintFormatter]]];
	[render prepareForDrawingPages:NSMakeRange(0, upperLimit)];
	[render drawPageAtIndex:0 inRect:CGRectMake(x, y, width, height)];
        CGContextRef *image = UIGraphicsGetCurrentContext();

But "image" comes nil.

Thanks a lot,

Fernando
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Prev by Date: NSToolbarItem Craziness
  • Next by Date: Build and Archive fails due to missing dSYM file
  • Previous by thread: Re: NSToolbarItem Craziness
  • Next by thread: Build and Archive fails due to missing dSYM file
  • Index(es):
    • Date
    • Thread