Solved

Convert a Text File to PDF (Coldfusion)

Posted on 2010-08-22
11
470 Views
Last Modified: 2012-05-10
Hi all.

How do convert a text file to PDF without losing the spaces, lines breaks etc)? I tried with <cfdocument format="pdf"> and looping over the text file but I loose all the spaces.

I need it to be exactly as the original text file but in PDF format.

Thanks,

Errol
0
Comment
Question by:Errol Farro
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +4
11 Comments
 
LVL 6

Expert Comment

by:sagiamar
ID: 33496480
did you try to use CutePDF printer ?

you can download from here http://www.cutepdf.com/
0
 
LVL 1

Expert Comment

by:mugsinc
ID: 33499278
try cffile and read the text file and output the content to a cfm document and then convert it to PDF
0
 
LVL 4

Expert Comment

by:silvera21
ID: 33502374
since cfdocument takes a webpage and converts it to PDF, that is why you are loosing your formatting. The text file is being interpreted as html. You would have to add that back, with inserting <br> tags and non-breaking spaces (&nbsp;) as you loop through the file. Or else the HTML interpretation will just run it together.
0
Raise the IQ of Your IT Alerts

From IT major incidents to manufacturing line slowdowns, every business process generates insights that need to reach the people required to take action. You need a platform that integrates with your business tools to create fully enabled DevOps toolchains.

You need xMatters.

 
LVL 63

Expert Comment

by:Zvonko
ID: 33504219
Check this:

<cfdocument format="pdf" srcfile="#ExpandPath(".\mytest.txt")#" mimetype="text/plain" >
</cfdocument>

0
 

Author Comment

by:Errol Farro
ID: 33505524
Hi Silvera21 and Zvonko,

I tried both suggestions. The result is somewhat better but still not 100%. Fields that fall exactly below
each other when opening with notepad or text pad, doesn't fall right below each other anymore. It has to be 100% the same since this text file needs to be used to print on a pre-printed form.
0
 
LVL 63

Expert Comment

by:Zvonko
ID: 33505639
What Font do you use in Notepad?
0
 

Author Comment

by:Errol Farro
ID: 33505798
Lucida Console, Regular, 10.
0
 
LVL 4

Expert Comment

by:silvera21
ID: 33506148
Perhaps instead of adding back the formatting as spaces and breaks you should be adding tables and table cells where necessary instead. This could possibly keep everything lined up. It sounds like the formatting is always the same, with the same number of fields. You can add ids to the cells and use css for further formatting and tweaking.
0
 
LVL 63

Expert Comment

by:Zvonko
ID: 33506998
There is no way to set base font for plain text files in cfdocument for PDF except doing it in basic Java calls. And that is definitely far beyond displaying Notepad formatted tables instead of HTML tables.

Use the proposal from the comment above.

0
 
LVL 3

Accepted Solution

by:
dagaz_de earned 125 total points
ID: 33508836
When you read the file to a variable try this:

<cfset thetext = replace(thetext, "#chr(13)##chr(10)#", "<br />", "all")>

with this method you can replace all other special chars too e.g. tabs

After that output it between your cfdocument tag
0
 
LVL 6

Assisted Solution

by:reiters
reiters earned 125 total points
ID: 33522941
This seems messy but you could:

<cfset thetext = replace(thetext, "#chr(13)##chr(10)#", "<br />", "all")>
<cfset thetext = replace(thetext, " ", "&nbsp;", "all")>
0

Featured Post

Learn by Doing. Anytime. Anywhere.

Do you like to learn by doing?
Our labs and exercises give you the chance to do just that: Learn by performing actions on real environments.

Hands-on, scenario-based labs give you experience on real environments provided by us so you don't have to worry about breaking anything.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article  is about submitting  form through  ColdFusion.Ajax.submitForm to the action page and send a response back in JSON format which later can be decoded using ColdFusion.JSON.decode. By this way you can avoid the usual page refresh for subm…
Hi. There are several upload tutorials using jquery and coldfusion. I found a very interesting one here Upload Your Files using Jquery & ColdFusion and Preview them (http://www.randhawaworld.com/) . I did keep the main js functions but made sever…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

717 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question