2.9  PHP Binding g 31
2.8.2The »Hello world« Example in Perl
use pdflib_pl 5.0.2;
$p = PDF_new();
eval {
if (PDF_open_file($p, "hello.pdf") == -1) {
printf("Error: %s\n", PDF_get_errmsg($p));
exit;
}
PDF_set_info($p, "Creator", "hello.pl");
PDF_set_info($p, "Author", "Thomas Merz");
PDF_set_info($p, "Title", "Hello world (Perl)");
PDF_begin_page($p, 595, 842);
$font = PDF_load_font($p, "Helvetica-Bold", "host", "");
PDF_setfont($p, $font, 18.0);
PDF_set_text_pos($p, 50, 700);
PDF_show($p, "Hello world!");
PDF_continue_text($p, "(says Perl)");
PDF_end_page($p);
PDF_close($p);
};
if ($@) {
printf("hello: PDFlib Exception occurred:\n");
printf(" $@\n");
exit;
}
PDF_delete($p);
2.8.3Error Handling in Perl
The Perl binding installs a special error handler which translates PDFlib errors to native 
Perl exceptions. The Perl exceptions can be dealt with by applying the appropriate lan-
guage constructs, i.e., by bracketing critical sections:
eval {
...some PDFlib instructions...
};
die "Exception caught" if $@;
2.9PHP Binding
2.9.1Installing the PDFlib PHP Edition
Detailed information about the various flavors and options for using PDFlib with PHP
1
including the question of whether or not to use a loadable PDFlib module for PHP, can 
be found in the readme.txt file which is part of the PDFlib distribution.
1. See http://www.php.net 
Converting pdf to tiff format - Convert PDF to tiff images in C#.net, ASP.NET MVC, Ajax, WinForms, WPF
Online C# Tutorial for How to Convert PDF File to Tiff Image File
convert pdf to tiff online; file conversion pdf to tiff
Converting pdf to tiff format - VB.NET PDF Convert to Tiff SDK: Convert PDF to tiff images in vb.net, ASP.NET MVC, Ajax, WinForms, WPF
Free VB.NET Guide to Render and Convert PDF Document to TIFF
pdf to tiff batch conversion; pdf to tiff converter for
32
Chapter 2:  PDFlib Language Bindings
Note We do not recommend using the PDFlib COM edition with PHP. Use the native PDFlib binding 
for PHP instead.
You must configure PHP so that it knows about the external PDFlib library. You have 
two choices:
>Add one of the following lines in php.ini:
extension=libpdf_php.so
; for Unix
extension=libpdf_php.dylib
; for Mac OS X
extension=libpdf_php.dll
; for Windows
PHP will search the library in the directory specified in the extension_dir variable in 
php.ini on Unix, and in the standard system directories on Windows. You can test 
which version of the PHP PDFlib binding you have installed with the following one-
line PHP script:
<?phpinfo()?>
This will display a long info page about your current PHP configuration. On this page 
check the section titled pdf. If this section contains PDFlib GmbH Version (and the 
PDFlib version number) you are using the supported new PDFlib wrapper. The un-
supported old wrapper will display PDFlib Version instead.
>Load PDFlib at runtime with one of the following lines at the start of your script:
dl("libpdf_php.so");
# for Unix
dl("libpdf_php.dll");
# for Windows
Modified error return for PDFlib functions in PHP. Since PHP uses the convention of re-
turning the value 0 (FALSE) when an error occurs within a function, all PDFlib functions 
have been adjusted to return 0 instead of -1 in case of an error. This difference is noted 
in the function descriptions in Section 7, »API Reference for PDFlib, PDI, and PPS«, page 
143. However, take care when reading the code fragment examples in Section 3, »PDFlib 
Programming«, page 41 since these use the usual PDFlib convention of returning -1 in 
case of an error.
File name handling in PHP. Unqualified file names (without any path component) and 
relative file names for PDF, image, font and other disk files are handled differently in 
Unix and Windows versions of PHP:
>PHP on Unix systems will find files without any path component in the directory 
where the script is located.
>PHP on Windows will find files without any path component only in the directory 
where the PHP DLL is located.
In order to provide platform-independent file name handling use of PDFlib’s Search-
Path facility (see Section 3.1.6, »Resource Configuration and File Searching«, page 47) is 
strongly recommended.
2.9.2The »Hello world« Example in PHP
<?php
$p = PDF_new();
/*  open new PDF file; insert a file name to create the PDF on disk */
if (PDF_open_file($p, "") == 0) {
die("Error: " . PDF_get_errmsg($p));
VB.NET Image: Tutorial for Converting Image and Document in VB.NET
than thirty image and document formats, including PDF, TIFF, GIF, BMP SDK to convert image, image format and its there comes a need of converting image from one
how to convert pdf file to tiff; pdf to tiff multipage
VB.NET TIFF: TIFF Converter Control SDK; Convert TIFF to Image &
TIFF to PDF conversion without using external PDF document processing VB.NE TIFF to JPEG Converting Plugin, VB.NE conversion SDK is able to convert TIFF file to
compare pdf to tiff; how to save pdf to tiff
2.10  Python Binding g 33
}
PDF_set_info($p, "Creator", "hello.php");
PDF_set_info($p, "Author", "Rainer Schaaf");
PDF_set_info($p, "Title", "Hello world (PHP)");
PDF_begin_page($p, 595, 842); /* start a new page     */
# Change "host" encoding to "winansi" or whatever you need!
$font = PDF_load_font($p, "Helvetica-Bold", "host", "");
PDF_setfont($p, $font, 24.0);
PDF_set_text_pos($p, 50, 700);
PDF_show($p, "Hello world!");
PDF_continue_text($p, "(says PHP)");
PDF_end_page($p);
/* close page*/
PDF_close($p);
/* close PDF document*/
$buf = PDF_get_buffer($p);
$len = strlen($buf);
header("Content-type: application/pdf");
header("Content-Length: $len");
header("Content-Disposition: inline; filename=hello.pdf");
print $buf;
PDF_delete($p);
/* delete the PDFlib object */
?>
2.9.3Error Handling in PHP
When a PDFlib exception occurs, a PHP exception is thrown. Unfortunately, PHP does 
not yet support structured exception handling: there is no way to catch exceptions and 
act appropriately. Do not disable PHP exceptions when using PDFlib, or you will run 
into serious trouble.
PDFlib warnings (nonfatal errors) are mapped to PHP warnings, which can be dis-
abled in php.ini. Alternatively, warnings can be disabled at runtime with a PDFlib func-
tion like in any other language binding:
PDF_set_parameter($p, "warning", "false");
2.10Python Binding
2.10.1Installing the PDFlib Python Edition
The Python
1
extension mechanism works by loading shared libraries at runtime. For the 
PDFlib binding to work, the Python interpreter must have access to the PDFlib Python 
wrapper:
Unix. The library pdflib_py.so (on Mac OS X: pdflib_py.dylib) will be searched in the direc-
tories listed in the PYTHONPATH environment variable.
1. See http://www.python.org 
C# PDF Convert to Images SDK: Convert PDF to png, gif images in C#
PDF to multiple image forms, including Jpg, Png, Bmp, Gif, Tiff, Bitmap, .NET C#.NET DLLs Solution for Converting Images to PDF in C# using RasterEdge.XDoc.PDF;
.net convert pdf to tiff; pdf to tiff conversion c#
C# PDF Convert to SVG SDK: Convert PDF to SVG files in C#.net, ASP
Support converting PDF document to SVG image within C#.NET project some situations, it is quite necessary to convert PDF document into SVG image format.
program to automatically convert pdf to tiff; pdf to tiff c#
34
Chapter 2:  PDFlib Language Bindings
Windows. The library pdflib_py.dll will be searched in the directories listed in the 
PYTHONPATH environment variable.
2.10.2The »Hello world« Example in Python
from sys import *
from pdflib_py import *
p = PDF_new()
if PDF_open_file(p, "hello.pdf") == -1:
print "Error: " + PDF_get_errmsg(p) + "\n"
exit(2);
PDF_set_info(p, "Author", "Thomas Merz")
PDF_set_info(p, "Creator", "hello.py")
PDF_set_info(p, "Title", "Hello world (Python)")
PDF_begin_page(p, 595, 842)
font = PDF_load_font(p, "Helvetica-Bold", "host", "")
PDF_setfont(p, font, 18.0)
PDF_set_text_pos(p, 50, 700)
PDF_show(p, "Hello world!")
PDF_continue_text(p, "(says Python)")
PDF_end_page(p)
PDF_close(p)
PDF_delete(p);
2.10.3Error Handling in Python
The Python binding installs a special error handler which translates PDFlib errors to na-
tive Python exceptions. The Python exceptions can be dealt with by the usual try/catch 
technique:
try:
...some PDFlib instructions...
except:
print 'Exception caught!'
2.11RPG Binding
PDFlib provides a /copy module that defines all prototypes and some useful constants 
needed to compile ILE-RPG programs with embedded PDFlib functions.
Since all functions provided by PDFlib are implemented in the C language, you have 
to add x'00' at the end of each string value passed to a PDFlib function. All strings re-
turned from PDFlib will have this terminating x'00' as well.
2.11.1Compiling and Binding RPG Programs for PDFlib
Using PDFlib functions from RPG requires the compiled PDFlib service program. To in-
clude the PDFlib definitions at compile time you have to specify the name in the D 
specs of your ILE-RPG program:
C# Raster - Raster Conversion & Rendering in C#.NET
This image converting library component offers reliable C#.NET image from image or document, like multi-page TIFF file page is a guide of ico format and offers
pdf to tiff c# open source; pdf to tiff converter online
VB.NET TIFF: How to Convert TIFF to PDF in a VB.NET Doc Imaging
Function Private Sub New(imagesource As List(Of REImage)) End Sub ' API for converting TIFF file to PDF Private Sub Convert(s As Stream, format As ImageFormat
pdf to tiff converters; pdf to tiff file conversion
2.11  RPG Binding g 35
d/copy QRPGLESRC,PDFLIB
If the PDFlib source file library is not on top of your library list you have to specify the li-
brary as well:
d/copy PDFsrclib/QRPGLESRC,PDFLIB
Before you start compiling your ILE-RPG program you have to create a binding directory 
that includes the PDFLIB service program shipped with PDFlib. The following example 
assumes that you want to create a binding directory called PDFLIB in the library PDFLIB:
CRTBNDDIR BNDDIR(PDFLIB/PDFLIB) TEXT('PDFlib Binding Directory')
After creating the binding directory you need to add the PDFLIB service program to your 
binding directory. The following example assumes that you want to add the service pro-
gram PDFLIB in the library PDFLIB to the binding directory created earlier.
ADDBNDDIRE BNDDIR(PDFLIB/PDFLIB) OBJ((PDFLIB/PDFLIB *SRVPGM))
Now you can compile your program using the CRTBNDRPG command (or option 14 in 
PDM):
CRTBNDRPG PGM(PDFLIB/HELLO) SRCFILE(PDFLIB/QRPGLESRC) SRCMBR(*PGM) DFTACTGRP(*NO)  
BNDDIR(PDFLIB/PDFLIB)
2.11.2The »Hello world« Example in RPG
*****************************************************************************************
d/copy QRPGLESRC,PDFLIB
*****************************************************************************************
d p               S               *
d font            s             10i 0
*
d error           s             50
d errmsg_p        s               *
d errmsg          s            200    based(errmsg_p)
*
d filename        s            256
d fontname        s             50
d fontenc         s             50
d infokey         s             50
d infoval         s            200
d text            s            200
d n               s              1    inz(x'00')
*****************************************************************************************
                  clear                   error
