How to generate pdf file from an html page??

Ismail Dönmez ismail at pardus.org.tr
Wed Dec 19 10:55:49 EST 2007


Wednesday 19 December 2007 17:40:17 tarihinde Terry Jones şunları yazmıştı:
> >>>>> "Grant" == Grant Edwards <grante at visi.com> writes:
>
> Grant> On 2007-12-19, abhishek <guptaabhishek1983 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

And the solution is to use subprocess [0] instead of os.system()

[0] http://docs.python.org/lib/module-subprocess.html

Regards,
ismail

-- 
Never learn by your mistakes, if you do you may never dare to try again.



More information about the Python-list mailing list