Catalyst::View::Wkhtmltopdf creating error with template - perl

I am using Catalyst::View::Wkhtmltopdf but issues are araising,
got the error
Caught exception in wealthe::View::Wkhtmltopdf->process "Void-input at /usr/local/share/perl5/Catalyst/View/Wkhtmltopdf.pm line 98."
When checked found its some issue with template, I have added the following config in myapp.pm
'View::Wkhtmltopdf' => { command => '/usr/local/bin/wkhtmltopdf',
tmpdir => '/usr/tmp',
tt_view => 'TT',
}
Template name is TT.pm under View and TT.pm is rendering correctly,
I have made Wkhtmltopdf.pm file under View with the following contents
package myapp::View::Wkhtmltopdf;
use Moose;
extends qw/Catalyst::View::Wkhtmltopdf/;
PACKAGE->meta->make_immutable();
is there anything else I need to get it working.

My experience with the PDF writing perl modules on CPAN is that every option is either:
extremely simple, but capable of only very rudimentary output
fully featured and capable of professional PDF output, but hideously complex and requiring pretty deep knowledge of PDF internals
We gave up.
Instead of trying to generate PDFs with perl natively from scratch, we attacked the problem by building the pages we wanted to render as PDF with Template Toolkit (in most cases reusing existing templates with different wrappers), and used the excellent wkhtmltopdf to handle the conversion to PDF.
Since then, Catalyst::View::Wkhtmltopdf has become available that makes this even simpler.

One of the easiest way is to create a (quite simple) HTML page then convert it to PDF: https://metacpan.org/pod/PDF::FromHTML
It needs the least amount of PDF knowledge.
The other module could create PDF on the fly but they are much more complicated: https://metacpan.org/pod/PDF::API2

Related

Combine two TCPDF documents

I'm using TCPDF to create two separate reports in different parts of my website. I would like that, in the end of the first report, the second report should be loaded.
It's different than import a PDF file, because the second report is also generated by TCPDF. Is there a way to do this?
I assume from your question that what you ultimately want to provide is one PDF file that consists of the first PDF concatenated with the second PDF.
One quick and dirty solution is to utilize the pdftk command line PDF processor and call it from within your PHP code using the exec() function. The pdftk command has many features and concatenating files is only one of them, but it does an awesome job. Depending on your hosting situation, this may or may not be an option for you.
The other option would be to use FPDI to import the two PDF files and concatenate them within your PHP code and then send the concatenated version to the user.
More information on using PFDI here:
Merge existing PDF with dynamically generated PDF using TCPDF
Given that you're already using TCPDF, importing the pre-existing file that you want to concatenate with the one you've just created shouldn't be too difficult.
Just add FPDI to your project/composer from:
https://www.setasign.com/products/fpdi/downloads/
Can you still used tcpdf.
FPDI support all the methods of tcpdf, just used new FPDI() instead new tcpdf() the result will be the same in your report, after you create your report marge the files with the code from this page:
https://www.setasign.com/products/fpdi/about/
In a loop, once set the first file and after this set the second...
If you will need help i am here for you.

simple php multiple upload resize

I'm looking for a script that uploads and resizes multiple images using php. I'm using a shared hosting so can't install things. I had managed to upload, resize and watermark ONE image but really can't get it to work with multiple files.
Has anyone got something I could start with please?
Thank you
Take a look at ImageWorkshop, which is a good oop image manipulation library in pure PHP (GD), and supports multiple layer.
Simple loop through your files:
foreach($_FILES['files']['tmp_name'] as $key => $tmp_name ){
$layer = ImageWorkshop::initFromPath($tmp_name);
$layer->resizeInPixel(400, null, true);
$layer->save($dirPath, $filename, $createFolders, $backgroundColor, $imageQuality);
}
More info in the Quickstart.
Sure you can also write you own Image Library.

Perl Catalyst, pass to stash 2 template parts