*
   Init on PDFlib
                  eval      p=pdf_new
                  if        p=*null
                  eval      error='Couldn''t create PDFlib object '+
                                  '(out of memory)!'
                  exsr      exit
                  endif
*
   Open new pdf file
                  eval      filename='hello.pdf'+x'00'
Convert Image & Documents Formats in Web Viewer| Online Tutorials
page provides detailed information for converting images or Barcodes from Your Documents. Multi-page Tiff Processing; RasterEdge OCR Engine; PDF Reading; Encode
pdf converter to tiff online; save pdf to tiff
VB.NET Word: VB Tutorial to Convert Word to Other Formats in .NET
VB.NET code, RasterEdge VB.NET Word to TIFF converter control to customize the VB.NET Word converting application by How to Convert & Render Word to PDF in VB
how to convert pdf into tiff file; converting pdf to tiff file
36
Chapter 2:  PDFlib Language Bindings
                  if        PDF_open_file(p:filename) = -1
                  exsr      geterrmsg
                  exsr      exit
                  endif
   Set info "Creator"
                  eval      infokey='Creator'+x'00'
                  eval      infoval='hello.rpg'+x'00'
                  callp     PDF_set_info(p:infokey:infoval)
   Set info "Author"
                  eval      infokey='Author'+x'00'
                  eval      infoval='Thomas Merz'+x'00'
                  callp     PDF_set_info(p:infokey:infoval)
   Set info "Title"
                  eval      infokey='Title'+x'00'
                  eval      infoval='Hello, world (RPG)!'+x'00'
                  callp     PDF_set_info(p:infokey:infoval)
   Start a new page
                  callp     PDF_begin_page(p:a4_width:a4_height)
