0

I'm using this class to generate PDF file from a UIWebView

-(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];
}

The only problem That I have is it just generate the PDF file in one single page and I just wonder if it is possible to separate it in multi pages.

Rudi
  • 4,304
  • 4
  • 34
  • 44

1 Answers1

1

Yeah you can have multipages in your PDF but for that you will have to mark the start of page each time manually using

 UIGraphicsBeginPDFPage

The idea is to do this part in for LOOP depending on the number of pages you want to generate.

Please Go Through this post

Community
  • 1
  • 1
Abhishek Singh
  • 6,068
  • 1
  • 23
  • 25