Solved

Convert a Text File to PDF (Coldfusion)

Posted on 2010-08-22
11
444 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
 
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
DevOps Toolchain Recommendations

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

 
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
Create array from a query and then loop it with coldfusion 12 68
CSS HELP 6 84
Coldfusion- Create and save form elements in Database 7 61
Coldfusion RegEx 8 56
PROBLEM: How to add your own buttons to the bottom toolbar with paging info ( result count ). While creating a cfgrid, I ran into an issue where I wanted to embed my own custom buttons where the default ones ( insert / delete / etc… ) are for aes…
CFGRID Custom Functionality Series -  Part 1 Hi Guys, I was once asked how it is possible to to add a hyperlink in the cfgrid and open the window to show the data. Now this is quite simple, I have to use the EXT JS library for this and I achiev…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

910 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now