How to generate pdf file from an html page??

MonkeeSage MonkeeSage at gmail.com
Thu Dec 20 07:52:32 EST 2007


On Dec 19, 10:17 am, Grant Edwards <gra... at visi.com> wrote:
> On 2007-12-19, Terry Jones <te... at jon.es> wrote:
>
>
>
> >>>>>> "Grant" == Grant Edwards <gra... at visi.com> writes:
> >Grant> On 2007-12-19, abhishek <guptaabhishek1... at gmail.com> wrote:
> >>>> > Hi everyone, I am trying to generate a PDF printable format file from
> >>>> > an html page. Is there a way to do this using python. If yes then
> >>>> > which library and functions are required and if no then reasons why it
> >>>> > cant be done.
>
> >>>> Here's one way:
>
> >>>> ------------------------------html2pdf.py-----------------------------------------
> >>>> #!/usr/bin/python
> >>>> import os,sys
>
> >>>> inputFilename,outputFilename = sys.argv[1:3]
>
> >>>> os.system("w3m -dump %s | a2ps -B --borders=no | ps2pdf - %s" % (inputFilename,outputFilename))
>
> > Note that this is highly insecure. outputFilename could be passed e.g., as
>
> >   /tmp/file.pdf; rm -fr /home/abhishek
>
> Here's a half-assed solution:
>
> inputFilename = inputFilename.replace("'","")
> outputFilename = outputFilename.replace("'","")
>
> os.system("w3m -dump '%s' | a2ps -B --borders=no | ps2pdf - '%s'" % (inputFilename,outputFilename))
>
> As somebody else suggested, building the pipeline "by hand"
> using the subprocess module is the most bullet-proof method.
>
> --
> Grant Edwards                   grante             Yow! I brought my BOWLING
>                                   at               BALL -- and some DRUGS!!
>                                visi.com

This looks a little better for me ... | a2ps -B --borders=0 --
columns=1 -f 10.0 | ...

Regards,
Jordan



More information about the Python-list mailing list