*
                  eval      fontname='Helvetica-Bold'+x'00'
   Change "host" encoding to "ebcdic" or whatever you need!
                  eval      fontenc='host'+x'00'
                  eval      font=PDF_load_font(p:fontname:0:fontenc:n)
*
                  callp     PDF_setfont(p:font:24)
                  callp     PDF_set_text_pos(p:50:700)
*
                  eval      text='Hello world!'+x'00'
                  callp     PDF_show(p:text)
                  eval      text='(says ILE RPG)'+x'00'
                  callp     PDF_continue_text(p:text)
   Close page
                  callp     PDF_end_page(p)
   Close PDF document
                  callp     PDF_close(p)
   Delete the PDF object
                  callp     PDF_delete(p)
*
                  exsr      exit
*****************************************************************************************
    geterrmsg     begsr
                  eval      errmsg_p=PDF_get_errmsg(p)
                  if        errmsg_p<>*NULL
                  eval      error=%subst(errmsg:1:%scan(x'00':errmsg)-1)
                  endif
                  endsr
*****************************************************************************************
    exit          begsr
                  if        error<>*blanks
                  eval      error='Error: '+error
    error         dsply
                  endif
                  seton                                        lr
                  return
                  endsr
You can compile this program as follows:
2.11  RPG Binding g 37
CRTBNDDIR BNDDIR(PDFLIB/PDFLIB) TEXT('PDFlib Binding Directory')
ADDBNDDIRE BNDDIR(PDFLIB/PDFLIB) OBJ((PDFLIB/PDFLIB *SRVPGM))
CRTBNDRPG PGM(PDFLIB/HELLO) SRCFILE(PDFLIB/QRPGLESRC) SRCMBR(*PGM) DFTACTGRP(*NO) +
BNDDIR(PDFLIB/PDFLIB)
2.11.3Error Handling in RPG
PDFlib clients written in ILE-RPG can install an error handler in PDFlib which will be ac-
tivated when an exception occurs. Since ILE-RPG translates all procedure names to up-
percase, the name of the error handler procedure should be specified in uppercase. The 
following skeleton demonstrates this technique:
*****************************************************************************************
d/copy QRPGLESRC,PDFLIB
*****************************************************************************************
d p               S               *
d font            s             10i 0
*
d error           s             50
*
d errhdl          s               *   procptr
*
 Prototype for exception handling procedure
