Как я могу использовать библиотеку PoDoFo для аннотирования PDF-файлов на iOS?
Я хотел бы аннотировать PDF-файлы в приложении для iOS. Я наткнулся на библиотеку PoDoFo, но я не уверен, как использовать это в приложении для iOS.
Можно ли использовать эту библиотеку для аннотирования PDF-файлов на iOS? Если так, то как?
2 ответа
Пожалуйста, сделайте что-нибудь подобное.
+ (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);
Ответ выше предоставляет только способ добавить аннотации (типа FreeText и т. Д.). Как правило, вы хотите создать / изменить поля. Я обычно использую PdfTextFields, PdfCheckboxes, PdfSignature Field для этой цели. надеюсь, это поможет
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();