PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Sat Aug 19, 2017 2:17 am

All times are UTC - 5 hours




Post new topic Reply to topic  [ 21 posts ]  Go to page 1, 2  Next
Author Message
PostPosted: Thu Feb 03, 2005 10:18 am 
Offline
Admin
User avatar

Joined: Wed Aug 13, 2003 7:02 am
Posts: 4522
Location: York, UK
First of all, download both the following packages

http://www.fpdf.org/

http://fpdi.setasign.de/index.php?p=home


Extract both packages into the same folder.

Put the PDF you want to add text to in the same folder and call it test1.pdf

Create a new script in the same folder called demo.php and add the following code.

Syntax: [ Download ] [ Hide ]
define('FPDF_FONTPATH','font/');

require('fpdi.php');



class PDF extends fpdi

{

//Page header

function Header()

{

    //Logo

    //$this->Image('logo_pb.png',10,8,33);

    //Arial bold 15

    //$this->SetFont('Arial','B',15);

    //Move to the right

    //$this->Cell(80);

    //Title

    //$this->Cell(30,10,'Title',1,0,'C');

    //Line break

    //$this->Ln(20);

}



//Page footer

function Footer()

{

    //Position at 1.5 cm from bottom

    $this->SetY(-15);

    //Arial italic 8

    $this->SetFont('Arial','I',8);

    //Page number

    $this->Cell(0,10,'This document was downloaded at '.date("G:i T", time()).' on '.date("l F jS Y", time()).'. This document is only valid for 24 hours from this date.',0,0,'C');

}

}



$pdf= new PDF();



$pagecount = $pdf->setSourceFile("test1.pdf");





for ($i=1; $i <= $pagecount; $i++) {



        $tplidx = $pdf->ImportPage(1);



        $pdf->addPage();

        $pdf->useTemplate($tplidx,0,0,0);

}





$pdf->Output("newpdf.pdf","I");


Easy peasy...obviously there is loads more you can do with this, but this should get ya started.

Uncomment the header function and change the image name to one that exists to add images!

Mark


Last edited by JayBird on Tue Dec 20, 2005 6:13 am, edited 2 times in total.

Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 03, 2005 4:21 pm 
Offline
Jedi Mod
User avatar

Joined: Tue Dec 21, 2004 6:03 pm
Posts: 5263
Location: usrlab.com
Thats mightily cool. I might be doing client reports in PDF format after I've had a play..

Maybe..


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 04, 2005 1:50 am 
Offline
DevNet Resident
User avatar

Joined: Fri Dec 24, 2004 3:59 am
Posts: 1452
Location: Lucknow, UP, India
Plz Tell me how I can insert SVG graphics into PDF using any of the PDF lib available out there.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Feb 05, 2005 7:06 am 
Offline
DevNet Resident
User avatar

Joined: Fri Dec 24, 2004 3:59 am
Posts: 1452
Location: Lucknow, UP, India
Plz reply somebody. :( Hey Feyd , can't you throw some light on this matter.
plz. i want to able to insert svg into pdf. anyhow...

thanx in advance...


Top
 Profile  
 
 Post subject:
PostPosted: Sat Feb 05, 2005 8:10 am 
Offline
Forum Donator

Joined: Mon Oct 20, 2003 8:31 pm
Posts: 1661
Location: Maine, USA
Have you tried searching? Probably not..


Top
 Profile  
 
 Post subject:
PostPosted: Sat Feb 05, 2005 8:14 am 
Offline
Neighborhood Spidermoddy
User avatar

Joined: Mon Mar 29, 2004 4:24 pm
Posts: 31559
Location: Bothell, Washington, USA
in all probability, you will need to convert the SVG to a supported image format, PNG or JPEG.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 07, 2005 12:16 am 
Offline
Forum Contributor
User avatar

Joined: Mon Jun 14, 2004 10:39 am
Posts: 259
Location: Amerika
you could probably spoof the server into believing the SVG is a PNG and if all goes well the server will gladly display the picture or put it into your PDF, whatever you want. I know this is possible with files such as Batch, you could spoof the server to make it think it is an exe and the user downloading would download it as an exe and of course the batch file wont run, but the point is that spoofing the server is possible. You do it with content-type headers.

gdlk

p.s. let us know if this solves your problem. :)


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 07, 2005 12:26 am 
Offline
Neighborhood Spidermoddy
User avatar

Joined: Mon Mar 29, 2004 4:24 pm
Posts: 31559
Location: Bothell, Washington, USA
what does content-type have to do with importing an unsupported image type into a PDF ?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 07, 2005 3:19 am 
Offline
Forum Contributor
User avatar

