TCPDF problem: how to align text and images?
I want to generate resume in PDF format via PHP. TCPDF looks like a flexible library for that purpose. Let's say this is the expected result:
I just started learning TCPDF, so far I have the company title, name and title done, but they are not on the same alignment.
Here's my code:
<?php
require_once('tcpdf/config/lang/eng.php');
require_once('tcpdf/tcpdf.php');
class MYPDF extends TCPDF {
//Page header
public function Header() {
// Logo
$image_file = 'umbrella_logo.jpg';
$this->Image($image_file, 10, 10, 45, '', 'JPG', '', 'T', false, 300, '', false, false, 0, false, false, false);
// Set font
$this->SetFont('helvetica', 'B', 20);
}
}
// create new PDF document
$pdf = new MYPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
// set document information
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor('Umbrella Corporation');
$pdf->SetTitle('Employee Resume');
// set default header data
$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE.' My PDF', PDF_HEADER_STRING, array(0,64,255), array(0,64,100));
$pdf->AddPage();
$pdf->SetXY(15, 30);
$pdf->Cell(25, 10, 'Tobias Rieper', 0, $ln=0, 'C', 0, '', 0, false, 'B', 'B');
$pdf->SetXY(15, 35);
$pdf->Cell(20, 10, 'Senior Biochemist', 0, $ln=0, 'C', 0, '', 0, false, 'B', 'B');
$pdf->setFooterData(array(0,64,0), array(0,64,128));
$pdf->Output('example_001.pdf', 'I');
?>
How to fix this?
php tcpdf
add a comment |
I want to generate resume in PDF format via PHP. TCPDF looks like a flexible library for that purpose. Let's say this is the expected result:
I just started learning TCPDF, so far I have the company title, name and title done, but they are not on the same alignment.
Here's my code:
<?php
require_once('tcpdf/config/lang/eng.php');
require_once('tcpdf/tcpdf.php');
class MYPDF extends TCPDF {
//Page header
public function Header() {
// Logo
$image_file = 'umbrella_logo.jpg';
$this->Image($image_file, 10, 10, 45, '', 'JPG', '', 'T', false, 300, '', false, false, 0, false, false, false);
// Set font
$this->SetFont('helvetica', 'B', 20);
}
}
// create new PDF document
$pdf = new MYPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
// set document information
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor('Umbrella Corporation');
$pdf->SetTitle('Employee Resume');
// set default header data
$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE.' My PDF', PDF_HEADER_STRING, array(0,64,255), array(0,64,100));
$pdf->AddPage();
$pdf->SetXY(15, 30);
$pdf->Cell(25, 10, 'Tobias Rieper', 0, $ln=0, 'C', 0, '', 0, false, 'B', 'B');
$pdf->SetXY(15, 35);
$pdf->Cell(20, 10, 'Senior Biochemist', 0, $ln=0, 'C', 0, '', 0, false, 'B', 'B');
$pdf->setFooterData(array(0,64,0), array(0,64,128));
$pdf->Output('example_001.pdf', 'I');
?>
How to fix this?
php tcpdf
add a comment |
I want to generate resume in PDF format via PHP. TCPDF looks like a flexible library for that purpose. Let's say this is the expected result:
I just started learning TCPDF, so far I have the company title, name and title done, but they are not on the same alignment.
Here's my code:
<?php
require_once('tcpdf/config/lang/eng.php');
require_once('tcpdf/tcpdf.php');
class MYPDF extends TCPDF {
//Page header
public function Header() {
// Logo
$image_file = 'umbrella_logo.jpg';
$this->Image($image_file, 10, 10, 45, '', 'JPG', '', 'T', false, 300, '', false, false, 0, false, false, false);
// Set font
$this->SetFont('helvetica', 'B', 20);
}
}
// create new PDF document
$pdf = new MYPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
// set document information
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor('Umbrella Corporation');
$pdf->SetTitle('Employee Resume');
// set default header data
$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE.' My PDF', PDF_HEADER_STRING, array(0,64,255), array(0,64,100));
$pdf->AddPage();
$pdf->SetXY(15, 30);
$pdf->Cell(25, 10, 'Tobias Rieper', 0, $ln=0, 'C', 0, '', 0, false, 'B', 'B');
$pdf->SetXY(15, 35);
$pdf->Cell(20, 10, 'Senior Biochemist', 0, $ln=0, 'C', 0, '', 0, false, 'B', 'B');
$pdf->setFooterData(array(0,64,0), array(0,64,128));
$pdf->Output('example_001.pdf', 'I');
?>
How to fix this?
php tcpdf
I want to generate resume in PDF format via PHP. TCPDF looks like a flexible library for that purpose. Let's say this is the expected result:
I just started learning TCPDF, so far I have the company title, name and title done, but they are not on the same alignment.
Here's my code:
<?php
require_once('tcpdf/config/lang/eng.php');
require_once('tcpdf/tcpdf.php');
class MYPDF extends TCPDF {
//Page header
public function Header() {
// Logo
$image_file = 'umbrella_logo.jpg';
$this->Image($image_file, 10, 10, 45, '', 'JPG', '', 'T', false, 300, '', false, false, 0, false, false, false);
// Set font
$this->SetFont('helvetica', 'B', 20);
}
}
// create new PDF document
$pdf = new MYPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
// set document information
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor('Umbrella Corporation');
$pdf->SetTitle('Employee Resume');
// set default header data
$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE.' My PDF', PDF_HEADER_STRING, array(0,64,255), array(0,64,100));
$pdf->AddPage();
$pdf->SetXY(15, 30);
$pdf->Cell(25, 10, 'Tobias Rieper', 0, $ln=0, 'C', 0, '', 0, false, 'B', 'B');
$pdf->SetXY(15, 35);
$pdf->Cell(20, 10, 'Senior Biochemist', 0, $ln=0, 'C', 0, '', 0, false, 'B', 'B');
$pdf->setFooterData(array(0,64,0), array(0,64,128));
$pdf->Output('example_001.pdf', 'I');
?>
How to fix this?
php tcpdf
php tcpdf
asked Jan 3 at 7:05
anta40anta40
4,78812337
4,78812337
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
First, you're using center alignment for your cells rather than left alignment, so your cells are being center-aligned to widths of 25 and 20 mm respectively.
Instead, change parameter 6 from 'C'
to 'L'
for your Cell
calls, and that will change them to left alignment. That should get your cells to line up the way you're expecting.
Next, for the header image and text alignment. Since you're trying to align your cells with the boundaries of an image (or perhaps something inside an image), you'll probably want to remove the default cell padding with $pdf->setCellPadding(0);
Then you can adjust your Image or Cell positions as you see fit. Here, I have them aligned at an abscissa of 10mm.
<?php
//Note that my paths are different, use your project's appropriate paths.
require_once('TCPDF-6.2.17/tcpdf.php');
class MYPDF extends TCPDF {
//Page header
public function Header() {
// Logo
// Set font
$image_file = 'lymle.jpg';
$this->Image($image_file, 10, 10, 45, '', 'JPG', '', 'T', false, 300, '', false, false, 0, false, false, false);
$this->SetFont('helvetica', 'B', 20);
}
}
// create new PDF document
$pdf = new MYPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
// set document information
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor('Umbrella Corporation');
$pdf->SetTitle('Employee Resume');
// set default header data
$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE.' My PDF', PDF_HEADER_STRING, array(0,64,255), array(0,64,100));
$pdf->AddPage();
$pdf->setCellPadding(0);
$pdf->SetXY(10, 30);
$pdf->Cell(25, 10, 'Tobias Rieper', 0, $ln=0, 'L', 0, '', 0, false, 'B', 'B');
$pdf->SetXY(10, 35);
$pdf->Cell(20, 10, 'Senior Biochemist', 0, $ln=0, 'L', 0, '', 0, false, 'B', 'B');
$pdf->setFooterData(array(0,64,0), array(0,64,128));
$pdf->Output('example_001.pdf', 'I');
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54017760%2ftcpdf-problem-how-to-align-text-and-images%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
First, you're using center alignment for your cells rather than left alignment, so your cells are being center-aligned to widths of 25 and 20 mm respectively.
Instead, change parameter 6 from 'C'
to 'L'
for your Cell
calls, and that will change them to left alignment. That should get your cells to line up the way you're expecting.
Next, for the header image and text alignment. Since you're trying to align your cells with the boundaries of an image (or perhaps something inside an image), you'll probably want to remove the default cell padding with $pdf->setCellPadding(0);
Then you can adjust your Image or Cell positions as you see fit. Here, I have them aligned at an abscissa of 10mm.
<?php
//Note that my paths are different, use your project's appropriate paths.
require_once('TCPDF-6.2.17/tcpdf.php');
class MYPDF extends TCPDF {
//Page header
public function Header() {
// Logo
// Set font
$image_file = 'lymle.jpg';
$this->Image($image_file, 10, 10, 45, '', 'JPG', '', 'T', false, 300, '', false, false, 0, false, false, false);
$this->SetFont('helvetica', 'B', 20);
}
}
// create new PDF document
$pdf = new MYPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
// set document information
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor('Umbrella Corporation');
$pdf->SetTitle('Employee Resume');
// set default header data
$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE.' My PDF', PDF_HEADER_STRING, array(0,64,255), array(0,64,100));
$pdf->AddPage();
$pdf->setCellPadding(0);
$pdf->SetXY(10, 30);
$pdf->Cell(25, 10, 'Tobias Rieper', 0, $ln=0, 'L', 0, '', 0, false, 'B', 'B');
$pdf->SetXY(10, 35);
$pdf->Cell(20, 10, 'Senior Biochemist', 0, $ln=0, 'L', 0, '', 0, false, 'B', 'B');
$pdf->setFooterData(array(0,64,0), array(0,64,128));
$pdf->Output('example_001.pdf', 'I');
add a comment |
First, you're using center alignment for your cells rather than left alignment, so your cells are being center-aligned to widths of 25 and 20 mm respectively.
Instead, change parameter 6 from 'C'
to 'L'
for your Cell
calls, and that will change them to left alignment. That should get your cells to line up the way you're expecting.
Next, for the header image and text alignment. Since you're trying to align your cells with the boundaries of an image (or perhaps something inside an image), you'll probably want to remove the default cell padding with $pdf->setCellPadding(0);
Then you can adjust your Image or Cell positions as you see fit. Here, I have them aligned at an abscissa of 10mm.
<?php
//Note that my paths are different, use your project's appropriate paths.
require_once('TCPDF-6.2.17/tcpdf.php');
class MYPDF extends TCPDF {
//Page header
public function Header() {
// Logo
// Set font
$image_file = 'lymle.jpg';
$this->Image($image_file, 10, 10, 45, '', 'JPG', '', 'T', false, 300, '', false, false, 0, false, false, false);
$this->SetFont('helvetica', 'B', 20);
}
}
// create new PDF document
$pdf = new MYPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
// set document information
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor('Umbrella Corporation');
$pdf->SetTitle('Employee Resume');
// set default header data
$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE.' My PDF', PDF_HEADER_STRING, array(0,64,255), array(0,64,100));
$pdf->AddPage();
$pdf->setCellPadding(0);
$pdf->SetXY(10, 30);
$pdf->Cell(25, 10, 'Tobias Rieper', 0, $ln=0, 'L', 0, '', 0, false, 'B', 'B');
$pdf->SetXY(10, 35);
$pdf->Cell(20, 10, 'Senior Biochemist', 0, $ln=0, 'L', 0, '', 0, false, 'B', 'B');
$pdf->setFooterData(array(0,64,0), array(0,64,128));
$pdf->Output('example_001.pdf', 'I');
add a comment |
First, you're using center alignment for your cells rather than left alignment, so your cells are being center-aligned to widths of 25 and 20 mm respectively.
Instead, change parameter 6 from 'C'
to 'L'
for your Cell
calls, and that will change them to left alignment. That should get your cells to line up the way you're expecting.
Next, for the header image and text alignment. Since you're trying to align your cells with the boundaries of an image (or perhaps something inside an image), you'll probably want to remove the default cell padding with $pdf->setCellPadding(0);
Then you can adjust your Image or Cell positions as you see fit. Here, I have them aligned at an abscissa of 10mm.
<?php
//Note that my paths are different, use your project's appropriate paths.
require_once('TCPDF-6.2.17/tcpdf.php');
class MYPDF extends TCPDF {
//Page header
public function Header() {
// Logo
// Set font
$image_file = 'lymle.jpg';
$this->Image($image_file, 10, 10, 45, '', 'JPG', '', 'T', false, 300, '', false, false, 0, false, false, false);
$this->SetFont('helvetica', 'B', 20);
}
}
// create new PDF document
$pdf = new MYPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
// set document information
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor('Umbrella Corporation');
$pdf->SetTitle('Employee Resume');
// set default header data
$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE.' My PDF', PDF_HEADER_STRING, array(0,64,255), array(0,64,100));
$pdf->AddPage();
$pdf->setCellPadding(0);
$pdf->SetXY(10, 30);
$pdf->Cell(25, 10, 'Tobias Rieper', 0, $ln=0, 'L', 0, '', 0, false, 'B', 'B');
$pdf->SetXY(10, 35);
$pdf->Cell(20, 10, 'Senior Biochemist', 0, $ln=0, 'L', 0, '', 0, false, 'B', 'B');
$pdf->setFooterData(array(0,64,0), array(0,64,128));
$pdf->Output('example_001.pdf', 'I');
First, you're using center alignment for your cells rather than left alignment, so your cells are being center-aligned to widths of 25 and 20 mm respectively.
Instead, change parameter 6 from 'C'
to 'L'
for your Cell
calls, and that will change them to left alignment. That should get your cells to line up the way you're expecting.
Next, for the header image and text alignment. Since you're trying to align your cells with the boundaries of an image (or perhaps something inside an image), you'll probably want to remove the default cell padding with $pdf->setCellPadding(0);
Then you can adjust your Image or Cell positions as you see fit. Here, I have them aligned at an abscissa of 10mm.
<?php
//Note that my paths are different, use your project's appropriate paths.
require_once('TCPDF-6.2.17/tcpdf.php');
class MYPDF extends TCPDF {
//Page header
public function Header() {
// Logo
// Set font
$image_file = 'lymle.jpg';
$this->Image($image_file, 10, 10, 45, '', 'JPG', '', 'T', false, 300, '', false, false, 0, false, false, false);
$this->SetFont('helvetica', 'B', 20);
}
}
// create new PDF document
$pdf = new MYPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
// set document information
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor('Umbrella Corporation');
$pdf->SetTitle('Employee Resume');
// set default header data
$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE.' My PDF', PDF_HEADER_STRING, array(0,64,255), array(0,64,100));
$pdf->AddPage();
$pdf->setCellPadding(0);
$pdf->SetXY(10, 30);
$pdf->Cell(25, 10, 'Tobias Rieper', 0, $ln=0, 'L', 0, '', 0, false, 'B', 'B');
$pdf->SetXY(10, 35);
$pdf->Cell(20, 10, 'Senior Biochemist', 0, $ln=0, 'L', 0, '', 0, false, 'B', 'B');
$pdf->setFooterData(array(0,64,0), array(0,64,128));
$pdf->Output('example_001.pdf', 'I');
answered Jan 7 at 9:33
EPBEPB
2,63911717
2,63911717
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54017760%2ftcpdf-problem-how-to-align-text-and-images%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown