How to render PDF data (Not a PDF file).

703 views
Skip to first unread message

James Bearden

unread,
Nov 19, 2012, 12:16:14 PM11/19/12
to mojol...@googlegroups.com
Hello,

I am, among other things, using a perl module to create dynamic PDF content. I could save the data to a temporary file and serve it up as a static file, but I would prefer to minimize flogging the hard drive. Mojolicious renders text and json data nicely, but how do I specify that I am sending PDF data? I have tried something like "$self->render(template => 'application/pdf', data => $Data);" but that doesn't work. Does anybody have any ideas? I have searched the archive and all I could find was information about serving PDF files, not PDF data. Any help would be greatly appreciated.

James

Pavel Goloborodko

unread,
Nov 19, 2012, 1:12:07 PM11/19/12
to mojol...@googlegroups.com
That's how I do that

$self->res->headers->content_disposition('attachment;filename='.$name.'.pdf');
$self->res->headers->content_type('application/pdf');
$self->render_data( $pdf );




James

--
You received this message because you are subscribed to the Google Groups "Mojolicious" group.
To view this discussion on the web visit https://groups.google.com/d/msg/mojolicious/-/0jeWA5USbgoJ.
To post to this group, send email to mojol...@googlegroups.com.
To unsubscribe from this group, send email to mojolicious...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/mojolicious?hl=en.



--
С уважением, / Kind regards,
Павел Голобородько / Pavel Goloborodko

Виктор Турский

unread,
Nov 20, 2012, 4:29:19 AM11/20/12
to Mojolicious
You can take a look at
https://metacpan.org/module/Mojolicious::Plugin::RenderFile
With this plugin you can easily render file from memory in the following way:
$self->render_file('data' => 'some data here', 'filename' => 'report.pdf');

2012/11/19 James Bearden <ja...@nontrivial.org>:
> --
> You received this message because you are subscribed to the Google Groups
> "Mojolicious" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/mojolicious/-/0jeWA5USbgoJ.
> To post to this group, send email to mojol...@googlegroups.com.
> To unsubscribe from this group, send email to
> mojolicious...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/mojolicious?hl=en.



--
Viktor Turskyi
http://webbylab.com
http://koorchik.blogspot.com

James Bearden

unread,
Jan 1, 2013, 4:46:15 PM1/1/13
to mojol...@googlegroups.com
Thanks,

I ended up using PDF::Create thusly:

my $pdf = new PDF::Create('Author'       => 'Howdy', 'Title'    => 'Howdy', 'CreationDate' => [ localtime ], );
my $page = $pdf->new_page('MediaBox' => $pdf->get_page_size('Letter'));
my $cert = $pdf->image(Mojo::Home->new->detect('H3O') . '/pub/static/images/cert.gif');
my $f1 = $pdf->font('BaseFont' => 'Helvetica');

$page->image('image' => $cert, 'xpos' => 5, 'ypos' => -6);
$page->stringc($f1, 16, 300, 350, "Howdy");

$pdf->close;
$Self->res->headers->content_disposition('attachment;filename='.'cert.pdf');
$Self->res->headers->content_type('application/pdf');
$Self->render(data => $pdf->get_data());

James

Tekki

unread,
Jan 5, 2013, 3:54:56 PM1/5/13
to mojol...@googlegroups.com
Am Dienstag, 1. Januar 2013 22:46:15 UTC+1 schrieb James Bearden:
I ended up using PDF::Create ...


It would be interesting to know how the others create PDF files. My impression is that modules like PDF::Create or PDF::API2 are not suitable to create more sophisticated documents, for example with tables that span multiple pages. What do you use? One of these? Another Perl module? Or an external program like FOP?

Regards
Tekki

sdnpol

unread,
Jan 6, 2013, 2:31:52 AM1/6/13
to mojol...@googlegroups.com
I use LaTex to create pdf files and then Mojolicious::Plugin::RenderFile to render them. As I need reports with check and radio boxes I started from here http://www.svenhartenstein.de/Software/LaTeX-Questionnaires

Regards
Paolo Saudin

Виктор Турский

unread,
Jan 6, 2013, 3:09:39 AM1/6/13
to Mojolicious
2013/1/5 Tekki <in...@tokon.net>

It would be interesting to know how the others create PDF files. My impression is that modules like PDF::Create or PDF::API2 are not suitable to create more sophisticated documents, for example with tables that span multiple pages. What do you use? One of these? Another Perl module? Or an external program like FOP?
You can try converting HTML to PDF.
I tryed a lot of solutions and the best working variant is WKHTMLTOPDF. But it lacks some features like repeatable table headers for mulipage reports. And now I use PHP mpdf (as extrernal script) to convert HTML to PDF. Mpdf supports a lot of features related to table formatting including repetable headers. 

satish MP

unread,
Jan 10, 2013, 12:40:41 PM1/10/13
to mojol...@googlegroups.com
HI All,

Recently I came through this kind of requirement, where I suppose  to write a PDF in regional/Indian language. I had to do lot of R & D , finally wha t worked was Dhrupal - Print PDF and Mpdf - has many features

Also works is Dhrpual Print PDF  with TCPDF.

Scott

unread,
Jan 15, 2013, 2:02:19 PM1/15/13
to mojol...@googlegroups.com

It would be interesting to know how the others create PDF files. My impression is that modules like PDF::Create or PDF::API2 are not suitable to create more sophisticated documents, for example with tables that span multiple pages. What do you use? One of these? Another Perl module? Or an external program like FOP?


I have used PDF::Reuse on a couple of projects. The module is a little old, but it is still working on a live site I maintain. The best use of the module is to take am already created PDF document and then add dynamic content to it. I use it for a report where I have to provide dynamic content to the proper location within a document, but because I start with a PDF page, 90% of the content is already in place. I would not use it to render an HTML page as a PDF view, but for providing certificates and reports is works well.

Scott

Rolf Schaufelberger

unread,
Jan 15, 2013, 4:53:11 PM1/15/13
to mojol...@googlegroups.com, Tekki
We use a commercial license from pdflib (www.pdflib.com). 
Licence starts at about 1000 Euros. Sounds much in the first moment but count the hours you save compared to try and error when dealing with PDF::API2 , the docs there are n't very verbose. 
Rolf Schaufelberger

Reply all
Reply to author
Forward
0 new messages