Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Cfdocument will not print PDF (Need Help)

Contributor ,
Aug 30, 2012 Aug 30, 2012

Hello,

Why would this not work. It throws an error "Acrobat could not open xxxxx because it is either not a supported file type or because the file has been damaged"

The records are served on the fly from an xslt generated content. It does not matter really because when I comment out the xsltfile content and enter just a text, it still throws the error.

The code below is in my pdf.cfm file and is an include just to generate the content based on what the report type is

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<cfdocument format="PDF" bookmark="yes" name="pdfreporttype" saveasname="reporttype.pdf">

   Hello Help print document in pdf.. <!--- #xsltfile# --->

</cfdocument>

<cfheader name="Content-Disposition" value="Attachment; filename=reporttype.pdf">

<cfcontent type="application/pdf" reset="true">

1.9K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Aug 30, 2012 Aug 30, 2012

I could be wrong, it's been a long time since I tried anything like this, but remove the reset="true" from the cfcontent.  I vaguely remember something about that, but again it's been a while.

^_^

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Aug 30, 2012 Aug 30, 2012

The cfcontent tag with reset in your code is clearing out the output buffer so none of the content above the cfcontent tag is sent to the browser.  Try something like this:

<!--- create a PDF file and store in memory, use the name attribute of cfdocument --->

<cfdocument format="pdf" name="report">

    This is the text of the report

</cfdocument>

<!---

write to browser using the cfcontent tag, you can add a cfheader to specify an attachment name and dispostion if desired

Note use of variable attribute to specify the content to be output.

The reset attribute will cause any text prior to the PDF content to be removed from the output.  This is generally desirable with working with non-HTML content such as PDF files.

--->

<cfcontent type="application/pdf" reset="yes" variable="#report#">

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Aug 30, 2012 Aug 30, 2012

When using the cfdocument tag you don't even need to specify the cfheader or cfcontent tags.  It does the work for you. 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Aug 30, 2012 Aug 30, 2012

The problem is still there.

Since the pdf is not meant to open inline in the browser, rather should open as an attachment for saving, hence the <cfheader name="Content-Disposition" value="Attachment; filename=reporttype.pdf">

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Aug 30, 2012 Aug 30, 2012
LATEST

So are you still getting the error from your initial post or are you passed that now?  Sounds like you are getting the PDF document now, but inline in the browser.

For what it's worth, I believe the final say on how the document is handled (inline or save dialog) is up to the browser.  Try using different browsers and see what happens.  Acrobat reader also has a setting on whether to always display in the browser or to always display within Acrobat.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources