使用 TideSDK 保存一个 pdf 文件

Save a pdf file with TideSDK

本文关键字:一个 pdf 文件 TideSDK 保存 使用      更新时间:2023-09-26

>我有一个解码问题。

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

为了生成PDF文件,我使用BytescoutPDF库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的路径和名称)。