?
Solved

PDF generation problem

Posted on 2009-02-18
6
Medium Priority
?
425 Views
Last Modified: 2013-11-10
Hi all,
I'm trying to make a business card application that outputs a PDF for the printer to print out.

But I am getting some strange problems when I try to use images.

Also If I try to move my DIVs I need to allow the layout of the fields in the PDF to arrange themselves to whatever positions the users move the DIVs to.

But this uses pixels and the PDF uses points any ideas on how to get that part working?


<?php
$fname = $_REQUEST["T1"];
$jobtitle = $_REQUEST["T2"];
$companyname = $_REQUEST["T3"];
$othermsg = $_REQUEST["T4"];
$add1 = $_REQUEST["T5"];
$add2 = $_REQUEST["T6"];
$add3 = $_REQUEST["T7"];
$add4 = $_REQUEST["T8"];
$tel = $_REQUEST["T9"];
$fax = $_REQUEST["T10"];
$mobile = $_REQUEST["T11"];
$email = $_REQUEST["T12"];
$website = $_REQUEST["T13"];
 
$pdf = pdf_new();
pdf_open_file($pdf, "C:\bennyboy.pdf");
 
pdf_set_info($pdf, "Author", "LiquidPrint");
pdf_set_info($pdf, "Title", "Business Card");
pdf_set_info($pdf, "Creator", "Liquidprint.co.uk");
pdf_set_info($pdf, "Subject", "Business Card");
 
pdf_begin_page($pdf, 258, 172.9);
 
$fontdir = "C:\WINDOWS\Fonts"; 
pdf_set_parameter($pdf, "FontOutline", "arialMyName=$fontdir\arial.ttf");
$arial = PDF_findfont($pdf,"arialMyName","host",0 );
 
//$arial = pdf_findfont($pdf, "Arial", "host", 1);
pdf_setfont($pdf, $arial, 12);
 
pdf_setfont($pdf, $arial, 14);
pdf_show_xy($pdf, "$fname",11, 157);
 
pdf_setfont($pdf, $arial, 9);
pdf_show_xy($pdf, "$jobtitle",139, 140);
 
pdf_setfont($pdf, $arial, 11);
pdf_show_xy($pdf, "$companyname",11, 127);
 
pdf_setfont($pdf, $arial, 9);
pdf_show_xy($pdf, "$othermsg",11, 115);
 
pdf_setfont($pdf, $arial, 9);
pdf_show_xy($pdf, "$add1",11, 92);
 
pdf_setfont($pdf, $arial, 9);
pdf_show_xy($pdf, "$add2",11, 82);
 
pdf_setfont($pdf, $arial, 9);
pdf_show_xy($pdf, "$add3",11, 70);
 
pdf_setfont($pdf, $arial, 9);
pdf_show_xy($pdf, "$add4",11, 58);
 
pdf_setfont($pdf, $arial, 9);
pdf_show_xy($pdf, "$tel",11, 47);
 
pdf_setfont($pdf, $arial, 9);
pdf_show_xy($pdf, "$fax",11, 38);
 
pdf_setfont($pdf, $arial, 9);
pdf_show_xy($pdf, "$mobile",11, 27);
 
pdf_setfont($pdf, $arial, 9);
pdf_show_xy($pdf, "$email",11, 18);
 
pdf_setfont($pdf, $arial, 9);
pdf_show_xy($pdf, "$website",11, 10);
 
 
$gif_image = pdf_open_image_file($pdf, "gif", "images/card001.gif", " ", 0);
pdf_place_image($pdf, $gif_image, 258, 172.9, 1.0);
pdf_close_image($pdf, $gif_image);
 
pdf_end_page($pdf);
pdf_close($pdf);
 
echo "<A HREF=\"C:\bennyboy.pdf\" TARGET=\"_blank\">Open pdf in a new window $user</A>"
?>

Open in new window

0
Comment
Question by:cataleptic_state
  • 3
  • 2
6 Comments
 
LVL 111

Accepted Solution

by:
Ray Paseur earned 500 total points
ID: 23676707
You might want to look into using FPDF.  I print business cards with it.  Here is what one looks like.

fpdf.org

HTH, ~Ray
business-card.png
0
 
LVL 4

Author Comment

by:cataleptic_state
ID: 23679749
Is it better than using the inbuilt php version?
0
 
LVL 4

Author Comment

by:cataleptic_state
ID: 23680262
I'm getting a problem with layout, i want everything left aligned for now.

And once it works I will try to work with user movement on the previous page.

But I cant get the text right.
<?php
require('fpdf/fpdf.php');
 
$fname = $_REQUEST["T1"];
$jobtitle = $_REQUEST["T2"];
$companyname = $_REQUEST["T3"];
$othermsg = $_REQUEST["T4"];
$add1 = $_REQUEST["T5"];
$add2 = $_REQUEST["T6"];
$add3 = $_REQUEST["T7"];
$add4 = $_REQUEST["T8"];
$tel = $_REQUEST["T9"];
$fax = $_REQUEST["T10"];
$mobile = $_REQUEST["T11"];
$email = $_REQUEST["T12"];
$website = $_REQUEST["T13"];
 
$pdf=new FPDF('L','mm', array(61,91));
$pdf->AliasNbPages();
$pdf->SetAutoPageBreak(FALSE); 
 
$pdf->AddPage();
$pdf->SetFont('Arial','B',14);
$pdf->Cell(0,0, "$fname");
 
$pdf->Cell(2,2, "$jobtitle");
$pdf->Cell(5,4, "$companyname");
$pdf->Cell(0,6, "$othermsg");
$pdf->Cell(0,8, "$add1");
$pdf->Cell(0,0, "$add2");
$pdf->Cell(0,0, "$add3");
$pdf->Cell(0,0, "$add4");
$pdf->Cell(0,0, "$tel");
$pdf->Cell(0,0, "$fax");
$pdf->Cell(0,0, "$mobile");
$pdf->Cell(0,0, "$email");
$pdf->Cell(0,0, "$website");
 
 
 
$pdf->Output("businesscard.pdf" , "F");
?>

Open in new window

0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 4

Author Closing Comment

by:cataleptic_state
ID: 31548186
Hi Ray,
I used your suggestion and it works, theres alot of help on the FPDF forum too. Briliant!

Thank you, I was stuck for a very long time.
0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 23711914
Thanks for the points - glad you've got it moving forward.  I really like FPDF - there was a learning curve, but once the first script was written, the rest fell into place very quickly.  Best, ~Ray
0
 

Expert Comment

by:eteran
ID: 35492264
This is a great thread
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses
Course of the Month13 days, 23 hours left to enroll

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question