大佬教程收集整理的这篇文章主要介绍了ios – 如何使用Annots创建PDF?,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
有谁知道如何为新创建的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); // 5 CFRelease(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>; }@H_70_5@media Box需要,但Annots没有.请帮助任何人!
以上是大佬教程为你收集整理的ios – 如何使用Annots创建PDF?全部内容,希望文章能够帮你解决ios – 如何使用Annots创建PDF?所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。