약 320 * 2000에 가까운 컨텐츠 크기를 가진 UIScrollView의 pdf를 생성하고 싶습니다. 현재 그래픽 이미지 컨텍스트를 사용하여 스크롤 뷰 레이어를 캡처하면 스크롤 뷰의 전체 레이어가 아닌 스크롤 뷰의 가시적 인 부분 만 캡쳐합니다. 샘플 코드는, 내가 같은 정확하게 일을하려고하시기 바랍니다 볼PDF 생성 UIScrollView + iphone
-(void)CreatePdf:(id)sender
{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *saveDirectory = [paths objectAtIndex:0];
NSString *saveFileName = @"myPDF.pdf";
[self writePDFAma];
CGRect arect=CGRectMake(0, 0, 768, 1024);
CreatePDFFileAma(arect, nil);
}
-(void) writePDFAma
{
UIImage *image;
NSData *data;
UIAlertView *successAlert;
UIAlertView *failureAlert;
//
NSArray *documentPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
// // This should be our documents directory
NSString *saveDiirectory = [documentPath objectAtIndex:0];
// // Our PDF is named 'Example.pdf'
NSString *saveFileName = @"FormImage2.JPG";
// // Create the full path using our saveDirectory and saveFileName
NSString *finalPath = [saveDiirectory stringByAppendingPathComponent:saveFileName];
//NSLog(@"%@",finalPath);
CGSize asize=CGSizeMake(_scrollview.frame.size.width, _scrollview.frame.size.height);
//NSLog(@"%d..%d",mainViewAma.frame.size.width, mainViewAma.frame.size.height);
UIGraphicsBeginImageContext(asize);
[[_scrollview layer] renderInContext:UIGraphicsGetCurrentContext()];
image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
data = UIImageJPEGRepresentation(image, 1.0);
BOOL catch;
if(!catch){
if ([[NSFileManager defaultManager] createFileAtPath:finalPath contents:data attributes:nil])
{
successAlert = [[UIAlertView alloc] initWithTitle:@"Success" message:@"Doodle was successfully saved to the Photo Library." delegate:self cancelButtonTitle:@"Close" otherButtonTitles:nil];
//[successAlert show];
[successAlert release];
} else {
failureAlert = [[UIAlertView alloc] initWithTitle:@"Failure" message:@"Failed to save doodle to the Photo Library." delegate:self cancelButtonTitle:@"Close" otherButtonTitles:nil];
//[failureAlert show];
[failureAlert release];
}
}
}
void CreatePDFFileAma (CGRect pageRect, const char *filename)
{
// This code block sets up our PDF Context so that we can draw to it
//some code here
CGContextRef pdfContext;
CFURLRef url;
CFMutableDictionaryRef myDictionary = NULL;
NSArray *documentPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
// // This should be our documents directory
NSString *saveDirectory = [documentPath objectAtIndex:0];
// // Our PDF is named 'Example.pdf'
//NSString *saveFileName = @"PDFForm2.pdf";
// // Create the full path using our saveDirectory and saveFileName
NSString *finalPath = [saveDirectory stringByAppendingPathComponent:saveFileName];
NSURL * aurl=[[NSURL alloc]initFileURLWithPath:finalPath];
url=(CFURLRef)aurl;
// This dictionary contains extra options mostly for 'signing' the PDF
myDictionary = CFDictionaryCreateMutable(NULL, 0,
&kCFTypeDictionaryKeyCallBacks,
&kCFTypeDictionaryValueCallBacks);
CFDictionarySetValue(myDictionary, kCGPDFContextTitle, CFSTR("AMA FORM PDF"));
CFDictionarySetValue(myDictionary, kCGPDFContextCreator, CFSTR("My Name2"));
// Create our PDF Context with the CFURL, the CGRect we provide, and the above defined dictionary
pdfContext = CGPDFContextCreateWithURL (url, &pageRect, myDictionary);
// Cleanup our mess
CFRelease(myDictionary);
CFRelease(url);
// Starts our first page
CGContextBeginPage (pdfContext, &pageRect);
// Draws a black rectangle around the page inset by 50 on all sides
CGContextStrokeRect(pdfContext, CGRectMake(50, 50, 768, 1024));
// This code block will create an image that we then draw to the page
CGImageRef image;
CGDataProviderRef provider;
CFURLRef pictureURL;
documentPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
// // This should be our documents directory
saveDirectory = [documentPath objectAtIndex:0];
NSString *saveFileName2 = @"FormImage2.JPG";
// // Create the full path using our saveDirectory and saveFileName
NSString *finalPath2 = [saveDirectory stringByAppendingPathComponent:saveFileName2];
NSURL * aurl2=[[NSURL alloc]initFileURLWithPath:finalPath2];
pictureURL=(CFURLRef)aurl2;
provider = CGDataProviderCreateWithURL (pictureURL);
CFRelease (pictureURL);
image = CGImageCreateWithJPEGDataProvider(provider, NULL, TRUE, kCGRenderingIntentDefault); //DataProvider (, NULL, true, kCGRenderingIntentDefault);
CGDataProviderRelease (provider);
CGContextDrawImage (pdfContext, CGRectMake(0, 0,768, 1024),image);
CGImageRelease (image);
CGContextEndPage (pdfContext);
// We are done with our context now, so we release it
CGContextRelease (pdfContext);
}
안녕 마르코 난 당신의 논리를 implimenting에 의해 시도했지만 나를 위해 작동 나던 : 더 많은 페이지에 대한
나는 기본적으로이 사용합니다. – ravoorinandan