위젯 및 링크와 같은 특수 효과가있는 코드로 PDF를 생성하려고합니다. PDF를 생성하고 문서 정보와 페이지의 MediaBox를 수정할 수는 있지만 어노테이션에 추가하는 방법을 알 수는 없습니다. 나는 그것을 페이지 사전에 추가하려고하지만 어떤 이유로 PDF가 그것을 받아들이지 않고있다.Annot을 사용하여 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
CFRelease(myDictionary);
CFRelease(url);
CGRect mediaBox;
mediaBox = CGRectMake (0, 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,
&kCFTypeDictionaryKeyCallBacks,
& kCFTypeDictionaryValueCallBacks);
CFMutableDictionaryRef pageDictionaryMutable = CFDictionaryCreateMutableCopy(NULL, 0, pageDictionary);
CFMutableDictionaryRef metaDataDictionary = CFDictionaryCreateMutable(NULL, 0, &kCFTypeDictionaryKeyCallBacks,&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,0, &kCFTypeArrayCallBacks);
CFArrayInsertValueAtIndex(array, 0, 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>;
}
미디어 박스는 필요하지만 Annots하지 않습니다. 누구든지 도와주세요!
답변을 얻었습니까? 페이지의 "annot"사전에 주석을 추가 할 수 있었습니까? –