1

I am a newbie and I am trying to upload an html page using TCPF and i used file_get_contents to get the html body , but still there are many buttons that i don't want to show up in my pdf file , got all the body but couldn't exclude those buttons , this is the php i am using (invoice is the id of the div that i want to print): (Edit : i've seen a similar problem , but it wasn't quite my case , the solutions didn't work for me) here's my code codepen.io/sescada/pen/LYWKxWm So while getting the PDF i always get the convert into pdf button with it , which i don't want to have in my PDF (i want to get all the html content except the button into the pdf ) I tried doing this with jspdf(it worked but looking for different ways of doing it xD!! ) and I tried for a while with DOM , didn't get how it works exactly so i stuck with TCPDF

<?php
if (isset($_POST['convert'])){
  require_once('tcpdf.php');
  $obj_pdf= new TCPDF ('p' ,PDF_UNIT,PDF_PAGE_FORMAT,true,'UTF-8',false);
  $obj_pdf->SetCreator(PDF_CREATOR);
  $obj_pdf->SetTitle("Essai");
  $obj_pdf->SetHeaderData('',0,PDF_HEADER_TITLE,PDF_HEADER_STRING);
  $obj_pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
  $obj_pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
  $obj_pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
  $obj_pdf->SetMargins(PDF_MARGIN_LEFT, '10', PDF_MARGIN_RIGHT);
  $obj_pdf->SetHeaderMargin(1);
  $obj_pdf->SetFooterMargin(1);
  $obj_pdf->SetAutoPageBreak(TRUE, 1);
  $obj_pdf->AddPage();
  $content=file_get_contents('./cvtest.html',false,NULL);
  $first=explode("<div id='invoice'>",$content);
  $obj_pdf->writeHTML($first[0], true, false, true, false, '');
  $obj_pdf->lastPage();
  $obj_pdf->Output('try.pdf','I');
}
?>
Sescada
  • 33
  • 5
  • What do you mean by "upload an html page using TCPF"? Which kind of "buttons" do you want to exclude? – Nico Haase Jun 23 '21 at 08:57
  • Let's rephrase the question to be more to the point: you have an HTML string, and you want to do some logical processing on it (let's say remove certain HTML elements). Everything else, including where/how you're getting that HTML and what you want to do with it after processing, is irrelevant. – Jon Jun 23 '21 at 09:15
  • 1
    Now that we know how to accurately describe the goal, searching produces good results: https://stackoverflow.com/questions/3577641/how-do-you-parse-and-process-html-xml-in-php – Jon Jun 23 '21 at 09:16
  • Please add all clarification to your question by editing it. Which kind of button are you talking about? Any in the markup? Then why not remove it through DOM operations before rendering it in the PDF library? – Nico Haase Jun 23 '21 at 10:07

1 Answers1

1

You can simply hide unwanted elements using CSS. Check TCPDF examples on using CSS (e.g. this one).

Zoli Szabó
  • 4,366
  • 1
  • 13
  • 19