Joined: Mon Jun 14, 2004 10:39 am
Posts: 259
Location: Amerika
hmm.. I suppose I read it wrong but I assumed he would mov the SVG file bits into a container in his script and then tell the browser that it is either jpeg or png bits and thus would pass the server check for png or jpeg (depending on the gped version his server has) and would then pipe those bits into his PDF. It was only a suggestion.. perhaps a bad one? :)

regards


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 09, 2005 1:18 am 
Offline
DevNet Resident
User avatar

Joined: Fri Dec 24, 2004 3:59 am
Posts: 1452
Location: Lucknow, UP, India
lol
Quote:
but I assumed he would mov the SVG file bits into a container in his script and then tell the browser that it is either jpeg or png bits and thus would pass the server check for png or jpeg (depending on the gped version his server has) and would then pipe those bits into his PDF.

lol.

How can you say that.. SVG is a XML format dear.
Only thing I have is BATIK - an SVG Graphics Package developed under XML Images Project.
See http://xml.apache.org/batik for more details.
But there are probs (many of 'em).

#1. It written in Java.
#2. On using it in PHP thru PHP/Java Bridge it generates Null Pointer Exception without any reason.
#3. Even the demo script they have in their docs (in Java) gives that error when I compile and run it.
#4. They've included a SVG-Rasterizer in the package which readily converts SVG into JPEG, PNG & TIFF.
From CMD line it runs OK but if I try to exec() it from a PHP script it does nothing.

These all are driving me nuts, nuts and bigger nuts . Plz help if anybody can.

Thanx 4 any help.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 10, 2005 2:26 am 
Offline
DevNet Resident
User avatar

Joined: Fri Dec 24, 2004 3:59 am
Posts: 1452
Location: Lucknow, UP, India
I am still stuck at the same point. Feyd, please see if you can turn up something on this matter. It would be a great help for me.
Thanx


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 10, 2005 2:41 am 
Offline
Neighborhood Spidermoddy
User avatar

Joined: Mon Mar 29, 2004 4:24 pm
Posts: 31559
Location: Bothell, Washington, USA
n00b Saibot wrote:
Feyd, please see if you can turn up something on this matter.
why? are your googling powers not so good? :P

Since Batik is open sourced, it shouldn't be too difficult to port to PHP entirely.. I'd bet that with the help of onion2k, you could accomplish such a feat. Although I didn't look at the source to the package, so I'm not entirely sure what other packages are needed.. but I'd imagine just an xml parser and graphics rendering stuffs.. both of which are available in php already :)


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 10, 2005 2:54 am 
Offline
DevNet Resident
User avatar

Joined: Fri Dec 24, 2004 3:59 am
Posts: 1452
Location: Lucknow, UP, India
feyd-the good one wrote:
why? are your googling powers not so good?


:lol: that isn't so. i've search extensively before posting here. i have a habit of solving my probs myself. its very rare that i turn to others for help.
methinks this is the first time i have posted a prob.
I thought two brains are better than one. so that's why i....

anyway. thanx very much :D


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 18, 2007 7:08 am 
Offline
Forum Newbie

Joined: Fri May 18, 2007 3:13 am
Posts: 9
i tried it an get parse errors:

Parse error: syntax error, unexpected '&' in /var/www/web3/html/moritz/fpdf153/demo.php on line 27

the line:
$this->SetY(-15);


besides this there are many other errors in it - says zend studio. what i make wrong? could it be some html chracters?
ok, sorry for the noobish question it is html.

but now i get a warning and an error:
Warning: Cannot modify header information - headers already sent by (output started at ..../fpdf153/demo.php:2) in .../fpdf153/fpdf.php on line 1022
FPDF error: Some data has already been output to browser, can't send PDF file


Last edited by dermoritz on Fri May 18, 2007 7:29 am, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Fri May 18, 2007 7:15 am 
Offline
Breakbeat Nuttzer
User avatar

Joined: Wed Mar 24, 2004 8:57 am
Posts: 13098
Location: Melbourne, Australia
dermoritz wrote:
i tried it an get parse errors:

Parse error: syntax error, unexpected '&' in /var/www/web3/html/moritz/fpdf153/demo.php on line 27

the line:
$this->SetY(-15);


besides this there are many other errors in it - says zend studio. what i make wrong? could it be some html chracters?


The forum has broken the code. > should be >


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 21 posts ]  Go to page 1, 2  Next

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group