Solved

Convert a Text File to PDF (Coldfusion)

Posted on 2010-08-22
11
447 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
  • 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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Most current Records - Query or Query ColdFusion 5 62
cfpdfform and populate 14 70
Coldfusion update database with CFLOOP 5 64
CFIf Syntax and Logic 27 42
Hi, Even though I have created this Tutorial on My personal Blog, Some people might not able to find my website, So here i am posting it again Today, from the topic it is very clear that i will be showing you here the very basic usage of how we …
Recently while working on a project I got a very annoying cfdocument has no body error message. I had never seen this error before. So I checked the code. The code was pretty simple; it was Just showing me the cfdocumnt tag and inside that tag a …
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

805 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