在Objective-C中使用PDF

时间:2013-07-03 01:13:32

标签: ios objective-c pdf

我目前正在构建一个将操纵PDF文档的iOS应用程序。您将能够输入有关您自己的信息,该应用程序将使用正确的信息填充文档上的某些文本字段,并创建一个您可以保存,共享等的PDF。

我对iOS编程很新。我可以使用该信息填充股票PDF的文本字段吗?

1 个答案:

答案 0 :(得分:1)

this code help you the genrate the pdf 


- (void) drawLine
{
    CGContextRef    currentContext = UIGraphicsGetCurrentContext();
    CGContextSetLineWidth(currentContext, kLineWidth);
    CGContextSetStrokeColorWithColor(currentContext, [UIColor blueColor].CGColor);
    CGPoint startPoint = CGPointMake(kMarginInset + kBorderInset, kMarginInset + kBorderInset + 40.0);
    CGPoint endPoint = CGPointMake(pageSize.width - 2*kMarginInset -2*kBorderInset, kMarginInset + kBorderInset + 40.0);
    CGContextBeginPath(currentContext);
    CGContextMoveToPoint(currentContext, startPoint.x, startPoint.y);
    CGContextAddLineToPoint(currentContext, endPoint.x, endPoint.y);
    CGContextClosePath(currentContext);
    CGContextDrawPath(currentContext, kCGPathFillStroke);

- (void) generatePdfWithFilePath: (NSString *)thefilePath
{
    UIGraphicsBeginPDFContextToFile(thefilePath, CGRectZero, nil);
    NSInteger currentPage = 0;
    BOOL done = NO;
    for (int i=0; i<8; i++) {
        //Start a new page.
        UIGraphicsBeginPDFPageWithInfo(CGRectMake(0, 0, pageSize.width, pageSize.height), nil);

        //Draw a page number at the bottom of each page.
        currentPage++;
        [self drawPageNumber:currentPage];
        //Draw a border for each page.
        // [self drawBorder];
        //Draw text fo our header.
        [self drawHeader:i];
        //Draw a line below the header.
        [self drawLine];
        //Draw some text for the page.
        //   [self drawText:thefilePath2 :i];
        //Draw an image
      //  [self drawImage:rd:i ];
        done = YES;
    }
    // Close the PDF context and write the contents out.
    UIGraphicsEndPDFContext();

- (IBAction)generatePdfButtonPressed:(id)sender
{
    pageSize = CGSizeMake(612, 792);
    NSString *fileName = @"Demo.pdf";
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSString *pdfFileName = [documentsDirectory stringByAppendingPathComponent:fileName];



        [self generatePdfWithFilePath:pdfFileName];
  }}}