gpt4 book ai didi

objective-c - 我们如何创建带注释的 PDF

转载 作者:太空狗 更新时间:2023-10-30 03:46:00 25 4
gpt4 key购买 nike

谁能告诉我如何创建带有文本注释的 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);

提前致谢

最佳答案

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);

关于objective-c - 我们如何创建带注释的 PDF,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5777924/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com