• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 428
  • Last Modified:

PDF generation problem

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
cataleptic_state
Asked:
cataleptic_state
  • 3
  • 2
1 Solution
 
Ray PaseurCommented:
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
 
cataleptic_stateAuthor Commented:
Is it better than using the inbuilt php version?
0
 
cataleptic_stateAuthor Commented:
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
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

 
cataleptic_stateAuthor Commented:
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
 
Ray PaseurCommented:
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
 
eteranCommented:
This is a great thread
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now