*
d errhandler      PR
 p                              *   value
 type                         10i 0 value
 shortmsg                   2048
*****************************************************************************************
                  clear                   error
*
       Set the procedure pointer to the ERRHANDLER procedure.
*
                  eval      errhdl=%paddr('ERRHANDLER')
*
                  eval      p=pdf_new2(errhdl:*null:*null:*null:*null)
...PDFlib instructions...
                  callp     PDF_delete(p)
*
                  exsr      exit
*****************************************************************************************
    exit          begsr
                  if        error<>*blanks
    error         dsply
                  endif
                  seton                                        lr
                  return
                  endsr
*****************************************************************************************
 If any of the PDFlib functions will cause an exception, first the error handler
 will be called and after that we will get a regular RPG exception.
    *pssr         begsr
                  exsr      exit
                  endsr
*****************************************************************************************
 Exception Handler Procedure
38
Chapter 2:  PDFlib Language Bindings
 This procedure will be linked to PDFlib by passing the procedure pointer to
 PDF_new2. This procedure will be called when a PDFlib exception occurs.
*
*****************************************************************************************
p errhandler      B
d errhandler      PI
 p                              *   value
 type                         10i 0 value
 c_message                  2048
*
 length         s             10i 0
*
   Chop off the trailing x'00' (we are called by a C program)
   and set the error (global) string
                  clear                   error
    x'00'         scan      c_message     length                   50
                  sub       1             length
                  if        *in50 and length>0
                  if        length>%size(error)
                  eval      error=c_message
                  else
                  eval      error=%subst(c_message:1:length)
                  endif
                  endif
