itext7/html2pdf: Inline image not aligned with text in generated PDF, but is in HTML - itext

I want to generate a PDF from input that contains LaTeX math markup. So I am converting the math markup to png images (using jlatexmath) and inserting them as base64 encoded inline images in an HTML document, which is then converted to PDF using itext7/html2pdf.
The HTML version is aligned correctly:
However the PDF version is not:
The HTML looks like this:
<p>Here is an example using LaTeX math: <img
src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAHgAAAAdCAIAAADuPz9sAAAFqUlEQVR4Xu2ZXUiUWxSGu4huFb3ySooUrxQUbS4K80pBBX8QFS1BiMKEskBLUVFRkeOgUVqgRKBS9gtqRlNJYJTY0cZGzZ8KRXMMsTBTLB2+8zL7zJ496/uZ0dP5xgufi2F/7946r8u911p7Zp+0hy7so8KOMJvNVNo17BJvWoGem5uLiIj4/v07nXDFaDR+/vyZqrsGeINDquqOVqBBRkYGlVx5/PhxW1sbVR2cOHEiKytLsv+1JpOptbX1zp07dNH/Dxw+efKEqvqiFej19fXc3FyqCmxsbCQlJVHVgcViQaDDw8Mxttls+Je8f/8eA7pOF5KTk+GWqjqiHOgHDx48evSopqamqamJzglcvXq1vb2dqg7KysrwS6xWK8bYyA0NDW/fvp2dnaXrdAE+4ZaqOqIQaBzz/Px8DOrq6oaGhui0QFRU1NraGlUdHD9+fGlpiapeAj4jIyOpqiMKgcZG7urqwiA7O3tzc5NOOxgfH4+Li6OqA/xgSEgIVb1KbGzs6OgoVfVCIdCXL1+enp5GpFJSUkZGRui0gytXrhQXF1PVwfDwcHx8PFW9yqVLlxobG6mqFwqBfvfuHdqD7u7uCxcu4JVOOzh58uS9e/eo6uD69euFhYVU1WRgYOD06dMdHR3s8ePHj8+ePXNdIvX393/58oWIDLfNaGdnJzxT1WNEe4reJE17CoH2kCNHjoyNjVHVAdqVmzdvUlUTRIFnqq2trfPnz7vO/4tGTdNuRnE6DQYDVT2G29PwJqnb23mgDx8+PD8/T1UHYWFh2AJU1SQ1NZWP0fbcvn1bmHSCKZw5qnrQjM7MzAQFBVHVY7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i3L+AOB3sMT9gKtE3uB1ol/ADKVewttxwYlAAAAAElFTkSuQmCC"/>.
And here is another: <img
src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEIAAAAPCAIAAADf8I4NAAAB6klEQVR4Xt2WTatBQRjHfQzfAR/AZ7CwUUpethYWslXeyurSRRZeUyiSnQVSslAKSRZessGCjY1IeYn7dM69g2fOPY6bW+79rWae/8zT/OeZmXNE53+BiLT0en0sFruSXpp4PK7T6Uj3YkMikZA2odFo2Gy2brebzWaxJphfSnK94Ds2JpNJMplstVrlchlrDIPBAIco7iYRAp3kARu5XG4+n8Nhq9VqWGOQSqU4RHE3iRDoJHw2jsdjpVLxeDz5fN5kMo1GIzKAE9r8cDgMh8PsnkEGpD4EbL9KpXI6nZyXls9Gr9c7HA7pdDqTyTSbze12SwZwQtvodDrRaBRsrNdrjUaDVAK4fb/F5/OtVis0DCqgVqv3+z2Kn/ltsJjN5ul0Sro0gUDgjUEsFrMNv99/Op1YVavV7na7arUKw27nPQa4UiqVi8UCCwx8NtrtNkxWKBTQrtfrRP0OuhoAWwS32w2VwdoX/X6f9U/wer3X1YBNgTzwhEBwPB5fTf2Ez4bVak2lUna7HfaSZxEEThsul6tUKsnlcrhpWBMMXE6Hw2EwGIxG4w8PlXBkMhmKJBKJQqGwXC4tFguSnsszbcxmMxSB71SxWAwGg5vNBknPhdsG/IyEQiHSfXEikQg8JKR7sfGn+Sc2PgBzdMQ49YHi+gAAAABJRU5ErkJggg=="/>.
</p>
and the CSS contains:
img {
vertical-align:middle;
}
Any idea how to make it align in the PDF version?

