Programmatically generate PDF from HTML on iPhone

I am looking for a way to programmatically (in obj-c) generate a PDF file from a local html file. I dynamically generate html from user inputs, I need to create a PDF file and send it to the user (via email). I'm having difficulty with the PDF creation part.

I have code to create a PDF using CGPDFContextCreateWithURL, but I'm struggling with drawing a page using quartz.

I searched a lot on SO, as well as on the Internet, but to no avail.

Any help is much appreciated!

+3
source share
6 answers

, NSAttributedString DTCoreText PDF . GitHub. html, . , CoreText, PDF .

, : HTML, DTCoreText NSAttributedString, PDF . , PDF " ".

+1

WebService, HTML- PDF ?

, iTextSharp #, 2 .
( ) .

0

, , , iPhone - . .

, , , , , . , -, , . . , - - . , - HTML .

0

, , , HTML UIWebView, PDF? .

UIWebView *webview = [[UIWebView alloc] initWithFrame:CGRectMake(...)];
[webview loadHTMLString:html baseURL:...];

:

- (void)webViewDidFinishLoad:(UIWebView *)webview {
    CGPDFContextRef pdfContext = CGPDFContextCreateWithURL(...);
    [webview.layer drawInContext:pdfContext];
    ...
}
0

, SO: fooobar.com/questions/373322/...

To maintain the same proportions of content, I had to multiply the size of WKWebView by 1.25 times the printableRect size for UIPrinterRenderer, since the screen points are different from PostScript ... I think.

0
source

Source: https://habr.com/ru/post/1769640/


All Articles