Solved

Convert a Text File to PDF (Coldfusion)

Posted on 2010-08-22
11
435 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
Comment Utility
did you try to use CutePDF printer ?

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

Expert Comment

by:mugsinc
Comment Utility
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
Comment Utility
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
Comment Utility
Check this:

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

0
 

Author Comment

by:Errol Farro
Comment Utility
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 63

Expert Comment

by:Zvonko
Comment Utility
What Font do you use in Notepad?
0
 

Author Comment

by:Errol Farro
Comment Utility
Lucida Console, Regular, 10.
0
 
LVL 4

Expert Comment

by:silvera21
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

The technique is by far very Simple! How we can export the ColdFusion query results to DOC file?  Well before writing this I researched a lot in Internet but did not found a good Answer anyways!  So i thought now i should share my small snippet w…
Sometimes databases have MILLIONS of records and we need a way to quickly query that table to return the results me need. Sure you could use CFQUERY but it takes too long when there are millions of records. That is why SOLR was invented. Please …
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

744 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

17 Experts available now in Live!

Get 1:1 Help Now