0

I'm we're trying to figure out if there would be a way to convert a .txt file to a .pdf file. Here's the catch. This needs to be done behind the scenes, and on the fly. Meaning, with a radio control selected, OnOK would create a .txt file. Behind the scenes, at run time, we would like for the .txt file to be converted to a .pdf file. Ideally we would like this to be done by running an executable in the background. The executable would take input "File.txt" and output "File.pdf". We're using C++ and Visual Studio 6.

Does anyone have any experience on this? Is this possible?

genpfault
  • 51,148
  • 11
  • 85
  • 139
Skizz
  • 1,405
  • 2
  • 11
  • 12

4 Answers4

2

libHaru may do what you want. Demo.

genpfault
  • 51,148
  • 11
  • 85
  • 139
  • 1
    LibHaru is a good package. Creating a PDF from text will only take a little bookkeeping for line and page endings. – Mark Ransom Apr 20 '11 at 20:43
1

This a2pdf tool will probably do the trick with minimal effort. Just be sure to turn off perl syntax highlighting.

http://perl.jonallen.info/projects/a2pdf

Null Set
  • 5,374
  • 24
  • 37
0

I recommend using this open source library. Once you have the base for generating PDF documents programmatically, you would still need a method for converting the text to the PDF elements, while keeping the text flow and word wrapping. This article may help. Please pay attention to the DoText(StreamReader sr) function. It takes text and purge it into separate lines within the PDF document, keeping the rendered within the margins.

Michael Haephrati
  • 3,660
  • 1
  • 33
  • 56
0

On of the simpler methods that has worked for 3 decades e.g. more than one quarter of a century is place a postscript header before the text then use ghostscript ps2pdf it is the same method as used by some commercial apps such as acrobat

at its most basic

Copy heading.ps file.txt printfile.ps
GS -sDEVICE=pdfwrite printfile.ps printfile.pdf

Master Example can be seen here

How to modify this plaintext-to-PDF-converting PostScript from 1992 to actually specify a page size?

K J
  • 8,045
  • 3
  • 14
  • 36