*
   Always call PDF_delete to clean up PDFlib
                  callp     PDF_delete(p)
*
                  return
*
p errhandler      E
2.12Tcl Binding
2.12.1Installing the PDFlib Tcl Edition
The Tcl 
1
extension mechanism works by loading shared libraries at runtime. For the 
PDFlib binding to work, the Tcl shell must have access to the PDFlib Tcl wrapper shared 
library and the package index file pkgIndex.tcl. You can use the following idiom in your 
script to make the library available from a certain directory (this may be useful if you 
want to deploy PDFlib on a machine where you don’t have root privilege for installing 
PDFlib):
lappend auto_path /path/to/pdflib
Unix. The library pdflib_tcl.so (on Mac OS X: pdflib_tcl.dylib) must be placed in one of 
the default locations for shared libraries, or in an appropriately configured directory. 
Usually both pkgIndex.tcl and pdflib_tcl.so will be placed in the directory
/usr/lib/tcl8.3/pdflib
Windows. The files pkgIndex.tcl and pdflib_tcl.dll will be searched for in the directories
1. See http://dev.scriptics.com 
2.12  Tcl Binding g 39
C:\Program Files\Tcl\lib\pdflib
C:\Program Files\Tcl\lib\tcl8.3\pdflib
2.12.2The »Hello world« Example in Tcl
package require pdflib 5.0.2
set p [PDF_new]
if {[PDF_open_file $p "hello.pdf"] == -1} {
puts stderr "Error:  [PDF_get_errmsg $p]"
exit
}
PDF_set_info $p "Creator" "hello.tcl"
PDF_set_info $p "Author" "Thomas Merz"
PDF_set_info $p "Title" "Hello world (Tcl)"
PDF_begin_page $p 595 842
set font [PDF_load_font $p "Helvetica-Bold" "host" "" ]
PDF_setfont $p $font 18.0
PDF_set_text_pos $p 50 700
PDF_show $p "Hello world!"
PDF_continue_text $p "(says Tcl)"
PDF_end_page $p
PDF_close $p
PDF_delete $p
2.12.3Error Handling in Tcl
The Tcl binding installs a special error handler which translates PDFlib errors to native 
Tcl exceptions. The Tcl exceptions can be dealt with by the usual try/catch technique:
if [ catch { ...some PDFlib instructions... } result ] {
puts stderr "Exception caught!"
puts stderr $result
}
40
Chapter 2:  PDFlib Language Bindings
Documents you may be interested
Documents you may be interested