如何在ios6中创建多页PDF?

问题描述:

以编程方式创建pdf的示例代码有用于生成包含多个页面的PDF的代码,但我无法理解我必须放置或实现该代码的位置。

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 .

第一个答案:生成我的PDF已经在我的项目中完成了。

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

第二回答:对于多页,我很困惑。谁能告诉我在哪里放这个代码来生成一个包含多个页面的PDF?

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?

用于创建多个页面

在.m文件的顶部定义 NSInteger currentPage = 0;

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

和generatePdfWithFilePath方法写

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