Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
Enough of the frustrations. Past time I sought a few more eyeballs on this issue.

I have this project spread across three servers at the moment: my local sandbox, my testbed server and the production server. The code below has not been deployed yet to production. An earlier version of this code is running on the testbed server and generating both a valid pdf at example.pdf and a plain text file at the computed path and file name.

On my local sandbox machine, I get only a two '\n' linefeed file which my file command describes as: 'ASCII text', and ls reports as having a length of two bytes.

I have three times now in the past two days, scp'd the sort of working module, template and configuration file from testbed, back to my sandbox and used diff to compare them with the local code which is not working. No distinctions which would explain the different result are apparent to me.

My preference would be to render the pdf in place with the generated path and file name (to prevent a race condition where two or more users might over-write one anothers example.pdf before it was moved into place. But for the moment I'd be happy to merely see the example.pdf file generated on my local sandbox. But so far I have met with no luck on that front.

My template -- drawing directly from perldoc for Template::Latex, looks like this:

[% USE Latex %] [% FILTER latex('example.pdf') %] \documentclass[letterpaper,10pt]{article} \usepackage{marvosym} . . . \end{document} [% END %]
Removing the FILTER line breaks this on the testbed server. Any and all attempts to replace example.pdf with a variable fed from the module also breaks things.

My configuration file includes a stanza like this:

[pdf] include_path='/etc/ymd/client_name/tmpl/' template='' output_path='/home/reports/pdfs/' report_type='weekly/' output='wkly_rpt__' suffix='_w'
My module includes:

package My::Module; use warnings; use strict; use File::Path; use Template::Latex; use Template::Constants qw( :debug ); use Template::Filters; use base 'CGI::FormBuilder::Config::Simple'; sub new { my $class = shift; my $ini = shift; # creates a Config::Simple object; # creates a DBI::db object return $self; } sub render_pdf_report { my $self = shift; my $field = shift; my $template = $self->{'cfg'}->param("pdf.template"); $self->{'pdf_output_path'} = $self->{'cfg'}->param("pdf.output_path" +) . $field->{'region'} . '/' . $self->{'cfg'}->param(" +_type"); $self->{'pdf_output_path'} =~ s/\ /_/g; chomp($self->{'pdf_output_path'}); unless( -d $self->{'pdf_output_path'} ){ mkpath $self->{'pdf_output_path'}; } $self->{'pdf_output'} = 'wkly_rpt_' . $field->{'region'} . '_' . $fi +eld->{'report_id'} . $self->{'cfg'}->param("pdf.suffix") . '.pdf'; $self->{'pdf_output'} =~ s/\ /_/g; chomp($self->{'pdf_output'}); $field->{'pdf_output'} = $self->{'pdf_output'}; $self->{'latex_paths'} = Template::Latex->latex_paths(); $self->{'tt'} = Template::Latex->new({ DEBUG => DEBUG_FILTERS | DEBUG_PLUGINS, INCLUDE_PATH => $self->{'cfg'}->param("pdf.include_path") +, OUTPUT_PATH => $self->{'pdf_output_path'}, LATEX_FORMAT => 'pdf' }); $Template::Latex::DEBUG = 1; $self->{'tt'}->process($template,{ field => $field },$self->{'pdf_ou +tput'},binmode => 1) || die $self->{'tt'}->error(); my $tmp_file = $self->{'pdf_output_path'} . 'example.pdf'; my $file = $self->{'pdf_output_path'} . $self->{'pdf_output'}; rename $tmp_file, $file; return; }
Running my test script generates these debug messages in my console:

[Template::Filters] store(latex_encode, ARRAY(0x9157390)) [Template::Filters] store(latex, ARRAY(0x91573c0)) [Template::Plugins] fetch(Latex, <no args>, Template::Context=HASH(0x91036c0)) [Template::Plugins] loading (PLUGIN_NAME) [Template::Plugins] calling Template::Plugin::Latex->load() [Template::Plugins] Latex => Template::Plugin::Latex [Template::Filters] store(latex_encode, ARRAY(0x92022c8)) [Template::Filters] store(latex, ARRAY(0x9202288)) [Template::Filters] fetch(latex, [ example.pdf ], Template::Context=HASH(0x91036c0))
and results in the following results:

ok 6 - We have correct path to: ps2pdf ok 7 - We have correct path to: dvips ok 8 - We have correct path to: bibtex ok 9 - We have correct path to: pdflatex ok 10 - We have correct path to: makeindex ok 11 - We have correct path to: latex ok 12 - Generated correct file name ok 13 - Generated the correct file path ok 14 - The file exists not ok 15 - Our file is a pdf file # TODO Not yet successfully produci +ng our pdf files # Failed (TODO) test 'Our file is a pdf file' # at t/11-pdf-report.t line 64. # 'text/plain' # doesn't match '(?-xism:application/pdf)' not ok 16 - We replicated a correct pdf file. # TODO Not yet successfu +lly producing our pdf files # Failed (TODO) test 'We replicated a correct pdf file.' # at t/11-pdf-report.t line 66. # got: 'e1c06d85ae7b8b032bef47e42e4c08f9' # expected: 'c27f1cab0f2e44184ebd8ce5361db134'
Those disparate values on test #16 being the md5 checksums of the generated (empty) file and the sample file it should match.

Can anyone advise what I might be missing here, please?

All help is appreciated.

-- Hugh

if( $lal && $lol ) { $life++; }
if( $insurance->rationing() ) { $people->die(); }

In reply to Template::Latex Frustrations . . . by hesco

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?

What's my password?
Create A New User
Domain Nodelet?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (2)
As of 2023-06-07 14:40 GMT
Find Nodes?
    Voting Booth?
    How often do you go to conferences?

    Results (29 votes). Check out past polls.