在我的应用程序中有一个带有 HTML 内容的 WebView。内容是 WebView 中的 3 页。现在我想将 WebView 内容转换为 PDF。我从 WebView 内容创建了 3 个图像。现在我想使用这 3 个图像创建 pdf。每个图像应该是一页 PDF。但它导致单页图像。因此,当我进行打印时,内容会被切断。我正在使用这个,
CGSize pageSize = CGSizeMake(612, 2324);
NSString *fileName = @"Demo.pdf";
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *pdfFileName = [documentsDirectory stringByAppendingPathComponent:fileName];
UIGraphicsBeginPDFContextToFile(pdfFileName, CGRectZero, nil);
// Mark the beginning of a new page.
UIGraphicsBeginPDFPageWithInfo(CGRectMake(0, 0, pageSize.width, pageSize.height), nil);
double currentHeight = 0.0;
for (int index = 1; index <= imageName ; index++)
{
NSString *pngPath = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"%d.png", index]];
UIImage *pngImage = [UIImage imageWithContentsOfFile:pngPath];
[pngImage drawInRect:CGRectMake(0, currentHeight, pageSize.width, pngImage.size.height)];
currentHeight += pngImage.size.height;
}
UIGraphicsEndPDFContext();
我对这段代码做错了什么。
谢谢