"Fossies" - the Fresh Open Source Software Archive

Member "PDFlib-Lite-7.0.5p3/bind/pdflib/perl/starter_pdfmerge.pl" (6 Jun 2012, 2095 Bytes) of package /linux/misc/old/PDFlib-Lite-7.0.5p3.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Perl source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "starter_pdfmerge.pl" see the Fossies "Dox" file reference documentation.

    1 #!/usr/bin/perl
    2 # $Id: starter_pdfmerge.pl,v 1.2.2.2 2008/12/25 13:28:41 rp Exp $
    3 #
    4 # PDF merge starter:
    5 # Merge pages from multiple PDF documents; interactive elements (e.g. 
    6 # bookmarks) will be dropped.
    7 #
    8 # required software: PDFlib+PDI/PPS 7
    9 # required data: PDF documents
   10 
   11 use pdflib_pl 7.0;
   12 
   13 # This is where the data files are. Adjust as necessary.
   14 $searchpath = "../data";
   15 $outfilename = "starter_pdfmerge.pdf";
   16 
   17 @pdffiles = (
   18     "PDFlib-real-world.pdf",
   19     "PDFlib-datasheet.pdf",
   20     "TET-datasheet.pdf",
   21     "PLOP-datasheet.pdf",
   22     "pCOS-datasheet.pdf"
   23 );
   24 
   25 $p = PDF_new();
   26 
   27 eval {
   28     # This means we must check return values of load_font() etc.
   29     PDF_set_parameter($p, "errorpolicy", "return");
   30 
   31     PDF_set_parameter($p, "SearchPath", $searchpath);
   32 
   33     if (PDF_begin_document($p, $outfilename, "") == -1) {
   34     die("Error: " . PDF_get_errmsg($p));
   35     }
   36 
   37     PDF_set_info($p, "Creator", "PDFlib starter sample");
   38     PDF_set_info($p, "Title", "starter_pdfmerge");
   39 
   40     foreach $pdffile (@pdffiles) { 
   41     # Open the input PDF
   42     $indoc = PDF_open_pdi_document($p, $pdffile, "");
   43     if ($indoc == -1) {
   44         printf("Error: %s\n", PDF_get_errmsg($p));
   45         next;
   46     }
   47 
   48     $endpage = PDF_pcos_get_number($p, $indoc, "/Root/Pages/Count");
   49 
   50     # Loop over all pages of the input document
   51     for ($pageno = 1; $pageno <= $endpage; $pageno++) {
   52         $page = PDF_open_pdi_page($p, $indoc, $pageno, "");
   53 
   54         if ($page == -1) {
   55         printf("Error: %s\n", PDF_get_errmsg($p));
   56         next;
   57         }
   58         # Dummy $page size; will be adjusted later
   59         PDF_begin_page_ext($p, 10, 10, "");
   60 
   61         # Create a bookmark with the file name
   62         if ($pageno == 1) {
   63         PDF_create_bookmark($p, $pdffile, "");
   64         }
   65 
   66         # Place the imported $page on the output $page, and
   67         # adjust the $page size
   68         
   69         PDF_fit_pdi_page($p, $page, 0, 0, "adjustpage");
   70         PDF_close_pdi_page($p, $page);
   71 
   72         PDF_end_page_ext($p, "");
   73     }
   74     PDF_close_pdi_document($p, $indoc);
   75     }
   76 
   77     PDF_end_document($p, "");
   78 
   79     PDF_delete($p);
   80 };
   81 
   82 if ($@) {
   83     printf("starter_pdfmerge: PDFlib Exception occurred:\n");
   84     printf(" $@\n");
   85     exit;
   86 }