pagebreak on coldfusion cfcontent word document - coldfusion

I am using cfcontent for creating a Word Document.
Example :
<cfsavecontent variable="sStr">
part1
part2
part3
</cfsavecontent>
<cfheader name="content-disposition" value="attachment; filename=wordDoc.doc">
<cfcontent type="application/msword" variable="#sStr#">
I want page break after each part.
The output should be in landscape format. How can I do this?

For a page break you should be using:
<cfdocumentitem type="pagebreak" />
And landscape you can set by:
<cfdocument orientation = "portrait|landscape>
As far as I know it's not possible to change the orientation of an individual page.

For cfcontent of a file you've saved to create an MS Word document:
<br clear=3Dall style=3D'page-break-before:always;mso-break-type:section-break'>

Got Page orientation to work with ms word by using the following style and making sure in cfcontent reset="no";
<html xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:w="urn:schemas-microsoft-com:office:word"
xmlns="http://www.w3.org/TR/REC-html40">
<head>
<title>Work Order Report</title>
<style>
#page Section1
{ size:11.0in 8.5in;
mso-page-orientation:landscape;
}
body.section1 {page:section1;}
</style>
<body class="section1">
<cfcontent type="application/msword" reset="no">

Related

Download CFM page as Word Doc

I'm trying to render the output of a .cfm into a Word doc using cfinclude like so:
<cfheader name="content-disposition" value="attachment; filename=""MyDocument.doc""" />
<cfcontent type="application/msword" reset="true">
<cfinclude template="PageToDownload.cfm">
Since cfinclude outputs the .cfm as html, this should theoretically work. However, doing this downloads a document that errors in Word with "A text/xml declaration may occur only at the very beginning of input." I inspected the downloaded document with Notepad++ and saw this at the top:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
...
If I remove the empty line, the ?xml, and the !DOCTYPE (basically cut off everything up to <html), this document opens in Word. Is it possible to strip off the xml and DOCTYPE tags and start at <html using cfinclude? Or, is there another approach I should take?
Using your technique, what you can do is put the contents of PageToDownload.cfm into a variable using <cfsavecontent>. Once the contents are in said variable, you could strip out everything prior to the opening <html> tag and then <cfoutput> that variable after your <cfheader> and <cfcontent> statements.
Your code could look something like this.
<!--- Save contents of file to download into fileContents variable --->
<cfsavecontent variable="fileContent">
<cfinclude template="PageToDownload.cfm">
</cfsavecontent>
<!--- Strip out contents prior to the opening <html> tag --->
<cfset pos = findNoCase("<html", fileContent)>
<cfset fileContent = mid(fileContent, pos, 1000000)>
<!--- Output fileContent after the header statements --->
<cfheader name="content-disposition" value="attachment; filename=""MyDocument.doc""" />
<cfcontent type="application/msword" reset="true">
<cfoutput>#fileContent#</cfoutput>

ColdFusion - CFDOCUMENT Title in URL

