使用 TideSDK 保存 pdf 文件

Save a pdf file with TideSDK

我有解码问题。

我有一个离线桌面应用程序,我必须在其中生成一个 pdf 文件并在他打开时保存。

要生成 PDF 文件,我使用 BytescoutPDF library createpdf.js.

这个 returns 我必须保存的文档变量。 我试过:

//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,在我的例子中,使用 [=15] 设置生成的 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 的路径和名称)。