如何将字符串值存储为PDF文件?

时间:2012-01-07 06:13:29

标签: objective-c pdf ios5

我从那以后一直在做同样的工作,但没有结果我需要你的帮助。以下是问题,

我将用户健康详细信息存储在sqlite3数据库中并以字符串形式检索(我在一个字符串中追加了8个值),然后我尝试保存下面的appended string as PDF file in document directory是我的代码

NSArray *pdf = [NSArray arraywithobject:pdf_val];
//pdf_val is the appended string with 8 values in it.
NSArray *documentPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *saveDirectory = [documentPath objectAtIndex:0];
NSString *saveFileName = @"mypdf.pdf";
NSString *finalPath = [saveDirectory stringByAppendingPathComponent:saveFileName];
[pdfwriteToFile:finalpath atomically:YES];

处理完上述代码后,我尝试在UIWebView中加载PDF文件,但我得到error: failed to load pdf: '%PDF' not found,有时显示空webView

1 个答案:

答案 0 :(得分:1)

您没有将PDF写入mypdf.pdf。您正在编写一个二进制属性列表,其中包含一个数组,其中包含pdf_val变量中的任何内容。

pdf_val中的内容是什么?如果这是PDF,那么您需要直接将其写入mypdf.pdf,而不将其包含在NSArray中。也许pdf_val是包含PDF的NSData,在这种情况下,您可以向其发送writeToFile:atomically:消息。如果它不是包含PDF的NSData,那么它是什么?

如果pdf_val是包含八个连接值的字符串,那么您需要了解如何创建PDF。 Drawing and Printing Guide for iOS中解释了创建PDF。