我正在尝试从UIView创建一个PDF并且效果很好,就像“How to Convert UIView to PDF within iOS?”那样。
但我的iPad是风景,是一种形式,冗长的形式,高度为3k。
当我转换为PDF时,它只转换iPad的高度大小,即748而不是我需要的3k。
有什么问题? iOS版本?
编辑:继承人像@wain问的代码
-(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 drawRect:aView.bounds];
// 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);
}
答案 0 :(得分:0)
我从这里找到解决方案“UIGraphicsGetCurrentContext and UIScrollView”并适应我的代码,现在抓住所有表格并打印出漂亮的PDF。 如果有人需要我的代码,请告诉我,我发布代码。