5

我想在 iOS 应用程序中注释 PDF。我遇到了PoDoFo 库,但我不确定如何在 iOS 应用程序中使用它。

是否可以使用此库在 iOS 上注释 PDF?如果是这样,怎么做?

4

2 回答 2

4

请做这样的事情。

+ (void)createUTFAnnotationTextOnPage:(NSInteger)pageIndex 
                                  doc:(PdfDocument*)doc   // PdfMemDocument instance
                                 rect:(PdfRect)rect 
                                title:(NSString*)title 
                              content:(NSString*)content
                                bOpen:(Boolean)bOpen
                               colorR:(double)r 
                               colorG:(double)g 
                               colorB:(double)b {
    PdfPage* pPage = doc->GetPage(pageIndex);
    if (! pPage) {
        // couldn't get that page
        return;
    }
    PdfAnnotation* anno;

    anno = pPage->CreateAnnotation(ePdfAnnotation_Text, rect);

    PdfString sTitle(reinterpret_cast<const pdf_utf8*>([title UTF8String]));
    PdfString sContent(reinterpret_cast<const pdf_utf8*>([content UTF8String]));

    anno->SetTitle(sTitle);
    anno->SetContents(sContent);
    anno->SetColor(r, g, b);
    anno->SetOpen(bOpen);
}

// ----------- 
    PdfError::EnableDebug(false);   // or true
    NSString* inFile = [[NSBundle mainBundle] pathForResource:@"forTesting.pdf" ofType:nil];
    PoDoFo::PdfMemDocument doc( [inFile UTF8String] );
    [YourPodofoObj createUTFAnnotationTextOnPage:0 doc:&doc rect:PdfRect(50, 50, 50, 50) title:@"author by XX" content:@"I use it for test" bOpen:true colorR:1.0 colorG:.0 colorB:.0];
    doc.Write(OUT_PUT_PATH);
于 2011-12-29T04:18:59.907 回答
2

上面的答案只为您提供了添加注释(类型为 FreeText 等)的方法。通常您会想要创建/修改字段。为此,我通常使用 PdfTextFields、PdfCheckboxes、PdfSignature 字段。希望有帮助

    PdfMemDocument memDoc;
    PdfFileInputStream fileInputStream(filePath);
    char *srcBuffer = new char[fileInputStream.GetFileLength()];
    size_t srcLen = fileInputStream.GetFileLength();
    fileInputStream.Read(srcBuffer,srcLen);


    PdfOutputDevice outputDevice(filePath);
    outputDevice.Write(srcBuffer,srcLen);
    memDoc.Load(srcBuffer,srcLen);

    PdfTextField txtField  = PdfTextField( pPage,PdfRect(50, 50, 50, 50),&memDoc);
    txtField.SetFieldName(@"SomeUniqueName");

    memDoc.Write(&outputDevice);
    outputDevice.Flush();
于 2013-12-17T22:38:05.893 回答