HylaFAX The world's most advanced open source fax server |
Michele Petrazzo - Unipex srl wrote:
4. better/easy way to create cover pages and *archive* them with faxes
+1!
The biggest difficulty here has been finding the *better* way. Here are the alternative ways that I've investigated...
After read this mail I spend some time for make tries and, I think to have found a possible solution with open sources programs and standard formats: openoffice -> pdf (with fdf) -> a script in someone language -> pdftk -> pdf filled !
These was my tries: Open the new OOo 3 (rc1, so the last unstable, but I think IT works with OOo 2), create a new OOo text document, add some "text box" with the "form control" dialog. Rename them with a unique name. Export the document with: file -> export as pdf -> general -> create pdf form -> submit form -> fdf
Create the fdf file and use pdftk for create the filled pdf file output. Thats all.
For create the fdf file I use my preferred language (python), but you can use which you want.
All this, except the pdf creation (with OOo) works without X, that on a server, normally isn't present.
The unique problem that I see here, it's that pdftk are done in java (on debian need libgcj and gcj) that can be not present on all the platforms where hylafax works on. If this is a problem, I can analyze the pdftk sources for see if there is the possibility to re-create the pdf-fill operations with python, that as I can know, it's present in all the os.
Attached here there is the odf file, the pdf one and the python script for create the fdf and the filled pdf.
Hope this help, Michele
Attachment:
hylafax_test.odt
Description: application/vnd.oasis.opendocument.text
Attachment:
hylafax_test.pdf
Description: Adobe PDF document
#!/usr/bin/python INPUT_PDF = "hylafax_test.pdf" OUTPUT_PDF = "hylafax_test_merge.pdf" import os from tempfile import mkstemp def go(): data_to_fill = {"name": "Michele", "surname": "Petrazzo", "multiline_field": "hylafax\nit's\nthe\nbetter"} fdf_path_out = create_fdf(data_to_fill) pdf_path = INPUT_PDF pdf_path_out = OUTPUT_PDF # pdftk usage: pdftk form.pdf fill_form data.fdf output out.pdf flatten os.system("/usr/bin/pdftk %s fill_form %s output %s flatten" % (pdf_path, fdf_path_out, pdf_path_out) ) #remove the fdf temp file os.remove(fdf_path_out) def create_fdf(data_to_fill): data = "%FDF-1.2\x0d%\xe2\xe3\xcf\xd3\x0d\x0a"; # header data += "1 0 obj\x0d<< " # open the Root dictionary data += "\x0d/FDF << " # open the FDF dictionary data += "/Fields [ " # open the form Fields array for k, v in data_to_fill.iteritems(): data += '<< /T (%s) /V (%s) /ClrF 2 /ClrFf 1 >> ' % (k, v) data += "] \x0d" # close the Fields array data += ">> \x0d" # close the FDF dictionary data += ">> \x0dendobj\x0d" # close the Root dictionary # trailer note the "1 0 R" reference to "1 0 obj" above data += "trailer\x0d<<\x0d/Root 1 0 R \x0d\x0d>>\x0d" data += "%%EOF\x0d\x0a" fd, path_out = mkstemp(prefix="hylafax_cover_") file_write = os.fdopen(fd, "wb") file_write.write(data) file_write.close() return path_out if __name__ == '__main__': go()