Re: Creating PDF files with Perl
by moritz (Cardinal) on May 09, 2011 at 13:41 UTC
|
I am trying to creating PDF files using "HTML::HTMLDoc", that seems to be the easiest one to accomplish this using Perl.
I found it easist to generate LaTeX files with Perl (for example with Text::Template), and run it through pdflatex. Your mileage might vary though.
| [reply] |
|
| [reply] [d/l] |
|
Do you have any code sample from your previous posting?
| [reply] |
|
|
Would you have any sample code based in what is been posted here and based in what you are suggesting?
| [reply] |
Re: Creating PDF files with Perl
by chrestomanci (Priest) on May 09, 2011 at 14:46 UTC
|
I have had success creating pdf files by first creating an svg document for each page, then converting to pdf using inkscape's svg2pdf tool, I then joined all the separate pdf files into one multi page document using pdftk
On that occasion the SVG file was created via a template. You could also look into GD::SVG
| [reply] |
Re: Creating PDF files with Perl (CPAN-Review)
by LanX (Saint) on May 10, 2011 at 13:21 UTC
|
| [reply] |
|
In my experience, htmldoc frequently dies ungracefully on HTML syntax it cannot digest, even when it is perfectly valid. So the RTFM method needs extra error handling. I do not know HTML::HTMLdoc, but the other comments indicate to me, that the module gives no good feedback on any problem.
Now to the actual question:
a field that I can edit from the PDF, like an input type="text" in a form, is that possible?
No. htmldoc does only*) simple HTML 3 and simple PDF, cf www.htmldoc.org
- *)
- I still find it useful when you have HTML in the first place and can clean up a bit before passing it on to htmldoc
| [reply] |
Re: Creating PDF files with Perl
by ww (Archbishop) on May 09, 2011 at 19:43 UTC
|
And before you ask -- again -- for "sample code" from one of the responders, you might wish to RTFM. | [reply] |
|
The reason is because all see here is people suggesting with no possible solution based on the person's code, and I see that this person posted some code sample for people to look at it, but come on, the answers here are no different than "Googling" for the topic been asked. Be reasonable, thats all!
| [reply] |
|
Due to popular demand ^^, here is a hello world example:
use warnings;
use strict;
use Template;
# create Template object
my $ttt = Template->new();
# define template variables for replacement
my $replacements = { name => "holli" };
my $template = join ("", <DATA>);
# process input template, substituting variables and save it to disk
$ttt->process( \$template, $replacements, "output.xml") || die $templa
+te->error();
#call fop and translate xml file to pdf
system "d:\\fop-1.0\\fop.bat -fo output.xml -pdf output.pdf"
__DATA__
<?xml version="1.0" encoding="iso-8859-1"?>
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
<fo:layout-master-set>
<fo:simple-page-master master-name="my-page">
<fo:region-body margin="1in"/>
</fo:simple-page-master>
</fo:layout-master-set>
<fo:page-sequence master-reference="my-page">
<fo:flow flow-name="xsl-region-body">
<fo:block>Hello, [% name %]!</fo:block>
</fo:flow>
</fo:page-sequence>
</fo:root>
Instead of running fop via system, you might also look at XML::ApacheFOP.
holli
You can lead your users to water, but alas, you cannot drown them.
| [reply] [d/l] |
|
I think my prior response was not unreasonable, given the appearance and reappearance of your (boilerplate) request for "sample code."
Read the documentation for what's suggested here; read the docs that Google turns up.
Don't ask, thinly disguised as a request for "sample code," that the Monks give you a complete solution. You'll learn a lot more from the docs and the effort to code your own solution.
| [reply] |
|
|