Laurent
December 13, 2021, 9:42am
1
Hello,
I have a cfm script that produces a PDF file to download.
the attribute saveAsName in a tag cfdocument has no effect on the downloaded file :
it’s always [the-script-name].pdf
It was working on ACF 11, not on Lucee.
What can i do ?
OS : Ubuntu Linux 18.04.5
Java Version : 11.0.7 (AdoptOpenJDK) 64bit
Tomcat Version : Apache Tomcat/9.0.35
Lucee Version : 5.3.8.189
Yes, I get the same result using the PDF extension version 1.0.0.97-RC.
Here’s a possible workaround:
<cfscript>
saveAsName = "mypdf.pdf";
document format="PDF" name="pdfBinary"{
WriteOutput( "Test" );
};
header name="Content-Disposition" value="attachment; filename=#Chr( 34 )##saveAsName##Chr( 34 )#";
content type="application/pdf" variable=pdfBinary reset="true";
</cfscript>
Or if you prefer tags:
<cfset saveAsName="mypdf.pdf">
<cfdocument format="PDF" name="pdfBinary">Test</cfdocument>
<cfheader name="Content-Disposition" value="attachment; filename=#Chr( 34 )##saveAsName##Chr( 34 )#">
<cfcontent type="application/pdf" variable=pdfBinary reset="true">
@Laurent Looking at the lucee pdf extension source code the attribute saveAsName is not implemented. Can you file a bug here https://luceeserver.atlassian.net/ ?
* set the value username When required by a proxy server, a valid username.
*
* @param proxyuser value to set
**/
public void setProxyuser(String proxyuser) {
this.attrProxyUser = proxyuser;
}
/**
* set the value password When required by a proxy server, a valid password.
*
* @param proxypassword value to set
**/
public void setProxypassword(String proxypassword) {
this.attrProxyPassword = proxypassword;
}
public void setSaveasname(String saveAsName) {
this.saveAsName = saveAsName;
}
Laurent
December 13, 2021, 11:27am
4
Fine workaround !
Thank’s a lot
Jamo
December 20, 2021, 5:14pm
6
I recommend using double quotes around the attachment file name or you’ll encounter issues when files have spaces.
<cfheader name="Content-Disposition" value="attachment; filename=""#Chr( 34 )##saveAsName##Chr( 34 )#""">
1 Like
The use of Chr( 34 )
means that shouldn’t be necessary.
Jamo
December 20, 2021, 7:31pm
8
Doh! You are right.
I didn’t perform the manual conversion in my head. (I’ve been using double quotes for so long as it appears more obvious.)
1 Like
Now the saveasname attribute implemented in cfdocument from PDF extension version 1.1.0.3-SNAPSHOT.
https://download.lucee.org/#66E312DD-D083-27C0-64189D16753FD6F0
1 Like