I am creating a PDF document using ColdFusion cfdocument tag. Works fine, however instead of showing the document name in browser Title - it shows the .cfc file that I call to create the PDF.
Here is how I'm calling it.
<cfdocument format="pdf" marginbottom=".5" margintop=".25" marginright=".5" marginleft=".5" saveAsName="#filename#.pdf">
<cfdocumentitem type="footer">
<p style="font-size:11px; text-align:right; font-style:italic;">Page #cfdocument.currentpagenumber# of #cfdocument.totalpagecount#</p>
</cfdocumentitem>
<html>
<head><title>#filename#.pdf</title></head>
<body><img src="file:///#application.tempFolder#\#thisFilename#" /></body>
</html>
</cfdocument>
What the heck am I missing? Why does it still show the filename.cfc file that I'm calling in the browser title instead of the filename I give to the PDF???
Figured it out. Had to create the document using CFDOCUMENT, then add a "Title" attribute to it using the CFPDF tag. Then output it to the browser.
<!--- Create the PDF --->
<cfdocument format="pdf" marginbottom=".5" margintop=".25" marginright=".5" marginleft=".5" filename="#application.tempFolder#\#thisSaveAsFilename#" overwrite="yes">
<cfdocumentitem type="footer">
<p style="font-size:11px; text-align:right; font-style:italic;">Page #cfdocument.currentpagenumber# of #cfdocument.totalpagecount#</p>
</cfdocumentitem>
<html>
<head><title>#thisSaveAsFilename#</title></head>
<body><img src="file:///#application.tempFolder#\#thisFilename#" /></body>
</html>
</cfdocument>
<!--- Use CFPDF to add attributes to it --->
<cfset thisInfo = StructNew()>
<cfset thisInfo.Title = "pdf title goes here...">
<cfpdf action="setinfo" info="#thisInfo#" source="#application.tempFolder#\#thisSaveAsFilename#" />
<!--- Send it to the browser --->
<cfcontent file="#application.tempFolder#\#thisSaveAsFilename#" type="application/pdf" />A

ColdFusion PDF "Open with" or "save file" prompt

How can I create a pop up that allows the user to "open with" or to save file as when dealing with coldfusion pdf's?
I am trying to figure out how to create it when this form is not actually mine and I am just using and prefilling a form that already exists.
<cfpdfform source="82040.pdf" action="populate">
<cfpdfformparam name="cust ##" value=""> <!---Section1 Customer Number--->
</cfpdfform>
I was able to create this pop up by doing something like this:
<cfsetting enablecfoutputonly="true">
<cfcontent type="application/pdf">
<cfheader name="Content-Disposition" value="attachment;filename=test.pdf">
<cfdocument format="PDF" localurl="yes"
marginTop=".25" marginLeft=".25" marginRight=".25" marginBottom=".25"
pageType="custom" pageWidth="8.5" pageHeight="10.2">
<cfoutput><?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>PDF Export Example</title>
</head>
<body>
</body>
</html>
</cfoutput>
</cfdocument>
But am not sure how I can combine these two. Any help is greatly appreciated!
Per Request What I have tried:
<cfset tempFilePath = "c:/path/to/someUniqueFileName.pdf">
<cfpdfform source="82040.pdf" action="populate" destination="#tempFilePath#">
<cfpdfformparam name="org" value="Yes"> <!---Above Section1 Original ---> <!---On--->
</cfpdfform>
<cfheader name="Content-Disposition" value="attachment;filename=Testme.pdf">
<cfcontent type="application/pdf" file="#tempFilePath#" deleteFile="false">
By default, cfpdfform renders the result in the browser ie "inline". To return it as an attachment instead, save the content to a file or a variable. Then use cfheader/cfcontent to return it as an attachment.
File:
Use the "destination" attribute to save it to a file. To avoid conflicts with other threads be sure use unique file names. To automatically remove the temporary file when finished, set deleteFile="true"
<cfset tempFilePath = "c:/path/to/someUniqueFileName.pdf">
<cfpdfform source="82040.pdf" action="populate" destination="#tempFilePath#">
...
<cfheader name="Content-Disposition" value="attachment;filename=test.pdf">
<cfcontent type="application/pdf" file="#tempFilePath#" deleteFile="false">
Variable:
Use the "name" attribute to save the content to a variable. Though "name" is not listed in the documentation, this bug report suggests it is just a documentation error.
<cfpdfform source="82040.pdf" action="populate" name="pdfContent">
... etcetera ...
<cfheader name="Content-Disposition" value="attachment;filename=test.pdf">
<cfcontent type="application/pdf" variable="#toBinary(pdfContent)#">

Why is CFHTMLHEAD not working in ColdFusion 11?

