Uammage를 PDF 파일로 저장하려고합니다. 어떻게해야합니까? 어떻게 내가 PDF 파일에 이미지를 저장하고 그 PDF 파일을 내보낼까요? 내가 직면 한 문제에 대한 해결책을 제안하십시오.UIImage를 PDF 파일로 변환
감사합니다.
Uammage를 PDF 파일로 저장하려고합니다. 어떻게해야합니까? 어떻게 내가 PDF 파일에 이미지를 저장하고 그 PDF 파일을 내보낼까요? 내가 직면 한 문제에 대한 해결책을 제안하십시오.UIImage를 PDF 파일로 변환
감사합니다.
제 생각에는 CGPDFContext을 만들고 UIImage를 그 파일에 저장하는 것이 좋습니다. 그래도 나 자신을하지 않았어.
안녕하세요.이 기능이 작동한다는 것을 발견했습니다. 도움이되기를 바랍니다.
-(void)createPDFfromUIView:(UIView*)aView saveToDocumentsWithFileName:(NSString*)aFilename
{
// Creates a mutable data object for updating with binary data, like a byte array
NSMutableData *pdfData = [NSMutableData data];
// Points the pdf converter to the mutable data object and to the UIView to be converted
UIGraphicsBeginPDFContextToData(pdfData, aView.bounds, nil);
UIGraphicsBeginPDFPage();
// draws rect to the view and thus this is captured by UIGraphicsBeginPDFContextToData
[aView.layer renderInContext:UIGraphicsGetCurrentContext()];
// remove PDF rendering context
UIGraphicsEndPDFContext();
// Retrieves the document directories from the iOS device
NSArray* documentDirectories = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask,YES);
NSString* documentDirectory = [documentDirectories objectAtIndex:0];
NSString* documentDirectoryFilename = [documentDirectory stringByAppendingPathComponent:aFilename];
// instructs the mutable data object to write its context to a file on disk
[pdfData writeToFile:documentDirectoryFilename atomically:YES];
NSLog(@"documentDirectoryFileName: %@",documentDirectoryFilename);
}
좋은 개념 인 것처럼 보이지만 공백의 PDF 파일을 그립니다. "aView"drawRect에 필요한 것은 무엇입니까? – WrightsCS
완벽하게 작동 중입니다. q보다 많이 sooooooooo 많은 가로수 길 amduser440071 –
나는 비어있는 pdf 파일도 갖고있다. 그래도 지금 일하고 있어요. 변경 시도 :
//[aView drawRect:aView.bounds]; // <- This
[aView.layer renderInContext:UIGraphicsGetCurrentContext()]; // <- To This
당신은 사용에 이미지를 그릴 다음 PDF 그래픽 컨텍스트를 시작하고 있습니다
:
[UIImage drawInRect: someRect];
당신은 어느 문서를 참조하십시오 그들이 생성의 좋은 설명을 제공 할 수 있습니다 pdf. pdf 생성 here에 좋은 자습서가있다.
왜? 가능하다면 PDF는 문서 및 벡터 그래픽을 저장하기에 최적화되어 있으며 UIImage는 비트 맵입니다 ... – kennytm