Skip to main content
Participating Frequently
July 19, 2009
Question

Rendering a PDF/Mime Type in cfDIV

  • July 19, 2009
  • 1 reply
  • 1010 views

Hi there

I have a cfform that looks at files in a directory. The template is meant to allow users to select a document and and view it on the page.

The relevant code is:

Main Page:

<cfform name = "name">

...

<cfinput name="displayName"  id="displayName" value="#URLEncodedFormat(displayName)#" type="text">

...

  <cfdiv bind="url:/_admin/utilities/viewer/viewer.cfm?displayName={displayName}" />

</cfform>

--------------------------

viewer.cfm

...

<cfset mimeType = getPageContext().getServletContext().getMimeType(displayName)>

<cfheader name="Content-Disposition" value="inline; filename=#displayName#">

<cfcontent type="#mimeType#" file="#displayName#">

---------------------------

Problem is, the text in the cfDiv appears literally as:

"

%PDF-1.4 %äüöß 2 0 obj <> stream x��� 5 }���� ����� ����wVI (���*�T٫��J�&#127;!��W�����u]� � N���J>  �w1������Lek� ���d�\W����dR%3- ��d{@�ȅ��4��G\8!�'��.�� o����� �9ܴ �� ��  �����X�������V����ִ�i>��*Y| �͋�"���=o�� .<��7 ��D�ϸ� uӊ��p�-� m�c ����o�i��j���7$TG�M E P�  P���QB���A 1�` ��; cS! : c2ċ9�c���.(6�Ċ� ΰ���i7

"

Is anyone able to make any suggestions?  For instance, can this event be done using AJAX tags?

Thanks in advance

Boon

This topic has been closed for replies.

1 reply

Inspiring
July 20, 2009

A cfdiv is not a separate browser window. So I do not think you can change the content type mid-stream that way.  You might try embedding the pdf with <object>. I think that would work.  (Of course that is assuming the user's browser is actually configured to display pdf's within the browser .. )