Webpage to PDF


Is there a way to covert webpage to pdf with the original size that is shown while you are scrolling this page in browser on mobile?

What I have done for now: converting webpage to PDF, but with printing format only.
Print option is not enough for me as the size of the page changes as for printing.

But what I would like to achieve is generating a PDF from a webpage in the same way how we can create a screenshot of the page and then create it as PDF. (so the original size and content is not changed and looks exactly how it looks on iPhone)

Does anyone have any ideas?:)

You might look at UIGraphicsPDFRenderer, it takes an explicit size of the area you want to create into a PDF, rendering from the current view, and I've used it to make snapshots of pages. I haven't gone to directly linking that with a view from WebKit, but that's the first place I'd likely explore.

EDIT/UPDATE: Glancing more into WebKit's views, there's some lovely direct calls there that are worth looking into, likely easier than rendering yourself: WKWebView.createpdf (configuration:completionHandler:)

1 Like