I started learning Perl Catalyst and its awesome!!! However, I am having a little issue here with templateing.
I am trying to pass two template variables to the page (header and footer), what I did in the Controller function is
$c->stash(template => 'header.html');
//other page contents
$c->stash(template => 'footer.html');
but this only outputs the footer.html (which it should and seems logical)
What would be the way for this approach? I searched google but could not find many helpful results (at least results that I could understand and use)
You need to create a view.
https://metacpan.org/pod/Catalyst::Manual::Tutorial::02_CatalystBasics#Hello-World-Using-a-View-and-a-Template
Also, have a look at how wrappers work in TT -- they are really cool.
http://www.template-toolkit.org/docs/manual/Directives.html#section_WRAPPER
You cannot pass 2 templates in stash.Only the last value will be kept.However the to way to do this, is to include the footer template inside the header.The commands include and process are very helpfull.

HTML form to invoke XQuery files

We have quite a number of .xqy files in several folders.
Sometimes, I need to invoke an .xqy file (via Marklogic's CQ) to test if it's working.
But I find it rather cumbersome to have to know what parameters to pass in and specify them in the xquery in CQ.
Is there a tool out there that would generate an HTML form that presents to me the parameters of a given .XQY file and invokes it when I press a "submit" button ?
If there is none out there, would somebody here know of how to make such an HTML form ? Right now, I can't seem to find any readily-available xdmp or xquery commands to tell me if an .XQY file is invocable or what parameters it expects to be fed.
Danny
The XQuery standard doesn't support introspection, nor does MarkLogic provide any functions that help with that. The closest you can get with this is using the XQDoc documentation code that is capable of parsing the XQuery code itself and producing descriptions of all function signatures within modules.
You can find more details about it here: http://developer.marklogic.com/code/xqdoc-ws
It doesn't provide a 'Submit' button, but using the XML output of xqdoc, you could make that yourself..
Good luck!
Another option would be to convert your XQuery to XQueryX and you can then process this as XML using XQuery (or XSLT) to generate an XForm or XHTML Form.
Since Danny mentioned unit testing, I'll risk plugging my own framework for that: https://github.com/mblakele/xqut
I usually run XQUT test suites in a cq buffer, but it would be easy enough to wrap one in a simple web page - with or without a form.

What is the best file parsing solution for converting files?

I am looking for the best solution for custom file parsing for our enterprise import routines. I want to basically change one file format into a standard file format and have one routine that imports that data into the database. I need to be able to create custom scripts for each client since its difficult to get the customer to comply with a standard or template format. I have looked at PowerShell and Iron Python to do this so far but I am not sure this is the route I want to go. I have also looked at some tools such as Talend which is a drag and drop style tool which may or may not give me what I want as far as flexibility. We are a .NET shop and have created custom code to do this in the past but I need something that is quicker to create then coding custom parsing functions each time we get a new file format in.
Depending on the complexity and variability of your work, you should consider an ETL tool like SSIS (SQL Server Integration Services).
Python is wonderful for this kind of thing. That's why we use. Each new customer transfer is a new adventure and Python gives us the flexibility to respond quickly.
Edit. All python scripts that read files are "custom file parsers". Without an actual example, it's not sensible to provide a detailed example.
with open( "some file", "r" ) as source:
for line in source:
process( line )
That's about all there is to a "custom file parser". If you're parsing .csv or .xml files, then Python has modules for that. If you're parsing fixed-format files, you'd use string slicing operations. If you're parsing other files (X12? JSON? YAML?) you'll need appropriate parsers.
Tab-Delim.
from collections import namedtuple
RecordLayout = namedtuple('RecordLayout',['field1','field2','field3',...])
def process( aLine ):
record = RecordLayout( aLine.split('\t') )
...
Fixed Layout.
from collections import namedtuple
RecordLayout = namedtuple('RecordLayout',['field1','field2','field3',...])
def process( aLine ):
fields = ( aLine[:10], aLine[10:20], aLine[20:30], ... )
record = RecordLayout( fields )
...