2011-04-25 2 views
6

데스크톱에서 PDF 리더를 사용하여 PDF를 여는 동안 주석을 볼 수 있도록 텍스트 주석이있는 PDF를 어떻게 만들 수 있습니까?주석을 사용하여 PDF를 만들려면 어떻게해야합니까?

현재 PDF를 만들 수 있지만 키 "Annot"에 대한 페이지 수준 사전을 설정할 수 없습니다. 이것은 페이지에 대한 메타 정보를 작성하기 위해 수행 한 샘플 코드입니다. 누군가가 내가 잘못한 곳이나 내가 따라야하는 다른 접근법을 말해 줄 수 있는가? 사전에

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

감사

답변

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