I've tested several pages so far, and it seems that wherever I am attempting to use <CFHTMLHEAD> to add CSS or JavaScript to a CFM page in ColdFusion 11, it will not add it (works fine in CF8).
I read on SO about increasing the "Maximum Output Buffer size" in the Administrator > Server Setttings > Settings from the default valut of 1024KB, but every value I've tried (2048KB, 4096KB, and even the max allowed 999999KB) I get the same result - the content is not included in the <HEAD> tag when the page loads.
Has anyone else run into this and found a solution yet?
Code Sample:
htmlhead.cfm:
<cfif NOT ThisTag.HasEndTag>
<cfthrow message="Missing end tag for custom tag htmlhead." type="HeadWrap" />
</cfif>
<cfif ThisTag.ExecutionMode is "End">
<cfhtmlhead text="#ThisTag.GeneratedContent#" />
<cfset ThisTag.GeneratedContent = "" />
</cfif>
index.cfm:
<cfsilent>
<!---
Data Retrieval, validation, etc. here
--->
<cf_htmlhead>
<style type="text/css">
tr.status-RETIRED td {
color: #800000;
}
tr.status-PENDING td {
color: #008000;
}
</style>
<script type="text/javascript">
$(function(){
$(".options-menu").mouseleave(function(e){
$(this).hide("fast");
})
$(".options-menu-link").mouseover(function(){
$(".options-menu").hide("fast");
$(".options-menu[data-sku='" + $(this).data("sku") + "']").show("fast");
}).click(function(e){
e.preventDefault();
});
});
</script>
</cf_htmlhead>
</cfsilent>
<!---
Custom Tag layout.cfm contains the DOCTYPE declaration, html, head (loads jquery, jquery-ui, css, etc.), and body tags with a header and footer for each page.
--->
<cf_layout>
<!--- Page Content Here (a form, a table, some divs, etc.) --->
</cf_layout>
I've found that in CF11 anything added using a cfhtmlhead call that comes before a cfcontent reset="true" does not get added to the resulting document. Does the cf_layout tag you are calling after your cf_htmlhead contain a content reset?
For example,
<!--- This will not be added under CF11. --->
<cfhtmlhead text="<!-- I'm some content that will only be included in CF10 or lower. -->">
<cfcontent reset="true">
<!--- This will be added under CF11 and lower. --->
<cfhtmlhead text="<!-- I'm some content that will be added in CF11 and lower. -->">
... the rest of your view code ...
<!--- This is a sample of the content you will get under CF11 --->
<!doctype html>
<html>
<head>
<meta charset="UTF-8" />
<title>Head Testing</title>
<!-- I'm some content that will be added in CF11 and lower. -->
</head>
<body>
<h1>Page content</h1>
</body>
</html>

Using cfpdf to display pdf files

I have a page where I need to display a pdf and an "I agree" button.
Q: Do I use cfpdf to create a thumbnail of the pdf and display the resulting output?
Chapter 32 of cfWack 8 talks about using cfpdf.
I did this in the office once...It's not that sweet as it's presented in Adobe's whitepapers.
Here's my code:
<cfpdf source="#attachmentFilePath##attachmentFilename#" pages="1" imagePrefix="#prefix#" action="thumbnail" destination="#application.attachmentsFilePath#/_thumbs" format="jpg" overwrite="true" resolution="low" scale="80">
<cfset thumbURL = "http://127.0.0.1:9001/attachments/_thumbs/#prefix#_page_1.jpg">
<cfif fileExists(thumb)>
<tr>
<td width="100%">
<a href="attachmentView.cfm?attachNo=#attachNo#&act=download">
<img alt="#attachmentFilename#" src="#thumbURL#" width="500" />
</a>
</td>
</tr>
<cfelse>
<cfheader name="Content-Type" value="#attachmentMIMEType#">
<cfheader name="Content-Disposition" value="attachment; filename=#attachmentFilename#">
<cfcontent type="#attachmentMIMEType#" file="#attachmentFilePath##attachmentFilename#">
</cfif>
I also check isPDF() and putting all this in try/catch.
So what's wrong with this? It works with 30% of PDF users are trying to preview so in catch I display link for download instead of image :(