【问题标题】:set pdf file name using abcpdf使用 abcpdf 设置 pdf 文件名
【发布时间】:2012-07-11 19:02:23
【问题描述】:

我发现了这个: How to set the name of the file when streaming a Pdf in a browser?

我在 Coldfusion 中使用 abcpdf。所以问题是:

我在 Coldfusion 中使用 abcpdf 来生成 Pdf 并将输出流式传输给用户。我的代码如下所示:

<cfscript>
theDoc = createObject("com","ABCpdf6.doc");
theDoc.rect.SetRect(10, 10, 600, 777); 

theID = theDoc.AddImageHTML(strHTML, true);

while(theDoc.Chainable(theID))
{
theDoc.Page = theDoc.AddPage();
theID = theDoc.AddImageToChain(theID);
}

page_count = theDoc.PageCount;
the_data = theDoc.getData();

enter code here



// Release the Objects
theDoc.clear();
ReleaseComObject(theDoc);

</cfscript>

此代码运行后,它将 Pdf 流式传输到打开 Acrobat Reader 的浏览器。效果很好!

我的问题是当用户尝试保存文件时,它默认为实际文件名......在这种情况下,它默认为 myPagename.pdf。无论如何我可以设置这个吗?如果有,怎么做?

任何帮助将不胜感激。

【问题讨论】:

  • 你能发布“将 pdf 流式传输到浏览器”的代码吗?

标签: coldfusion coldfusion-9 abcpdf


【解决方案1】:

你可以在 ABC 之外这样做:

var ms = new MemoryStream();
theDoc.Save(ms);
String fileName = name + ".pdf"; // where "name" is the default name
return File(ms, "application/pdf", fileName);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-02-14
    • 1970-01-01
    • 1970-01-01
    • 2011-05-14
    • 1970-01-01
    • 2012-04-23
    • 2022-12-23
    相关资源
    最近更新 更多