Я создаю pdf от UIView до pdf, он отлично работает, но у меня есть scrollView
с контентом, который я хочу преобразовать в pdf, но он отображает только видимую часть в pdf, а не весь контент scrollView
. Вот мой кодСоздание PDF из UIScrollView в приложении iphone
-(void)createPDFfromUIView:(UIView*)aView saveToDocumentsWithFileName:(NSString*)aFilename
{
NSMutableData *pdfData = [NSMutableData data];
// Get Scrollview size
CGRect scrollSize = CGRectMake(1018,76,scrollView.contentSize.width,scrollView.contentSize.height);
// Points the pdf converter to the mutable data object and to the UIView to be converted
UIGraphicsBeginPDFContextToData(pdfData, scrollSize, nil);
UIGraphicsBeginPDFPage();
CGContextRef pdfContext = UIGraphicsGetCurrentContext();
// draws rect to the view and thus this is captured by UIGraphicsBeginPDFContextToData
[aView.layer renderInContext:pdfContext];
// 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);
}
Посетите этот ответ, это поможет вам. http://stackoverflow.com/a/6566696/1223897 – Yuvrajsinh
@Yuvrajsinh это тот же самый код, который я использую, но это для равнины не UIScrollView –
Я думаю, что проблема, вы создаете новый UIView с статический размер. Используйте свойScrollView.contentSize для получения точного размера содержимого (ширина, высота) в вашем scrollview и без необходимости создания нового представления. – Yuvrajsinh