小编use*_*628的帖子

如何使用Annots创建PDF?

我正在尝试使用具有注释(如小部件和链接)的代码生成PDF。我可以生成PDF并修改文档信息和页面的MediaBox,但是我不知道如何添加到注释中。我尝试将其添加到页面字典中,但是由于某种原因,PDF不接受它。

有人知道如何将注释添加到新创建的PDF吗?以下是我要生成的PDF和要添加的测试注释词典的代码:

-(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, 0,

                                         &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 …
Run Code Online (Sandbox Code Playgroud)

pdf-generation annotations core-graphics ios podofo

5
推荐指数
1
解决办法
1813
查看次数

标签 统计

annotations ×1

core-graphics ×1

ios ×1

pdf-generation ×1

podofo ×1