Perl Pdf Create

Perl Pdf Create

Perl programmer for hire: download my resume (PDF).

Being able to generate PDF’s for reports and documents allow for a bevy of automation shortcuts where traditional Data Merging, or “variable imaging,” would be impractical and at times impossible to integrate into existing e-commerce or ERP platforms. To run this code on your own computer, you will need to download a Perl interpreter. Posted on 2010-07-22 09:35-07 by kodo Hi, now forgive me for being new, I have PDF-Create working just wonderfully, but I cannot find an example of an image being added to a pdf anywhere, and I've search all day.

“Using Perl 6” is a work-in-progress. Perl 6 is versatile, intuitive, and flexible. It embraces several paradigms like procedural, object oriented, and functional programming, and offers powerful tools for parsing text. Perl 6 is the newest member of the family of languages known as Perl.

Earlier this month I downloaded several episodes of the comic 'Suske en Wiske' (Spike and Suzy), as cbr files. I own the original dead tree copies, but they are still in the Netherlands, and I own too many to ask my mom to take them with her when she visits us. Besides, we're running out of storage space in our little apartment.

A cbr file is a collection of image files, scans of the actual comic book pages, archived using the RAR format, hence the last letter. And cb stands for comic book. I already read two 'Suske en Wiske' comic books during our short vacation in Puerto Escondido earlier this month using 'XnView Pocket' on my PDA, a Dell Axim X51v, by opening each image file (JPEG). But reading using XnView was not an easy task.

Just before we left I considered creating a PDF file with one page (JPEG) per page, and use PocketXpdf to read it. But there was no time left to code a small Perl solution to achieve this.

And tonight I had some spare time, and decided to give it a try. Below follows a simple Perl program that reads all JPEG images from a directory named 'test' and creates a PDF file 'test.pdf' with one image per page.

The dimension in pixels of each page is taken from the dimension of each JPEG image. Next, the image object is added to the left top of each page. The image files are read and added sorted in standard string comparison order, the default of the sort function.

The above Perl code is a simple example. Extending this example and adding additional error handling is left as an excercise to the reader. I might soon post a Perl program that has more functionality, but this example is already a good start to code your own solution.

As for now being able to read comic books on my Dell Axim using PocketXpdf, no such luck yet. Maybe PocketXpdf needs too much memory in order to display the comic. I will test later with a smaller pdf file. If that works, I just create for each comic book several pdf files, each file containing several pages of the book.

Perl and PDF related

Also today

  • Some Perl hacking (overview)
Please post a comment | read 2 comments, latest by Ray | RSS feed
  • METHODS
  • LIMITATIONS

PDF::Create - Create PDF files.

Version 1.46

PDF::Create allows you to create PDF document using a number of primitives.The result is as a PDF file or stream. PDF stands for Portable Document Format.

Documents can have several pages, a table of content, an information section and many other PDF elements.

PDF::Create provides an easy module to create PDF output from your perl script. It is designed to be easy to use and simple to install and maintain. It provides a couple of subroutines to handle text, fonts, images and drawing primitives. Simple documents are easy to create with the supplied routines.

In addition to be reasonable simple PDF::Create is written in pure Perl and has no external dependencies (libraries, other modules, etc.). It should run on any platform where perl is available.

For complex stuff some understanding of the underlying Postscript/PDF format is necessary. In this case it might be better go with the more complete PDF::API2 modules to gain more features at the expense of a steeper learning curve.

Example PDF creation with PDF::Create (see PDF::Create::Page for details of methods available on a page):

The method new(%params) create a new pdf structure for your PDF. It returns an object handle which can be used to add more stuff to the PDF. The parameter keys to the constructor are detailed as below:

Example:

If you are writing a CGI you can send your PDF on the fly to stdout / directly to the browser using '-' as filename.

CGI Example:

new_page(%params)

Add a page to the document using the given parameters. new_page must be called first to initialize a root page, used as model for further pages.Returns a handle to the newly created page. Parameters can be:

Example:

font(%params)

Prepare a font using the given arguments. This font will be added to the document only if it is used at least once before the close method is called.Parameters are listed below:

The ZapfDingbats font is not supported in this version.Default font is Helvetica.

new_outline(%params)

Adds an outline to the document using the given parameters. Return the newly created outline. Parameters can be:

Example:

get_page_size($name)

Returns the size of standard paper used for MediaBox-parameter of new_page. get_page_size has one optional parameter to specify the paper name. Possible values are a0-a6, a4l,letter,broadsheet,ledger,tabloid,legal,executive and 36x36. Default is a4.

