ios - Printing PDF from UIWebView yields unscaled pages -
i loading pdf file nsdata webview such:
[webview loaddata:pdf mimetype:@"application/pdf" textencodingname:@"utf-8" baseurl:nil];
it displays beautifully in uiwebview, , correctly shows number of pages of pdf.
however when try print, entire page , left on page filled maybe last tenth or of single pdf page. in other words, don't have 1 one page correspondence. doesn't seem scale content down.
how scale printing output? print using snippet:
uiprintinteractioncontroller *pic = [uiprintinteractioncontroller sharedprintcontroller]; uiprintinfo *printinfo = [uiprintinfo printinfo]; printinfo.outputtype = uiprintinfooutputgeneral; printinfo.jobname = printname; printinfo.duplex = uiprintinfoduplexnone; pic.printinfo = printinfo; pic.printformatter = [webview viewprintformatter]; pic.showspagerange = yes;
this so question describes method involves scaling input, hoping simpler exists.
regards, dane
so had problem too. using uiwebview access website link opened pdf document in window. when pdf printing, document getting cropped @ bottom , sent next page. annoying because 2 page pdf document printing 3 page pdf document nothing on third page. fix simple did 2 things. have not tested if both of these things necessary fix problem post both anything.
in method in viewcontroller.m:
- (void) webviewdidstartload:(uiwebview *)webview { webview.scalespagetofit = yes; }
and in printing method (i have method print since have multiple scenes webviews , print buttons.
-(void) printwebview:(uiwebview *)webview { uiprintinfo *pi = [uiprintinfo printinfo]; pi.outputtype = uiprintinfooutputgeneral; pi.jobname = webview.request.url.absolutestring; pi.orientation = uiprintinfoorientationportrait; uiprintinteractioncontroller *pic = [uiprintinteractioncontroller sharedprintcontroller]; pic.printinfo = pi; pic.showspagerange= no; uiprintpagerenderer *renderer = [[uiprintpagerenderer alloc] init]; webview.viewprintformatter.printpagerenderer.headerheight = 30.0f; webview.viewprintformatter.printpagerenderer.footerheight = 30.0f; webview.viewprintformatter.contentinsets = uiedgeinsetsmake(0.0f, 30.0f, 0.0f, 30.0f); webview.viewprintformatter.startpage = 0; [renderer addprintformatter:webview.viewprintformatter startingatpageatindex:0]; pic.printpagerenderer = renderer; [pic presentanimated:yes completionhandler:^(uiprintinteractioncontroller *pic2, bool completed, nserror *error) { // indicate done or error }]; }
now don't know if necessary application lines added helped me scaling problem are
webview.scalespagetofit = yes;
and pic.showspagerange= no;
this may seem bit odd i've read,
pic.showspagerange= no;
is key here. if set yes, xcode airprint scale paged screwy , margins messed mine did pdf loaded inside webview. read on stackoverflow, , credit author of post answer having difficulty locating post. seems bit of trade off, print dialog no longer show page range document being printed, short documents, think worth tradeoff simplicity of implementing scaled document print vs lengthy workaround.
anyways, hope works you, , if find better let know.
ps know code formatting/rendering messed up, trying figure out how manipulate printing options in xcode , have not deleted unnecessary lines yet.
Comments
Post a Comment