我想生成网页的打印预览并将其保存为PDF文件。
我试过stringByEvaluatingJavaScriptFromString:@"document.body.scrollHeight";
和
stringByEvaluatingJavaScriptFromString:@"document.body.scrollWidth";
用于查找高度和宽度的函数,但问题是java脚本程序在10秒后停止。
我想使用用于airPrint的默认打印选项,但我不想打印它。
我只想将打印预览保存为PDF格式。
请任何人帮助我..
发布于 2013-06-13 20:29:33
NSString *webServiceUrlString =@"https://www.google.com"; //Google.com is for example use your url
NSData *pdfData = [[NSData alloc]initWithContentsOfURL:[NSURL URLWithString:webServiceUrlString]];
NSString *resourceDocPath = [[NSString alloc] initWithString:[[[[NSBundle mainBundle] resourcePath] stringByDeletingLastPathComponent] stringByAppendingPathComponent:@"Documents"]];
NSFileManager *fm = [NSFileManager defaultManager];
NSError *error = nil;
for (NSString *file in [fm contentsOfDirectoryAtPath:resourceDocPath error:&error]) {
BOOL success = [fm removeItemAtPath:[NSString stringWithFormat:@"%@/%@", resourceDocPath, file] error:&error];
if (!success || error) {
}
}
NSString* fileName = @"Your File Name.pdf";
NSString *filePath = [resourceDocPath stringByAppendingPathComponent:fileName];
[pdfData writeToFile:filePath atomically:YES];
发布于 2013-06-03 19:34:52
您可以使用UIGraphicsBeginPDFContextToFile从网页内容创建一个PDF文件。
查看以下教程。MAKING A PDF FROM A UIWEBVIEW
https://stackoverflow.com/questions/16892003
复制相似问题