Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 591539
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T15:38:42+00:00 2026-05-13T15:38:42+00:00

I need to code a PHP script that would let me generate a pdf

  • 0

I need to code a PHP script that would let me generate a pdf file which displays a member ID card (something like a credit card used to identify oneself) at a certain resolution.

Let me explain:
I do have the basic blueprint of the card in png file format. The script needs to drop in a member’s name and birthday along with a serial. So far, no problem – there are plenty of good working PHP libraries out there.

My problem is to ensure that the resulting pdf (the generated image of the card, to be precise) meets a certain resolution (preferably 300dpi), so that printing it would look right.

Any ideas?

EDIT
I solved it using the TCPDF library which lets you scale images at a certain resolution.
Get it here: http://www.tecnick.com/public/code/cp_dpage.php?aiocp_dp=tcpdf

EDIT @Don

require_once(dirname(__FILE__).'/tcpdf/config/lang/eng.php');
require_once(dirname(__FILE__).'/tcpdf/tcpdf.php');

// create new PDF document
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT,
                 true, 'UTF-8', false); 

// set document information
$pdf->SetCreator('SO-youth');
// remove default header/footer
$pdf->setPrintHeader(false);
$pdf->setPrintFooter(false);

// set default monospaced font
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);

//set margins
$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);

//set auto page breaks
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);

//set image scale factor
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO); 

// set font
$pdf->SetFont('courier', '', 10);

// add a page
$pdf->AddPage();

// set JPEG quality
$pdf->setJPEGQuality(100);

$cred = <<<EOT
    <p>
        <b>{$userdata->first_name} {$userdata->last_name}</b><br/>
        <span style="font-size: 80%;">{$userdata->geburtstag}</span>
    </p>
EOT;
$id = <<<EOT
    <span style="font-size: 60%;">{$userdata->club_id}</span>
EOT;

$pdf->Image(dirname(__FILE__).'/img/clubcard.jpg',
            10, 10, 85.6, 53.98, null, null, null, false, 300);

$pdf->writeHTMLCell(60, 15, 50.5, 20.5, $cred);
$pdf->writeHTMLCell(50, 20, 77, 50.5, $id);

//Close and output PDF document
$pdf->Output($userdata->filename, 'F');
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T15:38:42+00:00Added an answer on May 13, 2026 at 3:38 pm

    I would use Imagemagick for this purpose, along with Imagick to be able to access it directly from php.

    You will then be able to take the original image, add some text to it, and output (or store) as pdf, with something like this:

        $image = new Imagick($filename);
        $draw = new ImagickDraw();
        $draw->setFont($font);
        $draw->setFontSize($fontSize);
        $image->annotateImage($draw, $xpos, $ypos, $rotation, $text);
        // Changes the dpi
        $image->setImageResolution(200,200);
    

    I can’t find the correct code for outputting/storing it as pdf quickly, but that should be documented somewhere on the Imagemagick site.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 315k
  • Answers 315k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer This is a tough one, I'll give a try. +1… May 13, 2026 at 11:22 pm
  • Editorial Team
    Editorial Team added an answer How about UUID: http://java.sun.com/j2se/1.5.0/docs/api/java/util/UUID.html#randomUUID%28%29 May 13, 2026 at 11:22 pm
  • Editorial Team
    Editorial Team added an answer You are not creating a generic function, you are creating… May 13, 2026 at 11:22 pm

Related Questions

In my webapp I have a page called display.php. The script in this page
I am writing an algorithm to generate combinations of items from a database. They
I have a folder of PHP scripts, they are mostly utility scripts. How to
I'm ultimately trying to install PEAR so I can easily install PHPUnit. I want
I am looking for way to parse the strikeout / strikethrough value of cells

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.