Current location: Hot Scripts Forums » Programming Languages » PHP » PDF Generation using PDFLIB


PDF Generation using PDFLIB

Reply
  #1 (permalink)  
Old 11-29-06, 01:17 AM
raji20 raji20 is offline
Newbie Coder
 
Join Date: Aug 2006
Posts: 41
Thanks: 0
Thanked 0 Times in 0 Posts
PDF Generation using PDFLIB IN PHP

Hello Guys,

Im using pdflib for generating pdf, It is working fine, when I used a single page pdf as the template, but when I use a pdf with two pages I dont know how to write in first page and second page

$page = PDF_open_pdi_page($p, $blockcontainer, 2, ""); // I have set the pdf points to second page

Here in the above line, I have set the pdf to write in second page, but I dont know how to write in first page of the pdf.

here is the code that I have used to generate pdf.

Can anyone help me to sort out this issue.

Thanks in Advance.

PHP Code:

<?php

$infile 
"Template.pdf";

$searchpath "./data";

$p PDF_new();

/*  open new PDF file; insert a file name to create the PDF on disk */
if (PDF_begin_document($p"""") == 0) {
    die(
"Error1: " PDF_get_errmsg($p));
}

/* Set the search path for fonts and PDF files */
PDF_set_parameter($p"SearchPath"$searchpath);

/* This line is required to avoid problems on Japanese systems */
PDF_set_parameter($p"hypertextencoding""winansi");

    
PDF_set_info($p'Creator''PDF Builder using PDFlib');
    
PDF_set_info($p'Author''Author Name');
PDF_set_info($p"Title""Card Title");

$blockcontainer PDF_open_pdi($p$infile""0);
if (
$blockcontainer == 0){
    die (
"Error2: " PDF_get_errmsg($p));
}

$page PDF_open_pdi_page($p$blockcontainer2"");   // I have set the pdf points to second page
if ($page == 0){
    die (
"Error3: " PDF_get_errmsg($p));
}

PDF_begin_page_ext($p600600"");        /* dummy page size */

/* This will adjust the page size to the block container's size. */
PDF_fit_pdi_page($p$page00"adjustpage");


//Load the fonts to be used
 // FuturaHeavy
 
PDF_set_parameter($p'FontOutline''FuturaHeavy=lte50188.ttf' );
 
$font PDF_load_font($p'FuturaHeavy''winansi''embedding');
 
// FuturaHeavy PostScript Font
 
PDF_set_parameter($p'FontPFM''FuturaLtBt=0138A___.PFM' );//NOTE - you have to use 'FontPFM' for the FontMetrics of PS font in place of FontOutline as for TT fonts
 
PDF_set_parameter($p'FontOutline''FuturaLtBt=0138A___.PFB' );//NOTE - you have to use 'FontOutline' for PS font FontOutline in addition to the above
 
$font PDF_load_font($p'FuturaLtBt''winansi''embedding'); 
 
PDF_set_parameter($p"charref""true");// allows &nbsp etc

 
//Do colour
//$spot = PDF_makespotcolor($p, "PANTONE 341 U", 0);
//PDF_setcolor($p, "both", $spot, 0.7, 0, 0);

//Create the name
$text="<leading=100% charspacing=0.35 fontname=FuturaLtBt fontsize=5 encoding=winansi>Name\r\n";
$text.="<leading=250% charspacing=0.95 fontname=FuturaLtBt fontsize=5 encoding=winansi>email@email.com\r\n";
$text.="<leading=290% charspacing=0.35 fontname=FuturaLtBt fontsize=5 encoding=winansi>000 0000 0000\r\n";
$text.="<leading=140% charspacing=0.35 fontname=FuturaLtBt fontsize=5 encoding=winansi>000 0000 0000\r\n";
$text.="<leading=143% charspacing=0.35 fontname=FuturaLtBt fontsize=5 encoding=winansi>000 0000 0000\r\n";
$text.="<leading=409% charspacing=0.35 fontname=FuturaLtBt fontsize=5 encoding=winansi>Address Address \r\n";
$text.="<leading=139% charspacing=0.35 fontname=FuturaLtBt fontsize=5 encoding=winansi>POSTCODE1WL\r\n";


$textbox PDF_create_textflow($p$text"fillcolor={ spotname {PANTONE 341 U} 1 } alignment=left leading=170% charspacing=1 fontname=FuturaHeavy fontsize=9 encoding=winansi") or die ("PDF Error=" PDF_get_errmsg($p));

$left_x=114.175;
$left_y=6.175;            //    
$right_x=227.05515;        // Horizontal moving towards right
$right_y=128.13203;        // moving the box top vertically
$offset 0;

//"fillcolor={rgb 1 0 0}"
$result PDF_fit_textflow($p$textbox$left_x$left_y$right_x$right_y"verticalalign=top showborder=false") or die ("PDF Error=" PDF_get_errmsg($p));



if (
strcmp($result"_stop"))  {
    die (
"Error: result=" $result " PDF Error=" PDF_get_errmsg($p));
}

PDF_delete_textflow($p$textbox);
$text="";


PDF_end_page_ext($p"");
PDF_close_pdi_page($p$page);

PDF_end_document($p"");
PDF_close_pdi($p$blockcontainer);

$buf PDF_get_buffer($p);
$len strlen($buf);

header("Content-type: application/pdf");
header("Content-Length: $len");
header("Content-Disposition: inline; filename=test.pdf");
print 
$buf;

PDF_delete($p);
?>

Last edited by Nico; 11-29-06 at 02:24 AM. Reason: Please use [php] wrappers when posting PHP code.
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
PDF Generation raji20 PHP 1 08-12-06 02:09 AM
Creating PDF from HTML content? Alfarin PHP 0 07-24-06 06:48 AM
Searching inside pdf sk8ar PHP 1 05-03-06 05:43 AM
PDF file upload php4tric PHP 0 08-15-05 08:21 AM
pdf on the fly?? fraggle PHP 2 04-28-05 10:51 AM


All times are GMT -5. The time now is 05:46 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.