2

In "Sample code to create pdf programmatically" there is code for generating a PDF with multiple pages, but I can't understand where I have to put or implement that code .

First answer: generate PDF that I've already done in my project.

Second Answer: for multiple page in that I am confuse. Can anyone tell me where I put this code to generate a PDF with multiple pages?

Community
  • 1
  • 1
Chetu
  • 428
  • 1
  • 7
  • 19

1 Answers1

2

For creating multiple pages

Define NSInteger currentPage = 0; at the top in .m file

and in generatePdfWithFilePath method write

-(void) generatePdfWithFilePath: (NSString *)thefilePath
{
    NSLog(@"\n==========\n \t the file path==  %@",thefilePath);

    UIGraphicsBeginPDFContextToFile(thefilePath, CGRectZero, nil);

    do
    {        
           currentPage++;

           if(currentPage == 1) 
              pageSize= CGSizeMake(612,2350);
           else
              pageSize = CGSizeMake(612, 2000);

           [self drawBorder];

           //Draw text fo our header.
           [self drawHeader];

           //Draw a line below the header.
           [self drawLine];

           //Draw some text for the page.
           [self drawText];

           //Draw an image
           [self drawImage];

    }while (currentPage !=2); //You can write required page number here

    currentPage=0;

    UIGraphicsEndPDFContext();
}
Shah Paneri
  • 729
  • 7
  • 28