0

I am using a plugin named Spiritix(https://github.com/spiritix/php-chrome-html2pdf) for generating a chromepdf on symfony framework.I am getting the pagenumber on the headerTemplate and footerTemplate using the class pageNumber . My Requirement is to get pagenumber on the body part of the pdf.Is there any possible way exists?

My Pdf Controller Function

  /**
 * Function to view the contact of a club or federation.
 *
 * @return Json array
 */
public function viewspiritixpdfAction(Request $request)
{
    $input = new StringInput();
    $converter = new Converter($input, new EmbedOutput());
    $html = $this->renderView('ClubadminContactBundle:ContactList:pdftest.html.twig', [
        'title' => "Welcome to our PDF Test"

    ]);
    $header = $this->renderView('ClubadminContactBundle:ContactList:pdftestheader.html.twig', [
    ]);
    $footer = $this->renderView('ClubadminContactBundle:ContactList:pdftestfooter.html.twig', [
    ]);
    $converter->setOptions([
        'displayHeaderFooter'=> true,
        'headerTemplate'=> $header,
        'footerTemplate'=> $footer,
        'margin'=> [ 
            'top'=> "100px", 
            'bottom'=> "100px",
            'right'=>'20px',
            'left'=>'20px'
        ]
        ]);
    $input->setHtml($html);
    $output = $converter->convert();
    $output->embed('html.pdf');

}

pdftest.html.twig

{% for i in 0..20 %}
    <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has
    survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing
    software like Aldus PageMaker including versions of Lorem Ipsum.</p>


{% endfor %}

On the pdftest.html.twig i need a condition that if pagenumber is 2 then render a image.

Vimal
  • 1,140
  • 1
  • 12
  • 26
  • I don't think conditionally checking for page 2 will be easily possible. Since you are generating html, which is not split into pages, which is then "printed" as PDF. The page number in the pdf depends on factors such as margins, format (A4?), direction (landscape or portrait), etc. and your rendered html does not have those infos. All you can do is generate test pdfs and then manually align stuff. – dbrumann Oct 14 '19 at 07:21
  • Couldn't generate testpdfs and manually aligning stuff since the content is dynamically changing.The format and margins will be setting on the Setoptions.Default Format will be A4 – Vimal Oct 14 '19 at 07:28

0 Answers0