Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

correct aproach for stationery and content #112

Closed
twoSGmbH opened this issue Oct 18, 2018 · 1 comment
Closed

correct aproach for stationery and content #112

twoSGmbH opened this issue Oct 18, 2018 · 1 comment

Comments

@twoSGmbH
Copy link

Hello,

i've got a stationery with header and footer. in between those blocks should appear the content of every site. The stationery blocks should appear on every site so i put them in an object and added it to all pages via addObject. Now my problem is that i can't get the ezSetMargins to work. My thought was that i add the stationery object to all sites and then set the correct margin for the area in between the header and the footer so that the content would automatically break onto a new page before running into the footer and starts after the header on the new page.

what would be the correct aproach to achieve this?

thanks in advance

@ole1986
Copy link
Collaborator

ole1986 commented Oct 21, 2018

Here is a quick example on how to add header and footer while positioning the rest of its content using $pdf->ezSetMargins

<?php

include '../src/Cezpdf.php';

$pdf = new Cezpdf('a4', 'portrait', 'none', null);

$all = $pdf->openObject();
$pdf->saveState();
$pdf->setStrokeColor(0, 0, 0, 1);

// header line and text
$pdf->line(20, 822, 580, 822);
$pdf->addText(20, 800, 14, 'Repeating header line');
$pdf->line(20, 790, 580, 790);
// footer line and text
$pdf->line(20, 40, 578, 40);
$pdf->addText(20, 30, 8, 'Hello footer');
$pdf->addText(580, 30, 8, 'footer right aligned', 0, 'right');

$pdf->restoreState();
$pdf->closeObject();

$pdf->addObject($all,'all');

$pdf->ezSetMargins(100, 100, 50, 50);


$text = str_repeat(
    "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.\n\n"
    , 20);

$pdf->ezText($text, 0, ['justification' => 'full']);


if (isset($_GET['d']) && $_GET['d']) {
    echo "<pre>";
    echo $pdf->ezOutput(true);
    echo "</pre>";
} else {
    $pdf->ezStream(['Content-Disposition' => 'readme.pdf']);
}

Please note: Using the ez* methods (like ezText and ezTable) may have side effects when using it inside $pdf->addObject

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant