ios - PDF from UIScrollView is blank -


i have uiscrollview want export pdf file. scroll view contains view (content view) contains visible content:

scrollview : uiscrollview -> contentview : uiview    -> view1 : uiview       ...    -> view2 : uiview       ...    ... 

the code pdf export is:

func generatepdfdata() -> nsdata {     // first tried use scroll view result same     let bounds = contentview.bounds      let pdfdata = nsmutabledata()     uigraphicsbeginpdfcontexttodata(pdfdata, bounds, nil)      let pdfcontext = uigraphicsgetcurrentcontext()     cgcontextsetinterpolationquality(pdfcontext, kcginterpolationmedium)     cgcontextsetrenderingintent(pdfcontext, kcgrenderingintentdefault)     cgpdfcontextbeginpage(pdfcontext, nil)      // without following 2 settings, result remains same     cgcontextscalectm(pdfcontext,1.0,-1.0)     cgcontexttranslatectm(pdfcontext,0.0,-bounds.size.height)      contentview.layer.renderincontext(pdfcontext)      uigraphicsendpdfcontext()     return pdfdata } 

i use data generate pdf file. resulting file has size of 120 kb, expect contain stuff (the view not comprise images). however, when try open it, blank page.

it looks problem beginning new pdf page in context. replace cgpdfcontextbeginpage(pdfcontext, nil) uigraphicsbeginpdfpage() , should work.


Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -