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
Solved

Convert a Text File to PDF (Coldfusion)

Posted on 2010-08-22
11
454 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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
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…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

839 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