Synopse Open Source - Tag - htm2pdfmORMot MVC / SOA / ORM and friends2024-02-02T17:08:25+00:00urn:md5:cc547126eb580a9adbec2349d7c65274DotclearBetter Unicode support in Reports and PDF generationurn:md5:e03e8e0a802691d2752b1c65b11dbffa2012-07-10T23:44:00+02:002012-07-10T23:44:00+02:00AB4327-GANDIOpen Source librariesDelphiGDIGDIPlushtm2pdfi18nmORMotPDFSourcestringTrueTypeUnicodeUniscribe<p>By default, both GDI+ anti-aliased drawing and PDF file generation
using our libraries did lack of <em>font-fallback</em> implementation.</p>
<p>If some of the characters in a string are not supported in a requested font,
they were drawn as square symbols on the GDI+ canvas or the PDF content.</p>
<p>The <em>font-fallback</em> mechanism implemented will use a third-party font
(<em><a href="http://en.wikipedia.org/wiki/Arial_Unicode_MS">Arial Unicode
MS</a></em> by default, which is installed with <em>Microsoft
Office</em>), for any glyph that are missing when rendering the content. Of
course, for PDF generation, you are able to embed the font within the generated
file (this is by the way mandatory for <a href="https://blog.synopse.info?post/post/2011/02/08/Synopse-PDF-Engine-1.12">PDF/A-1</a> format).</p>
<p>Both of these new features are handled by the <code>SQlite3Pages</code>
unit, i.e. for report anti-aliased drawing preview and PDF generation.</p>
<p>By the way, the <code>TGDIPages</code> class itself (the one used for
<a href="https://blog.synopse.info?post/post/2010/06/30/Making-report-from-code">report generation from
code</a>) now handles by default <em>Unicode</em> text, even with Delphi
versions prior to 2009 (via the <code>SynUnicode</code> string type, which maps
<code>WideString</code> before Delphi 2009, then <code>UnicodeString</code>
starting with Delphi 2009). Does make sense with such
a <em>font-fallback</em> mechanism.</p> <p>The following modifications have been committed:</p>
<ul>
<li>New <code>TPdfDocument.UseFontFallBack</code> property (enabled by default)
and associated <code>FontFallBackName</code> property (set to '<em>Arial
Unicode MS</em>' by default), used to define if the PDF document will handle
"font fallback" for characters not existing in the current font: it will avoid
rendering block/square symbols instead of the correct characters (e.g. for
Chinese text);</li>
<li>New <code>TGDIPlusFull.ForceUseDrawString</code> property for properly
handling font fall-back if needed when drawing text (disabled by default), and
corresponding parameter in <code>DrawEmfGdip()</code> function;</li>
<li>Now implements font fall-back in internal Anti-Aliaised drawing of
<code>TGdiPages</code>, if the new ForceInternalAntiAliasedFontFallBack
property is set to TRUE.</li>
</ul>
<p>In fact, the EMF to EMF+ conversion routine included in GDI+ 1.1 is not able
to implement <em>font-fallback</em> (and text underlining, by the way).<br />
Our Delphi-based conversion code sounds definitively better than the original!
That is the reason why our internal code is enabled by default, instead of GDI+
1.1 <code>GdipConvertToEmfPlus</code> API call.</p>
<p>I think it is perhaps now time for a 1.17 release of our <em>mORMot</em>
units, as a bug-fix version.</p>
<p>Comments <a href="http://synopse.info/forum/viewtopic.php?pid=4650#p4650">are welcome on our
forum</a>!</p>htm2pdf free toolurn:md5:5ea939fb6312eaf00fbec568dc6e80722010-07-14T19:07:00+02:002011-01-23T12:48:54+01:00AB4327-GANDISynopse PDF engineblogDelphiGIFhtm2pdfPDFPNGSynopse<p>Using our SynPDF library and a public domain THtmlView component, and
discussion with some of our users, we were able to make a html to pdf
conversion tool.</p> <p>After <a href="http://synopse.info/forum/viewtopic.php?id=34">a discussion
with Pawel Stroinski</a> on our forum, the THtmlView component was used to make
a tool converting any html document into pdf, i.e. "printing" a html document
as a pdf.</p>
<p>I downloaded via SVN the <a href="http://code.google.com/p/thtmlviewer/">latest THtmlView source code available
from the successor of the well-known HTMLViewer components for Delphi</a>
(previously sold by <a href="http://www.pbear.com">PBear.com</a>), i.e.
r36.</p>
<p>Then I compiled it under Delphi 7. Some errors in the code. I therefore
fixed them. Then try to compile under Delphi 2010 - a lot of warnings, and some
main feature not working as expected (like css support). Fixed most bugs, and
made a lot of code refactoring - a lot of warning remains, and the component is
not truly Unicode: THtmlView use internaly UTF-8 encoding. But it works better
than the original version.</p>
<p>Then I used Pawel Stroinski's code using our <a href="http://synopse.info/forum/viewforum.php?id=1">SynPdf</a> unit to produce a pdf
file from any html content.</p>
<p>Some bitmaps where not printed: fixed some part of the <em>SynPdf</em>
library (now in version 1.8.3 in our source code repository).</p>
<p>And since the code from THtmlView did rely on jpeg.pas and was handling PNG
just with Delphi 2010, I added a compilation define (set by default) in order
to use our <a href="http://synopse.info/forum/viewforum.php?id=4">SynGdiPlus</a> library to read
GIF, PNG and JPEG files. So the resulting executable is smaller in size (less
than 890 KB), and work as expected. If you don't like all this, and need GIF
animated in your PDF (??? it's a joken pdf doesn't allow this), you can turn
the compilation define OFF, and use the previous code.</p>
<p>I've uploaded the source code in the <em>HtmlView</em> sub directory of our
<a href="http://synopse.info/fossil">Source Code Repository</a>.</p>
<p>You can download an executable file from<br />
<a href="http://synopse.info/files/pdf/htm2pdf.zip">http://synopse.info/files/pdf/htm2pdf.zip</a></p>
<p>Just extract the htm2pdf.exe file in a directory, then launch it:<br />
<br />
<a href="http://synopse.info/files/pdf/htm2pdf.png"><img src="http://synopse.info/files/pdf/htm2pdf.png" alt="" width="413" height="282" /></a><br />
<br />
Click on the "Open" button to open a html file, then browse it on the screen,
update the parameters below (like margins or paper size), and click on the
"Save as" or "Save" buttons.<br />
A pdf file will be created, containing the whole html content, together with
the files.</p>
<p>As a demo, I included in the <em>HtmlView/demo</em> sub directory of our
<a href="http://synopse.info/fossil">Source Code Repository</a> some html, css
and picture files. </p>
<p>You can download the resulting pdf from <a href="http://synopse.info/files/pdf/sample.pdf">http://synopse.info/files/pdf/sample.pdf</a></p>
<p>This <em>htm2pdf</em> tool can be used from the command line, without the
GUI window above:</p>
<p>1. you'll observe that the last used parameters are saved in a
<em>htm2pdf.ini</em> file in the same directory than the executable.</p>
<p>If you launch</p>
<div class="codebox">
<pre>
<code>htm2pdf /silent</code>
</pre></div>
<p>all parameters from htm2pdf.ini will be used, no GUI will be displayed, and
the conversion will be made.</p>
<p>2. you can force to specify a html source file name, and an optional
destination pdf file:</p>
<div class="codebox">
<pre>
<code>htm2pdf sample.htm</code>
</pre></div>
<p>will create a <em>sample.pdf</em> file in the same directory as
<em>sample.htm</em></p>
<div class="codebox">
<pre>
<code>htm2pdf sample.htm dest.pdf</code>
</pre></div>
<p>will create a <em>dest.pdf</em> file</p>
<p>This tool is released under the Public Domain, free but with no warranty at
all.</p>
<p><strong>Discussion and comments are welcome on our
forum:<br /></strong><a href="http://synopse.info/forum/viewtopic.php?pid=187"><strong>http://synopse.info/forum/viewtopic.php?pid=187</strong></a></p>