Siehe diesen Code.
NSString *text = @"this is textField's text";
NSMutableData *pdfData = [[NSMutableData alloc] init];
UIGraphicsBeginPDFContextToData(pdfData, CGRectMake(0, 0, 320, 480), nil);
UIGraphicsBeginPDFPage();
[text drawInRect:UIGraphicsGetPDFContextBounds() withAttributes:@{NSFontAttributeName:[UIFont boldSystemFontOfSize:17]}];
UIGraphicsEndPDFContext();
NSString *file = @"file.pdf"; //this is the file name.
NSArray<NSURL *> *dir = [[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask];
if (dir.count > 0){
NSURL *path = [[dir firstObject] URLByAppendingPathComponent:file];
[pdfData writeToFile:path.path atomically:false];
}
Sie können alle gewünschten Formatierungsoptionen im withAttributes-Wörterbuch in der Zeichenmethode angeben.
Und wenn Sie mehrere Seiten in einem PDF wollen gerade auf diesen Code in einer Schleife
UIGraphicsBeginPDFPage();
[text drawInRect:UIGraphicsGetPDFContextBounds() withAttributes:@{NSFontAttributeName:[UIFont boldSystemFontOfSize:17]}];
UIGraphicsEndPDFContext();
und den Text ändern, die zieht. Sie können auch Bilder zeichnen, wenn Sie sie in Ihrem PDF möchten. Überprüfen Sie das erstellte PDF
Hoffe, das hilft.
http://stackoverflow.com/questions/21562085/create-pdf-from-uiscrollview-objective-c? – Larme
@larme Danke für die Antwort der Link, den Sie gesendet haben, ist nicht klar, also bitte geben Sie mir eine andere klare Lösung –