version($number)

Set and return version number. Valid version numbers are 1.0, 1.1, 1.2 and 1.3.

close(%params)

Close does the work of creating the PDF data from the objects collected before. You must call close() after you have added all the contents as most of the real work building the PDF is performed there. If omit calling close you get no PDF output. Returns the raw content of the PDF. If fh was provided when creating object of PDF::Create then it does not try to close the file handle. It is, therefore, advised you call flush() rather than close().

flush()

Generate the PDF content and returns the raw content as it is.

reserve($name, $type)

Reserve the next object number for the given object type.

add_comment($message)

Add comment to the document.The string will show up in the PDF as postscript-style comment:

annotation(%params)

Adds an annotation object, for the time being we only do the 'Link' - 'URI' kind This is a sensitive area in the PDF document where text annotations are shown or links launched. PDF::Create only supports URI links at this time.

URI links have two components,the text or graphics object and the area where the mouseclick should occur.

For the object to be clicked on you'll use standard text of drawing methods. To define the click-sensitive area and the destination URI.

Example:

The point (x, y) is the bottom left corner of the rectangle containing hotspot rectangle, (w, h) are the width and height of the hotspot rectangle. The Border describes the thickness of the border surrounding the rectangle hotspot.

The function string_underline returns the width of the string, this can be used directly for the width of the hotspot rectangle.

image($filename)

Prepare an XObject (image) using the given arguments. This image will be added to the document if it is referenced at least once before the close method is called. In this version GIF,interlaced GIF and JPEG is supported. Usage of interlaced GIFs are slower because they are decompressed, modified and compressed again. The gif support is limited to images with a LZW minimum code size of 8. Small images with few colors can have a smaller minimum code size and will not work. If you get errors regarding JPEG compression, then the compression method used in your JPEG file is not supported by PDF::Image::JPEG. Try resaving the JPEG file with different compression options (for example, disable progressive compression).

Example:

get_data()

If you did not ask the $pdf object to write its output to a file, you can pick up the pdf code by calling this method. It returns a big string. You need to call close first.

PDF::Create comes with a couple of limitations or known caveats:

PDF Size / Memory

Unless using a filehandle, PDF::Create assembles the entire PDF in memory. If you create very large documents on a machine with a small amount of memory your program can fail because it runs out of memory. If using a filehandle, data will be written immediately to the filehandle after each method.

Small GIF images

Some gif images get created with a minimal lzw code size of less than 8. PDF::Create can not decode those and they must be converted.

I support PDF::Create in my spare time between work and family, so the amount of work I put in is limited.

If you experience a problem make sure you are at the latest version first many of things have already been fixed.

Perl pdf create rectangle

Please register bug at the CPAN bug tracking system at http://rt.cpan.org or send email to bug-PDF-Create [at] rt.cpan.org

Be sure to include the following information:

- PDF::Create Version you are running
- Perl version (perl -v)
- Operating System vendor and version
- Details about your operating environment that might be related to the issue being described
- Exact cut and pasted error or warning messages
- The shortest, clearest code you can manage to write which reproduces the bug described.

I appreciate patches against the latest released version of PDF::Create which fix the bug.

Feature request can be submitted like bugs. If you provide patch for a feature which does not go against the PDF::Create philosophy (keep it simple) then you have a good chance for it to be accepted.

PDF::Labels Routines to produce formatted pages of mailing labels in PDF, uses PDF::Create internally.

PDF::Haru Perl interface to Haru Free PDF Library.

PDF::EasyPDF PDF creation from a one-file module, similar to PDF::Create.

PDF::CreateSimple Yet another PDF creation module

PDF::Report A wrapper written for PDF::API2.

Fabien Tassin

Perl Pdf Create Rectangle

GIF and JPEG-support: Michael Gross (info@mdgrosse.net)

Maintenance since 2007: Markus Baertschi (markus@markus.org)

Perl Pdf::create

Currently maintained by Mohammad S Anwar (MANWAR) <mohammad.anwar at yahoo.com>

Perl Create Pdf From Html

Copyright 1999-2001,Fabien Tassin.All rights reserved.It may be used and modified freely, but I do request that this copyright notice remain attached to the file. You may modify this module as you wish,but if you redistribute a modified version , please attach a note listing the modifications you have made.

Perl Pdf Create

Copyright 2007 Markus Baertschi

Perl Create Pdf

Copyright 2010 Gary Lieberman

Perl Pdf Reader

This is free software; you can redistribute it and / or modify it under the same terms as Perl 5.6.0.