Home > front end >  script to create PDF from delimited txt/csv
script to create PDF from delimited txt/csv

Time:12-10

Hope everyone who is reading this is just fine!

I'm currently working as a developer for bash/unix processes.

So... I was assigned the task of generating a PDF report with the information we receive daily, this information consists on fields separated by pipes "|" , which I can extract easily with awk and print to a simple .txt output. The problem is, how can I generate a PDF file from a bashscript?. Currently I have been reading a lil' bit about postscript but the time is getting shorter and shorter, could someone please help me with some idea?

Thaks

Tried to do some things with postscript:

% ------------ Define Procedures -------------
/colorear
{ gsave
  setrgbcolor fill
  grestore stroke
} def

/rellenar
{ gsave
  setgray fill
  grestore stroke
} def

/TEXT {moveto show} def
/TEXT_CENTER {moveto Centrar show} def
/TEXT_RIGHT  {moveto Derecha show} def

But it's too complex to achieve what i want in deadline, so i'm asking for help, even if i could finish the .ps program, i think i have to convert it to PDF by using ghostscript, so it's all about the time i have left to make this possible

CodePudding user response:

You can use cupsfilter to convert to pdf. It's basically printing to pdf but directed to standard output.

cupsfilter input.txt > output.pdf

CodePudding user response:

The "quick hack" way I usually do this kind of thing is to use a tool like awk or perl to convert the data into PostScript data. Then the PostScript code to use it can be simple and straightforward.

$ cat data.txt
field 1|field 2|field 3
$ echo \[ ; perl -npe "s/^/[(/; s/\|/)(/g; s/$/)]/;" data.txt ; echo \]
[
[(field 1)(field 2)(field 3)]
]

Then you can iterate through the arrays with forall.

% assume above data is on the stack
72 720 moveto % 1 inch from top left of US letter paper
/position-next-field { 36 0 rmoveto } def
/position-next-line { 36 currentpoint exch pop 20 sub moveto } def
{ % each line
  { % each field
    show
    position-next-field
  } forall
  position-next-line
} forall
showpage
  • Related