我遇到解码问题。
我有一个离线桌面应用程序,我必须在其中生成一个 pdf 文件并在打开时保存。
为了生成 PDF 文件,我使用 BytescoutPDF library createpdf.js。
这会返回一个我必须保存的文档变量。 我尝试过:
//this calls the createPDF to BytescoutPDF library
//and returns the variable into 'doc'
var doc = generaStaticPartBolla_2();
//take the stream
var bolla = Ti.Filesystem.getFileStream(billPath);
//open in write mode
bolla.open(Ti.Filesystem.MODE_WRITE);
//write the doc file decodified in Base 64
bolla.write(doc.getBase64Text());
//close the stream
bolla.close();
现在,生成的文件已损坏。 我无法打开这个。我怎样才能做到这一点?文件必须转换为 Base 64 或其他格式?
最佳答案
我不知道你现在是否已经解决了你的问题,但我有同样的要求:离线应用程序,从 HTML 生成 pdf,在我的例子中,用 CSS 设计生成的 pdf 的样式。 在尝试了多种解决方案后,主要问题是使用 CSS 进行样式设置。 最后我使用了 WkhtmlToPdf (http://wkhtmltopdf.org/)。基本上,我将二进制文件(适用于 mac os 和 Windows)嵌入到应用程序中,并且对于平台,我使用 Ti.Process 方法执行它们。 WkhtmlToPdf会在指定路径下生成一个pdf,这样,你就可以打开这个pdf了。 (为了设置pdf的路径,我使用openSaveAsDialog(http://tidesdk.multipart.net/docs/user-dev/generated/#!/api/Ti.UI.UserWindow-method-openFileChooserDialog),它允许用户设置生成的pdf的路径和名称)。
关于javascript - 使用 TideSDK 保存 pdf 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28043242/