spipu / html2pdf Goto Github PK
View Code? Open in Web Editor NEWOFFICIAL PROJECT | HTML to PDF converter written in PHP
Home Page: http://html2pdf.fr/en/default
License: Open Software License 3.0
OFFICIAL PROJECT | HTML to PDF converter written in PHP
Home Page: http://html2pdf.fr/en/default
License: Open Software License 3.0
My issue is about the cellspacing attribute set at "0" on table
The fact is there is always a thin space between cells...
I just try this on the last version (4.5.0), and the issue still exist.
Here is my sample html where you can see thin vertical and horizontal spaces :
<style type="text/css">
table td { background: #DDDDDD; border: solid 0px #DDDDDD;height: 30px;}
</style>
<page>
<table cellspacing="0" cellpadding="0" border="0">
<tr>
<td style="width:150px;background: #DDDDDD;">Ceci est un</td>
<td style="width:150px;background: #DDDDDD;" class="col1"><?php echo 'tést de style';?></td>
<td style="width:150px;background: #DDDDDD;">Ceci est un</td>
</tr>
<tr>
<td style="background: #FFFFFF;">Ceci est deux</td>
<td style="background: #DDDDDD;" class="col1"><?php echo 'tést de style';?></td>
<td style="background: #FFFFFF;">Ceci est un</td>
</tr>
</table>
</page>
regards
Hi,
I have this error when I use HTM2PDF 4.5.1
[ERROR]
It seems that HTML2PDF dependencies are not installed...
you must install thems with composer install
When I replac with the previous version 4.4.0, everything is OK.
I m on a Debian 8 server, PHP 5.6.
Not a big deal ... it's just to let you know !
table {
width: 100%;
border-collapse: collapse;
}
table tr.total td {
border: 1px solid #999;
}
All borders are rendered expect top one.
Hello I have this problem when I try to create a PDF, you could help me ?
Are there ways not to split tables on page break?
I create documents with many little tables out from a database. But some tables are splitting on page break. Is it possible to hold tables together?
Like this css: "page-break-inside: avoid"?
Hey,
I want to install HTML2PDF in my Website ... But I don't how to do it..
I have download the files by FTP.
And I have this error : "[ERROR] It seems that HTML2PDF dependencies are not installed... you must install thems with composer install
"
I Know, I must install "composer" but how ? By SSH in my server ?
Thanks
This package could be registered at packagist.org so it can be downloaded via composer.
I tried to use html2pdf.fr to create a pdf for a table with about 40'000 rows. Unfortunately it takes to much time. for about 1'000 Records I just have to wait about one minute and the CPU-load of the server is about 99%. Does anyone has an idea to perform the creation? The table is quite simple without any css.
Hi
First of all thank you so much for this nice package.
I want to say that I have a " dream " :D that soon, we can integrate bootstrap css ^^ this is very important for most apps web
Thanks :)))
Hi,
how do we use external js( Jquery plugins ).
i have html page with javascript, highcharts, html, css but its not working with external js
any solution ..??
I would like to propose a enhancement, if you allow me
There is a properties named word-wrap
that works with word-break
to break word preventing it to overflow the parent width, this property specifies line break opportunities within words.
For word-break
Values have the following meanings:
normal
: Break lines according to their usual rules.<?php
$text = "The quick brown fox jumped over the lazy dog.";
$newtext = wordwrap($text, 20, "<br />\n");
break-all
: Lines may break between any two characters within words. Hyphenation is not applied. This option is used mostly in a context where the text is predominantly using CJK characters with few non-CJK excerpts and it is desired that the text be better distributed on each line.<?php
$text = "A very long woooooooooooord.";
$newtext = wordwrap($text, 8, "<br />\n", true);
keep-all
: Lines may break only at word separators and other explicit break opportunities. Otherwise this option is equivalent to ‘normal’. This option is mostly used where the presence of word separator characters still creates line-breaking opportunities, as in Korean./**
* Based on @cmbuckley original function I implemented a function to wrap my texts with line break,
* in all cases this is the best function, fit the word base on width on the table cell.
* When the word is too long it will be break in a 2 lines also.
* Similar of this style: `style="word-wrap: break-word; word-break: break-all;"`
**/
<?php
function smart_wordwrap($string, $width = 75, $break = "<br>") {
// split on problem words over the line length
$pattern = sprintf('/([^ ]{%d,})/', $width);
$output = '';
$words = preg_split($pattern, $string, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE);
foreach ($words as $word) {
// normal behaviour, rebuild the string
if (false !== strpos($word, ' ')) {
$output .= $word;
} else {
// work out how many characters would be on the current line
$wrapped = explode($break, wordwrap($output, $width, $break));
$count = $width - (strlen(end($wrapped)) % $width);
// fill the current line and add a break
$output .= substr($word, 0, $count) . $break;
// wrap any remaining characters from the problem word
$output .= wordwrap(substr($word, $count), $width, $break, true);
}
}
// wrap the final output
return wordwrap($output, $width, $break);
}
The result into a table cell of this last is it:
But as I'm applying a fixed width it on original string not on text value of parsed on html2pdf class. It would be very useful if it respect the cell width(if defined) to break the words into lines to prevent table overflow.
dir=rtl not worked ;
I am generating a document in several languages (including Japanese, Chinese, Korean, Thai, but also Greek, Polish and more). All characters display properly in the document except when they appear in page_header or page_footer tags, where they get replaced by question marks.
I've confirmed that these characters display properly when replacing <page_header>
and <page_footer>
tags with ordinary <div>
s.
I've been trying to find a fix for this for hours with no success at all unfortunately.
Here is the code I'm using to initialize the library:
$pdf = new HTML2PDF('P', 'A4', 'en', true, 'UTF-8', array(14, 14, 14, 12));
I'm using Arial Unicode MS to make sure that TCPDF uses the proper font, as described on several forums:
$pdf->setDefaultFont('arialunicid0');
As you can see on the screenshot below, all characters are properly displayed on the page, but not in the header.
Thanks for the great library by the way!
Hi.
I’m developing for OpenEMR project. The project uses html2pdf library v.x.x.x to generate PDF from HTML.
I’m trying to fix their PDF report generation to generate right-to-left ( RTL ) documents correctly.
It seems there is a problem there.
$pdf = new HTML2PDF ($GLOBALS['pdf_layout'],
$GLOBALS['pdf_size'],
$GLOBALS['pdf_language'],
true, // default unicode setting is true
'UTF-8', // default encoding setting is UTF-8
array($GLOBALS['pdf_left_margin'],$GLOBALS['pdf_top_margin'],$GLOBALS['pdf_right_margin'],$GLOBALS['pdf_bottom_margin']) );
$pdf->pdf->setRTL(true);
$pdf->writeHTML($content, false);
if ($PDF_OUTPUT == 1) {
$pdf->Output('report.pdf', $GLOBALS['pdf_output']); // D = Download, I = Inline
}
Do you support RTL languages?
I don’t success to use with ‘setRTL’ method of TCPDF library.
Please let me knew about this.
Thank you.
Amiel.
In order to be able to get PSR4 we'll need to upgrade at least to PHP 5.3
Since the current minimum supported version of PHP is 5.5, we may also discuss which minimum version is more relevant.
As it's a breaking change, i think this should target the 5.0 release
Hi
is the hypenation (plugin of fpdf) supported?
I tried with this code
$html2pdf = new HTML2PDF('P', 'A4', 'it', true, 'UTF-8',array(0,0,0,0));
$html2pdf->pdf->SetDisplayMode('fullpage');
$hyphen_patterns = $html2pdf->pdf->getHyphenPatternsFromTEX('hyphens/it.tex');
$content = $html2pdf->pdf->hyphenateText($content, $hyphen_patterns, array(), 1, 2, 1, 8);
$html2pdf->writeHTML($content);
$html2pdf->Output($allegato, 'F');
but not works
Thanks
Fatal error: Can't inherit abstract function Spipu\Html2Pdf\Tag\TagInterface::getName() (previously declared abstract in Spipu\Html2Pdf\Tag\AbstractTag) in /var/www/ikoolclub.com/public_html/vkooladmin/html2pdf/src/Tag/AbstractTag.php on line 25
how to fix it thanks
After solved the issue #81 I got a new one,
The table header is rendering twice.
The HTML:
<page backtop="37mm" backbottom="0mm" backleft="0mm" backright="0mm" style="margin: 12mm;">
<page_header style="width: 100%;">
<table style="width: 100%;">
<tr>
<td style="text-align: center; width: 19%">
<img src="{{img}}" width="52" style="margin: 2mm;" />
</td>
<td style="text-align: left; width: 81%; padding: 1mm auto auto 1mm;">
{{client_name}}
</td>
</tr>
<tr>
<td>REQUERENTE:</td>
<td>{{requerente}}</td>
</tr>
<tr>
<td>PROCESSO:</td>
<td>{{_numproc}}</td>
</tr>
<tr>
<td>ASSUNTO:</td>
<td>{{tipodescr}}</td>
</tr>
</table>
</page_header>
<h5>FICHA FINANCEIRA</h5>
<table id="t1" style="width: 100%; font-size: 77.9%;" border="1">
<thead>
<tr>
<th style="width: 15mm; text-align: center; " >Lançamento</th>
<th style="width: 15mm; text-align: center;" >DAM</th>
<th style="width: 16mm; text-align: center; ">Valor Documento</th>
<th style="width: 14mm; text-align: center; ">Data Emissão</th>
<th style="width: 14mm; text-align: center; ">Data Vencimento</th>
<th style="width: 30mm; text-align: center; ">Classificação</th>
<th style="width: 14mm; text-align: center; ">Data Pagamento</th>
<th style="width: 16mm; text-align: center; ">Valor Pago</th>
<th style="width: 15mm; text-align: center; ">Situação</th>
</tr>
</thead>
<tbody>
<tr nobr="true">
<td style=" text-align: center; ">2665940</td>
<td style=" text-align: center; ">14688395</td>
<td style=" text-align: right; ">364509</td>
<td style=" text-align: center; ">10/4/2015</td>
<td style=" text-align: center; ">21/7/2015</td>
<td style=" text-align: center; ">TAXA DE ARRECADAÇÃO</td>
<td style=" text-align: center; ">27/9/2015</td>
<td style=" text-align: right; ">533300</td>
<td style=" text-align: center; ">ATIVO</td>
</tr>
(...)
</tbody>
</table>
</page>
PHP Call:
<?php
use Spipu\Html2Pdf\Html2Pdf;
$orientation = 'P';
$format = 'A4';
$langue = 'en';
$unicode = true;
$encoding = 'UTF-8';
$marges = array(12, 12, 12, 12);
$html2pdf = new Html2Pdf($orientation, $format, $langue, $unicode, $encoding, $marges);
$content = file_get_contents("page.html");
$html2pdf->WriteHTML($content);
$html2pdf->Output('processo' . $numproc . '.pdf');
?>
I'm not sure about whats happening.... I'm using the latest version of souce code and TCPDF.
Could someone help to solve it?
A PDF with a long table (4 pages), get many blank page in it.
I try to check it.
When an image is not available, it is currently replaced by a pink area.
It could be great to :
This change will imply to update _drawImage
and _drawRectangle
methods.
Hi there,
I don't have server level access to the website I'm developing and I would like to know how to easily include HTML2PDF without the need of composer? Is there a fully extractable package that I can use?
Thanks,
Hello , here I have this error that appears, I tried to solve it but not here is the code of my img tag :
img src="http://moodle-dev.dinf.cll.qc.ca/pluginfile.php/45/mod_ouwiki/content/46/ch%20gene.jpg" height="237" width="725" alt="ch%20gene.jpg"
Hi, I use html2pdf and output as 'd' (i.e. $html2pdf->Output($diffname,'d');).
I want to add some alert/close the current after the download finish.
How can I check this?
Can I include the css file?
I need to replace the hard code filename used in the Output command by a variable like $filename because the file name is never the same.
I tried the following two approaches but none is working:
$html2pdf->Output('$exemple.pdf','F');
or
$html2pdf->Output($exemple.pdf,'F');
Any idea ? Thank you very much in advance.
Hello,
I am sorry, but forum is not online, so I will ask here:
is possible render PDF from SVG which contains multiple layers and a few has parameter display="none" ...? Will html2pdf accept such parameter?
Thank You
The hypenation is suported in html2pdf? If yes how is the function?
Thanks
Hi,
I'm using v4,
Why do I get the first page "blank" !?
Here my code :
<body>
<page backcolor="#FEFEFE" backtop="10mm" backbottom="30mm" footer="date;heure;page" style="font-size: 12pt">
<page_header>
<table class="page_header">
<tr>
<td style="width: 100%; text-align: center">
<img src='{{asset('images/emec_logo.jpg')}}' alt='logo' style='width: 10mm'>
</td>
</tr>
<tr>
<td style="width: 100%; text-align: center">
<b>CONSORTIUM EMEC-ES</b>
</td>
</tr>
</table>
</page_header>
<page_footer>
<table class="page_footer">
<tr>
<td style="width: 100%; text-align: right">
page [[page_cu]]/[[page_nb]]
</td>
</tr>
</table>
</page_footer>
</page>
<?php
$content = ob_get_clean();
$html2pdf = new \HTML2PDF('P', 'A4', 'fr', true);
$html2pdf->writeHTML($content);
$html2pdf->Output('file.pdf');
?>
</body>
Hello,
I do not know if it has to be considered as a problem but :
If i have border:0; in my css html2pdf draw a border on the styled block.
In a browser there isn't any border.
Finaly, I must set border:0px; (force unit) to do not draw a border.
Thanks.
Hello,
How to add background image for generated PDF file?
Regards
unicode fonts with devanagari script for Hindi language?
I have a strange one for you :-)
My pdf is happily displaying bullets (both UL and OL) when I output straight to the browser or as a download. The problem is when I save the pdf to the browser they disappear....! Can anyone help? I just noticed this and the project has to go live tomorrow afternoon!
Thanks in advance,
Will
With a JPG of 140k, one PDF of 12 pages is generate in 54s.
Without, the PDF is generate in 6s.
I try to check where this issue come from, i think it's from TCPDF (try with v5 to v6.2.11), but i'm not sure.
I have to create a dynamic document which is changed based on the data from my database. But this document only has a page header starting from the second page.
I wasn't capable of creating the HTML to solve that problem. Is that possible? How can I do that?
Hi,
here is a small bug (see example : https://gist.github.com/Grummfy/1d22c3984af8e415251f )
when we have a property "border-collapse: collapse;" on a table the property border-top doesn't work.
thanks
Unit tests should be created in order to improve code quality and avoid regressions.
The forum is not working, so maybe some help here.
I am trying to generate a PDF, with ul li. I have the stlye="float:left" on the li objects. When rendering in the bowser ($llama->writeHTML($content,true);
The li objects stack the way I intended. When the PDF is generated, they do not stack, and it appears that the text is overwriting itself.
Any help would be greatly appreciated.
table {
margin: 0 0 21px;
}
has no effect.
Thank you for your work, html2pdf is a great tool!
Is there any particular reason why an old version of TCPDF is used? The version 5.0.002 was released 5 years ago (https://github.com/tecnickcom/TCPDF/blob/develop/CHANGELOG.TXT).
Can you update TCPDF to version 6.x, or add TCPDF as a dependency in the composer.json file?
Regards,
Guillaume
Hi @spipu,
It seems Packagist doesn't recognize the current tag parttern like v4.03
.
Should be v4.0.3
or v4.3
. Or without the prefix 'v', like 4.0.3
or 4.3
.
Could you change it? Or could you keep both parttern?
References:
i use pjmail in codeigniter but not working, may be problem with email config like smtp host..etc,
how to send html2pdf convert as attach in send mail codeigniter or may u want to tell me how to use pjmail in codeigniter.. thanks..
Hi,
I'm trying to print a report on a table, but I'm geting some issues on
But when some table does not fit on the page, the page cells overlap the page header:
Page Code:
<page>
<page_header style="width: 100%;">
<table style="width: 100%;">
<tr>
<td style="text-align: center; width: 19%">
<img src="{{img}}" width="52" style="margin: 2mm;" />
</td>
<td style="text-align: left; width: 69%; padding: 1mm auto auto 1mm;">
Prefeitura Municipal de Nova Friburgo - RJ<br>SEMMADUS</td>
<td style="text-align: left; width: 12%; padding: 1mm auto auto 1mm;">
Folha:<br><br><br><br>
</td>
</tr>
<tr>
<td>REQUERENTE</td>
<td colspan="2"></td>
</tr>
<tr>
<td>NRO. PROCESSO:</td>
<td colspan="2"></td>
</tr>
<tr>
<td>ASSUNTO:</td>
<td colspan="2"></td>
</tr>
</table>
</page_header>
<div style="position: relative; page-break-before: right; clear:both; margin-top: 35mm;">
<h5>FICHA FINANCEIRA</h5>
<table border="1" style="width: 100%; font-size: 75.7%;">
<thead>
<tr>
<th style=" text-align: left; " >Num.</th>
<th style=" text-align: left;" >DAM</th>
<th style=" text-align: center; ">Valor Documento</th>
<th style=" text-align: left; ">Data Emissão</th>
<th style=" text-align: left; ">Data Vencimento</th>
<th style=" text-align: left; ">Classificação</th>
<th style=" text-align: left; ">Data Pagamento</th>
<th style=" text-align: left; ">Valor Pago</th>
<th style=" text-align: left; ">Situação</th>
</tr>
</thead>
<tbody>
<tr nobr="true">
<td>2680313</td>
<td>15135325</td>
<td>999999.00</td>
<td>00/00/0000</td>
<td>00/00/0000</td>
<td>nono nono no no nono nono no</td>
<td>00/00/0000</td>
<td>999999.00</td>
<td>Cancelado</td>
</tr>
(.....)
<tr nobr="true">
<td>2680313</td>
<td>15135325</td>
<td>999999.00</td>
<td>00/00/0000</td>
<td>00/00/0000</td>
<td>nono nono no no nono nono no</td>
<td>00/00/0000</td>
<td>999999.00</td>
<td>Cancelado</td>
</tr>
</tbody>
</table>
</div>
</page>
PHP Call:
<?php
use Spipu\Html2Pdf\Html2Pdf;
$orientation = 'P';
$format = 'A4';
$langue = 'en';
$unicode = true;
$encoding = 'UTF-8';
$marges = array(12, 12, 12, 12);
$html2pdf = new Html2Pdf($orientation, $format, $langue, $unicode, $encoding, $marges);
$content = file_get_contents("page.html");
$html2pdf->WriteHTML($content);
$html2pdf->Output('processo' . $numproc . '.pdf');
?>
I tried to put a margin on table> instead page content but no success, when table creates a new header on the second page it doesn't respect the original table> margin.
I'm not sure, but I think it's a bug, because table overflows should respect the page_header and don't overlap.
Regards.
Hello,
in tcpdfConfig.php, on line 66, $kPathUrl is set only if $_SERVER['HTTP_HOST'] is not empty.
then K_PATH_URL constant is defiened that way :
define('K_PATH_URL', $kPathUrl);
(line 80)
But $_SERVER['HTTP_HOST'] is not always set (during a CRON, for exemple), resulting in a notice :
PHP Notice: Undefined variable: kPathUrl in /var/www/sites/bazarchicv4/library/external/html2pdf/_class/tcpdfConfig.php on line 80
Trying to open test examples and get this errors:
Warning: require_once(/-----------/html2pdf/examples/../vendor/autoload.php) [function.require-once]: failed to open stream: No such file or directory
And then fatal error, of course
Where can i find this file?
Hi.
I have found a bug, when having a table with border-collapse: collapse
and there is a
<style type="text/css">
table {border-collapse: collapse;}
.table-bordered {border-width: 0.25mm; border-style: solid; border-color: #aaaaaa;}
</style>
<page backtop="5mm" backbottom="5mm" backleft="5mm" backright="5mm">
<table>
<tr>
<th class="table-bordered" style="width: 20mm;">0 0</th>
<th class="table-bordered" style="width: 21mm;">0 1</th>
<th class="table-bordered" style="width: 22mm;">0 2</th>
</tr>
<tr>
<td class="table-bordered"><div>1 0</div></td>
<td class="table-bordered">1 1</td>
<td class="table-bordered">1 2</td>
</tr>
</table>
</page>
The result of this code looks like this:
The first column is stretched over the whole page, because of the <div>
element in the table cell.
But if you remove the table {border-collapse: collapse;}
the table is rendered correctly. See:
I tried to debug the code and find out why this happens. But I was unsuccessful. So I hope you are more successful and can fix the issue @spipu ;-)
text-transform should be applied based on the current enconding.
Hi,
First merci for the HTML2PDF package.
I had a look at the source code and found out that the default font set in HTML2PDF_ParsingCss::initStyle() is set to 'Arial' at line 123, however, since HTML2PDF uses TCPDF, it is IMHO better to attempt to get the default value from the TCPDF constant PDF_FONT_NAME_MAIN, if it is set, e.g.:
--- _common/html2pdf/_class/parsingCss.class.php (revision )
+++ _common/html2pdf/_class/parsingCss.class.php (revision )
@@ -120,7 +120,7 @@
$this->value['id_lst'] = array('*'); // tag - list of legacy
$this->value['mini-size'] = 1.; // specific size report for sup, sub
$this->value['mini-decal'] = 0; // specific position report for sup, sub
- $this->value['font-family'] = 'Arial';
+ $this->value['font-family'] = defined('PDF_FONT_NAME_MAIN') ? PDF_FONT_NAME_MAIN : 'Arial';
$this->value['font-bold'] = false;
$this->value['font-italic'] = false;
$this->value['font-underline'] = false;
\ No newline at end of file
Bonjour à tous,
merci de continuer à faire vivre ce projet, je ne connaissais pas du tout et après quelques recherches sur le net, je suis tombée dessus.
Quand j'essaie d'utiliser votre class, j'ai cette erreur :
TCPDF ERROR: Some data has already been output, can't send PDF file
Voici mon code :
$html2pdf = new HTML2PDF('P', 'A4', 'fr', true, 'UTF-8');
$html2pdf->setDefaultFont('Helvetica');
$html2pdf->pdf->SetDisplayMode('fullpage');
$html2pdf->WriteHTML($tpl); // $tpl est ma chaine html
$html2pdf->Output('test.pdf');
J'utilise votre class sur un projet en local pour le moment avec Wamp. Une idée d'où ça peut venir ?
Merci.
When I try to use your class, I have this error :
TCPDF ERROR: Some data has already been output, can't send PDF file
Here is my code :
$html2pdf = new HTML2PDF('P', 'A4', 'fr', true, 'UTF-8');
$html2pdf->setDefaultFont('Helvetica');
$html2pdf->pdf->SetDisplayMode('fullpage');
$html2pdf->WriteHTML($tpl); // $tpl is my html string
$html2pdf->Output('test.pdf');
I use your php class on a local project with Wamp. Any idea where it comes from ?
Thanks.
hello, i just use html2pdf on my localhost. then open it in url localhost/html2pdf/example. then i click the qrcode.php. just show the php not directly show download message. the i tried to copy the url and paste it into the other browser and its directly show the download message. can you explain to me why?
there is currently no tag tree
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.