Related

convert html to pdf i angular 5

I must be convert html elements to PDF, but I don't want to use html2canvas, because this package convert html image at first, then convert to pdf. this way didn't efficient for my needs.
I used latest version of jspdf ( 1.5.3, that said support built in Unicode and utf-8 characters) with jspdf-autotable.
all things worked, except Persian character that corrupted.
do I must any setting for Unicode characters in last version of jspdf?
I must be use custom font? or default setting built in support Unicode characters?
I read all article about this issue, and run it, but I didn't solve my problem
Try to use html2pdf library for properly export unicode and Persian/Arabic characters.
The html code must be convert to canvas in first step and then convert to pdf.
function export_to_pdf() {
// Get the element.
var element = document.getElementById('root');
// Generate the PDF.
html2pdf().from(element).set({
margin: 0,
filename: 'test.pdf',
html2canvas: { scale: 1},
jsPDF: {orientation: 'portrait', unit: 'in', format: 'a4', compressPDF: true}
}).save();
}

Using mpdf PDF document do not display unicode symbols

I am using mpdf for generating pdf. And the problem is with unicode character.
For example I have:
<tr>
<td>□ Yes</td>
<td>☑ No</td>
</tr>
When PDF is generating I have the same view instead of normal symbols.
□ Yes
☑ No
I am initialising mPDF and passing in the HTML like that:
$mpdf=new mPDF('lt','A4','','',5,5,10,5,1,1);
$mpdf->WriteHTML($css, 1);
$mpdf->WriteHTML($html);
$mpdf->Output($pdf_filename, $pdf_destination);
What can be wrong with unicode encoding?

Put highlighted code in a word document using Apache POI

I'm generating some docx file (using Apache POI) that has a lot of SQL code in it. Because I'd like that code to be colored in a Word document, I'm first generating HTML with styles that does syntax highlighting. Now I can't put that HTML in a Word document. Is that even possible (using POI)?
What I'd like to achieve is SQL code in a docx being colored based on a generated HTML (like exporting SQL code from Notepad++ as HTML and pasting it in a Word document). Any ideas?

converting html to text with perl

I have a bunch of html files and need to convert and format them to text with perl i.e somthing like <br/> will be interperted to \n
I found this perl module on cpan html::formattext it format the text well but if there is link it strip it ,
are there any option with HTML::FormatText to format the html as is to text but when
there links like this
<a href="http://www.microsoft.com>http://www.microsoft.com</a>
i.e somthing like this :
<br /><b>Microsoft</b><br /><a href="http://www.microsoft.com>`
will be converted to:
microsoft
http://www.microsoft.com
Take a look at HTML::FormatText::WithLinks
Setting the after_link option to, say, " (%l)" will put the link in line after the anchor text. In your example you would get Microsoft (http://www.microsoft.com).

Perl PDF line by line Parser?

I have a pdf, consists only of text, with no special characters nor images etc.
Is there any Perl module out there (Been looking at cpan to no avail) to help me parse each page line by line?
(Converting the PDF to text yields bad results and unparsable data)
Thanks,
When I want to extract text from a PDF, I feed it to pdftohtml (part of Poppler) using the -xml output option. This produces an XML file which I parse using XML::Twig (or any other XML parser you like except XML::Simple).
The XML format is fairly simple. You get a <page> element for each page in the PDF, which contains <fontspec> elements describing the fonts used and a <text> element for each line of text. The <text> elements may contain <b> and <i> tags for bold and italic text (which is why XML::Simple can't parse it properly).
You do need to use the top and left attributes of the <text> tags to get them in the right order, because they aren't necessarily emitted in top-to-bottom order. The coordinate system has 0,0 in the upper left corner of the page with down and right being positive. Dimensions are in PostScript points (72 points per inch).