简体   繁体   中英

Library can be used to generate pdf offline ios(native)

I want to be generate pdf offline in ios. Does iText give library of that?I found that iText give libraries for andoid, java and C#. I used it for android and java (server side).

iOS, unlike Android, has a native way to create PDF documents - and it's actually quite clever. You can create a PDF context via CoreGraphics and then use that to draw into - just like you would draw into a regular image context. It will correctly write text as text, so you get the benefits of sharp text even at high zoom levels.

Here's how this looks in Objective-C:

NSString *pdfFileName = [self getPDFFileName];
UIGraphicsBeginPDFContextToFile(pdfFileName, CGRectZero, nil);

// draw into the context
UIFont *font = [UIFont systemFontOfSize:12];
[@"My PDF file title" drawInRect:CGRectMake(0,0,100,100) withFont:font];

UIGraphicsEndPDFContext();

You can learn more in Apple's Creating PDF Content documentation. Now fair warning, Apple's PDF engine is not quite on top of their list, and there are many aspects that you cannot control well, such as image compression, PDF version or metadata like page labels, a PDF outline, PDF annotations or even forms.

I've been working with my team for the past 5 years on an alternative, commercial SDK named PSPDFKit that is more flexible and allows all of the above both on iOS and Android and soon also for the browser. See PSPDFNewPageConfiguration for a start.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM