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

  • SEARCH
  • Home
  • 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

Related Questions

I need a php code and sql code that will let someone upload an
I need to daily run a script that will download a file from a
I need to send newsletters. I have already a PHP script that sends mass
I'm working on a PHP search script that scans a text file repository of
I'm using a PHP script to stream a live video (i.e. a file which
Quick question; I replaced a .css file which I was referencing in html/php that
I have a PHP Mail script that sends out emails and I need to
I would like to generate a static html page from a php file and
I have a ruby code that triggers php script over https. Use case: The
I need PHP code to replace comma or whitespace with hyphen For eg: If

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.