Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SVG to PDF conversion using TCPDF in PHP

Tags:

php

pdf

svg

tcpdf

I am trying to convert a SVG file to PDF file using TCPDF library in PHP. I have created a SVG file and use PHP to replace text and plan to render the resultant SVG file to PDF file.

Any idea, if TCPDF library supports SVG to PDF conversion. Any pointers in this direction would really help me.

like image 810
Kiran Avatar asked Oct 20 '22 14:10

Kiran


1 Answers

You don't really need to replace text or render, Once you have created your svg file. All you just need to include tcpdf in your script and create its object like e.g.

            require_once(DOCUMENT_ROOT . '/library/Lib/tcpdf/mypdf.php');
            $this->pdf = new MYPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
            $this->pdf->AddPage(); // Add page to pdf before addding content
            //There are several other property need to be set on basis of your need
            $this->pdf->ImageSVG('file/mySVGFile.svg', 15, 20, '', '', '',
            '', '', 1, false); // 15,20 are co-ordinate to position graph in pdf

Once you added your content to your pdf, Last step comes is to download the pdf using .

$this->pdf->Output('my.pdf', 'FD');

Feel free to ask for anything you have any query in this code.

like image 157
Kuldeep Dangi Avatar answered Oct 23 '22 06:10

Kuldeep Dangi