【问题标题】:How can we create A PDF with Annotation我们如何创建带有注释的 PDF
【发布时间】:2011-04-25 11:33:57
【问题描述】:

谁能告诉我如何创建带有文本注释的 PDF(以便在桌面上使用 PDF 阅读器打开 PDF 时可以看到注释)?

目前我可以创建 PDF,但我无法为键“Annots”设置页面级字典。这是我为创建有关页面的元信息所做的示例代码。谁能告诉我哪里出了问题以及我应该遵循的任何其他方法。

CFMutableDictionaryRef  metaDataDictionary = CFDictionaryCreateMutable(NULL, 0, &kCFTypeDictionaryKeyCallBacks,&kCFTypeDictionaryValueCallBacks); 


CFDictionarySetValue(metaDataDictionary, CFSTR("Subtype"), CFSTR("Text"));
CFDictionarySetValue(metaDataDictionary, CFSTR("Contents"), CFSTR("This is a sample"));
CFDictionarySetValue(metaDataDictionary, CFSTR("Subj"), CFSTR("Subject"));
CFDictionarySetValue(metaDataDictionary, CFSTR("M"), CFSTR("Date"));
CFDictionarySetValue(metaDataDictionary, CFSTR("NM"), CFSTR("Name of Annotation"));
CFMutableArrayRef array = CFArrayCreateMutable(kCFAllocatorDefault,0, &kCFTypeArrayCallBacks);
CFArrayInsertValueAtIndex(array, 0, metaDataDictionary);
CFDictionarySetValue(pageDictionary,CFSTR("Annots"), array);

提前致谢

【问题讨论】:

    标签: objective-c pdf-generation ipad quartz-graphics ios-4.2


    【解决方案1】:
    NSString *documentsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
    NSString *filename = @"test.pdf";
    NSURL *fileURL = [NSURL fileURLWithPathComponents:[NSArray arrayWithObjects:documentsDirectory, filename, nil]];
    
    // Create PDF context
    CGContextRef pdfContext = CGPDFContextCreateWithURL((CFURLRef)fileURL, NULL, NULL);
    CGPDFContextBeginPage(pdfContext, NULL);
    UIGraphicsPushContext(pdfContext);
    // Flip coordinate system
    CGRect bounds = CGContextGetClipBoundingBox(pdfContext);
    CGContextScaleCTM(pdfContext, 1.0, -1.0);
    CGContextTranslateCTM(pdfContext, 0.0, -bounds.size.height);
    
    // Drawing commands
    [@"HEADER" drawAtPoint:CGPointMake(130, 50) withFont:[UIFont boldSystemFontOfSize:15.0f]];
    [@"First line" drawAtPoint:CGPointMake(145, 80) withFont:[UIFont boldSystemFontOfSize:15.0f]];
    [img drawAtPoint:CGPointMake(10,100)];
    [@"Bye Bye" drawAtPoint:CGPointMake(10,500 ) withFont:[UIFont boldSystemFontOfSize:20.0f]];
    // Clean up
    UIGraphicsPopContext();
    CGPDFContextEndPage(pdfContext);
    CGPDFContextClose(pdfContext);
    

    【讨论】:

      猜你喜欢
      • 2011-08-13
      • 1970-01-01
      • 2012-06-08
      • 1970-01-01
      • 1970-01-01
      • 2014-03-08
      • 1970-01-01
      • 2021-06-27
      • 2011-07-10
      相关资源
      最近更新 更多