{"id":41,"date":"2011-03-02T21:42:00","date_gmt":"2011-03-02T19:42:00","guid":{"rendered":"http:\/\/dev.bratched.fr\/en\/?p=41"},"modified":"2011-03-02T21:42:00","modified_gmt":"2011-03-02T19:42:00","slug":"how-to-convert-xhtml-to-pdf-in-c","status":"publish","type":"post","link":"https:\/\/bratched.com\/en\/2011\/03\/02\/how-to-convert-xhtml-to-pdf-in-c\/","title":{"rendered":"How to convert XHTML to PDF in C#"},"content":{"rendered":"<p><a href=\"http:\/\/dev.bratched.fr\/en\/wp-content\/uploads\/sites\/3\/2011\/03\/todelka219711619951.png\">\u00a0<\/a><\/p>\n<p>In this blog post I will illustrate how you could convert an XHTML page into PDF using the <a href=\"http:\/\/code.google.com\/p\/flying-saucer\/\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">flying-saucer<\/a> library. This is a Java library so we need to first step would be to convert it to a .NET assembly.<\/p>\n<p>I will use the <a href=\"http:\/\/www.ikvm.net\/userguide\/ikvmc.html\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">IKVM.NET Bytecode Compiler (ikvmc.exe)<\/a> for this purpose. So go ahead and download both the flying-saucer library and the IKVM project. Then run the following command:<\/p>\n<pre class=\"lang:default decode:true\">ikvmc.exe -target:library -out:CoreRenderer.dll iText-2.0.8.jar core-renderer.jar<\/pre>\n<p><!--more--><\/p>\n<p>This will generate the CoreRenderer.dll assembly which could be used. And finally we would create an application which would use it inside a console application:<a href=\"http:\/\/dev.bratched.fr\/en\/wp-content\/uploads\/sites\/3\/2011\/03\/sourcecode395858614.png\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-127\" src=\"http:\/\/dev.bratched.fr\/en\/wp-content\/uploads\/sites\/3\/2011\/03\/sourcecode395858614.png\" alt=\"sourcecode395858614\" width=\"858\" height=\"517\" srcset=\"https:\/\/bratched.com\/en\/wp-content\/uploads\/sites\/4\/2011\/03\/sourcecode395858614.png 858w, https:\/\/bratched.com\/en\/wp-content\/uploads\/sites\/4\/2011\/03\/sourcecode395858614-300x181.png 300w, https:\/\/bratched.com\/en\/wp-content\/uploads\/sites\/4\/2011\/03\/sourcecode395858614-768x463.png 768w\" sizes=\"(max-width: 858px) 100vw, 858px\" \/><\/a><\/p>\n<p><a href=\"http:\/\/dev.bratched.fr\/en\/wp-content\/uploads\/sites\/3\/2011\/03\/sourcecode395858614.png\">\u00a0<\/a><\/p>\n<p>One last step is to ensure that you have referenced the following assemblies:<\/p>\n<p><a href=\"http:\/\/dev.bratched.fr\/en\/wp-content\/uploads\/sites\/3\/2011\/03\/todelka1267959470.png\">\u00a0<\/a><a href=\"http:\/\/dev.bratched.fr\/en\/wp-content\/uploads\/sites\/3\/2011\/03\/todelka1267959470.png\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-128\" src=\"http:\/\/dev.bratched.fr\/en\/wp-content\/uploads\/sites\/3\/2011\/03\/todelka1267959470.png\" alt=\"todelka1267959470\" width=\"219\" height=\"222\" \/><\/a><\/p>\n<p>Those assemblies are part of the IKVM project and have dependencies on many other assemblies that are included with it. So the final folder should contain all those:<\/p>\n<p><a href=\"http:\/\/dev.bratched.fr\/en\/wp-content\/uploads\/sites\/3\/2011\/03\/todelka219711619951.png\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-130\" src=\"http:\/\/dev.bratched.fr\/en\/wp-content\/uploads\/sites\/3\/2011\/03\/todelka219711619951.png\" alt=\"todelka21971161995\" width=\"565\" height=\"272\" srcset=\"https:\/\/bratched.com\/en\/wp-content\/uploads\/sites\/4\/2011\/03\/todelka219711619951.png 565w, https:\/\/bratched.com\/en\/wp-content\/uploads\/sites\/4\/2011\/03\/todelka219711619951-300x144.png 300w\" sizes=\"(max-width: 565px) 100vw, 565px\" \/><\/a><\/p>\n<p>And that\u2019s pretty much all. When you run the console application it should generate the output PDF file.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u00a0 In this blog post I will illustrate how you could convert an XHTML page into PDF using the flying-saucer library. This is a Java library so we need to first step would be to convert it to a .NET assembly. I will use the IKVM.NET Bytecode Compiler (ikvmc.exe) for this purpose. So go ahead [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[263,266],"tags":[297,308,327],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/bratched.com\/en\/wp-json\/wp\/v2\/posts\/41"}],"collection":[{"href":"https:\/\/bratched.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/bratched.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/bratched.com\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/bratched.com\/en\/wp-json\/wp\/v2\/comments?post=41"}],"version-history":[{"count":0,"href":"https:\/\/bratched.com\/en\/wp-json\/wp\/v2\/posts\/41\/revisions"}],"wp:attachment":[{"href":"https:\/\/bratched.com\/en\/wp-json\/wp\/v2\/media?parent=41"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/bratched.com\/en\/wp-json\/wp\/v2\/categories?post=41"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/bratched.com\/en\/wp-json\/wp\/v2\/tags?post=41"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}