0

このクラスを使用して、UIWebViewからPDFファイルを生成しています

-(void)createPDFfromUI:(UIView *)aView saveToDocumentsWithFileName:(NSString*)aFilename
{
    // Creates a mutable data object for updating with binary data, like a byte array
    NSMutableData *pdfData = [NSMutableData data];

    // Points the pdf converter to the mutable data object and to the UIView to be converted
    UIGraphicsBeginPDFContextToData(pdfData, aView.bounds, nil);
    UIGraphicsBeginPDFPage();

    CGContextRef pdfContext = UIGraphicsGetCurrentContext();


    // draws rect to the view and thus this is captured by UIGraphicsBeginPDFContextToData

    [aView.layer renderInContext:pdfContext];

    // remove PDF rendering context
    UIGraphicsEndPDFContext();

    // Retrieves the document directories from the iOS device
    NSArray* documentDirectories = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask,YES);

    NSString* documentDirectory = [documentDirectories objectAtIndex:0];
    NSString* documentDirectoryFilename = [documentDirectory stringByAppendingPathComponent:aFilename];

    // instructs the mutable data object to write its context to a file on disk
    [pdfData writeToFile:documentDirectoryFilename atomically:YES];
}

私が抱えている唯一の問題は、PDFファイルを1つのページに生成するだけであり、それを複数のページに分割できるかどうか疑問に思っています。

4

1 に答える 1

1

ええ、PDFに複数ページを含めることができますが、そのためには、毎回手動でページの開始をマークする必要があります。

 UIGraphicsBeginPDFPage

アイデアは、生成したいページ数に応じて、LOOPのためにこの部分を実行することです。

この投稿を読んでください

于 2013-03-17T09:42:50.083 に答える