有谁知道如何为新创建的pdf添加注释?下面是我要生成pdf的代码和我试图添加到它的测试Annotation字典:
-(voID) createpdffile: (CGpdfpageRef) pageRef{CGContextRef pdfcontext;CFStringRef path;CFURLRef url;cfmutabledictionaryRef myDictionary = NulL; NSArray *paths = NSSearchPathForDirectorIEsInDomains(NSdocumentDirectory,NSUserDomainMask,YES); Nsstring *documentsDirectory = [paths objectAtIndex:0]; // Get documents folder const char *filepath = [[documentsDirectory stringByAppendingString:@"/fileTest.pdf"] UTF8String];path = CFStringCreateWithCString (NulL,filepath,kcfStringEnCodingUTF8);url = CFURLCreateWithfileSystemPath (NulL,path,kcfURLPOSIXPathStyle,0);CFRelease (path);myDictionary = CFDictionaryCreateMutable(NulL,&kcfTypeDictionaryKeyCallBacks,&kcfTypeDictionaryValueCallBacks); CFDictionarySetValue(myDictionary,kCGPdfcontextTitle,CFSTR("My pdf file"));CFDictionarySetValue(myDictionary,kCGPdfcontextCreator,CFSTR("My name"));CGRect pageRect = self.bounds;pdfcontext = CGPdfcontextCreateWithURL (url,&pageRect,myDictionary); // 5CFRelease(myDictionary);CFRelease(url);CGRect mediaBox;mediaBox = CGRectMake (0,pageRect.size.wIDth,100);CFStringRef myKeys[1];CFTypeRef myValues[1];myKeys[0] = CFSTR("MediaBox");myValues[0] = (CFTypeRef) CFDataCreate(NulL,(const UInt8 *)&mediaBox,sizeof (CGRect));CFDictionaryRef pageDictionary = CFDictionaryCreate(NulL,(const voID **) myKeys,(const voID **) myValues,1,& kcfTypeDictionaryValueCallBacks);cfmutabledictionaryRef pageDictionaryMutable = CFDictionaryCreateMutablecopy(NulL,pageDictionary);cfmutabledictionaryRef MetaDataDictionary = CFDictionaryCreateMutable(NulL,&kcfTypeDictionaryValueCallBacks); CFDictionarySetValue(MetaDataDictionary,CFSTR("DA"),CFSTR("/Helvetica 10 Tf 0 g"));CFDictionarySetValue(MetaDataDictionary,CFSTR("F"),CFSTR("4"));CFDictionarySetValue(MetaDataDictionary,CFSTR("FT"),CFSTR("Tx"));CFDictionarySetValue(MetaDataDictionary,CFSTR("Subtype"),CFSTR("Widget"));CFDictionarySetValue(MetaDataDictionary,CFSTR("T"),CFSTR("undefined"));CFDictionarySetValue(MetaDataDictionary,CFSTR("Type"),CFSTR("Annot"));CFDictionarySetValue(MetaDataDictionary,CFSTR("V"),CFSTR(""));CFMutableArrayRef array = CFArrayCreateMutable(kcfAllocatorDefault,&kcfTypeArrayCallBacks);CFArrayInsertValueAtIndex(array,MetaDataDictionary);CFDictionarySetValue(pageDictionaryMutable,CFSTR("Annots"),array);CGPdfcontextBeginPage (pdfcontext,pageDictionaryMutable);CGPdfcontextEndPage (pdfcontext);CGContextRelease (pdfcontext);CFRelease(pageDictionary);}
打印出cfmutabledictionary pageDictionaryMutable表示应该将Annots字典添加到pdf以及MediaBox:
(gdb) po pageDictionaryMutable{ Annots = ( { DA = "/Helvetica 10 Tf 0 g"; F = 4; FT = Tx; Subtype = Widget; T = undefined; Type = Annot; V = ""; } ); MediaBox = <00000000 00000000 00008044 0000c842>;}
Media Box需要,但Annots没有.请帮助任何人!
解决方法 看看PodoFo library: http://podofo.sourceforge.netPodoFo根据GPL和LGPL获得部分许可.
有了它,您可以修改pdf文件并为其添加注释.它可以移植到iOS.查看文档,它是否可以处理您想要的内容并查看其工作原理.
如果您有兴趣,也可以查看this sample project on GitHub.我将库集成到iOS项目中,您可以使用iPad添加FreeText和Square Annotations.
总结以上是内存溢出为你收集整理的ios – 如何使用Annots创建PDF?全部内容,希望文章能够帮你解决ios – 如何使用Annots创建PDF?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)