Writing PDF Using PHP (PDFLib)

I am currently writing code to output a PDF file in PHP using PDFlib from http://www.pdflib.com/ . The problem is that all html tags are also written to the output file. How can I cancel all those tags?

Here is my sample code.

$postVariable = $_POST;

$contentData = "";
foreach($postVariable as $key => $value){ 
    if(is_array($key)){
        foreach($key as $key1 => $value1){
           $contentData.= $key1 .": ". $value1."<nextline>";
        }
    }else{
        $contentData.= $key .": ". $value."<nextline>";
    } 
}

$testdata = nl2br($contentData);
$pdf = pdf_new();
// open a file
pdf_open_file($pdf, $_SERVER['DOCUMENT_ROOT']."cas".DIRECTORY_SEPARATOR."$filename.pdf");
// start a new page (A4)
pdf_begin_page($pdf, 595, 842);

// Locate Font Directory
$fontdir = "C:\WINDOWS\Fonts";
// Font Name Parameters
pdf_set_parameter($pdf, "FontOutline", "arialMyName=$fontdir\arial.ttf");
// Find Font
$arial = PDF_findfont($pdf,"arialMyName","host",0 );
// Set font size and font name
pdf_setfont($pdf, $arial, 10);

//$arial = pdf_findfont($pdf, "Arial", "host", 1);
//pdf_setfont($pdf, $arial, 10);
// print text
pdf_show_xy($pdf, "TO THE UNIT OWNER",50, 750); 
pdf_show_xy($pdf, "Test ext", 50,730);
pdf_show_xy($pdf, "test test", 50,715);
pdf_show_xy($pdf, $contentData, 50,700);
// end page
pdf_end_page($pdf);
// close and save file
pdf_close($pdf);

and sample output: TO UNIT OWNER Test text test test Type: Apartment **** page_name: **** var_company: **** var_date: **** submit: Save and load <

It ignores the html tags and includes it in the content.

Are there any other ways to print HTML to PDF using the library I am currently using (PDFlib).

Thank.

Regards, Resty

+3
3

TCPDF. HTML PDF , CSS-. HTML- . , , PDF , 100% . .

HTML-, , strip_tags. , .

, - PHP, HTML- WebKit PDF . libwkhtmltox . . , PDF , New York Times - . (http://www.2shared.com/document/kYuS_G7p/nytimes.html - " " " ). . . , PHP, . : TCPDF.

+3

PDF- HTML PDFLib. , , .

TCPDF, HTML.

+2

Man ... I tried to do the same thing once. Using pdflib is very difficult.

I found this project hosted on Google. The project earned 10 stars out of 5.

It's called the DOM PDF, you can download it here . You can create PDF files from CSS-enabled HTML pages. You can create PDFs with less than 10 lines of code!

Look at the samples to see them in action.

+2
source

Source: https://habr.com/ru/post/1765812/


All Articles