Is there possible to achieve writing text direction bottom-up in xmlworker? I would like to use it in table. My code is
But it it doesn't work after conversion from html to pdf. Text FIRST and SECOND are not in direction bottom-to-up.
kuujinbo
7,98322 gold badges2929 silver badges5252 bronze badges
DanielDaniel
3 Answers
This was a pretty interesting problem, so +1 to the question.
The first step was to lookup whether or not iTextSharp XML Worker supports the
HTML td tag. The mappings can be found in the source in iTextSharp.tool.xml.html.Tags. There you find td is mapped to iTextSharp.tool.xml.html.table.TableData, which makes the job of implementing a custom tag processor a little easier. I.e. all we need to do inherit from the class and override End() :
As noted in the inline comments, this is a very simple implementation for your specific needs. You'll need to add extra logic to support any other writing-mode
CSS property value, and include any sanity checks.
Based on the comment left by @Daniel, it's not clear how to add custom
CSS when converting the HTML to PDF . First the updated HTML:
Then a small snippet of custom CSS:
The slightly difficult part is the extra setup - you can't use the simple out of the box
XMLWorkerHelper.GetInstance().ParseXHtml() commonly seen here at SO. Here's a simple helper method that should get you started:
Instead of rehashing an explanation of the example code above, see the documentation (iText removed documentation, linked to Wayback Machine) to get a better idea of why you need to setup the parser that way.
Also note:
Tested with iTextSharp and XML Worker versions 5.5.9 Here's the updated result:
kuujinbokuujinbo
7,98322 gold badges2929 silver badges5252 bronze badges
Pablo G. GonzálezPablo G. González
how to render the image tags inside the table in pdf as per their table location? - @kuujinbo
Siddarth DuttaSiddarth Dutta
Not the answer you're looking for? Browse other questions tagged c#htmlasp.netitextsharpxmlworker or ask your own question.
I am trying to convert HTML to PDF with Bryan
iTextSharp in MVC Razor, but everything I have tried has not worked. Does anyone know how to accomplish this?
2,65077 gold badges3434 silver badges4040 bronze badges
RaviRavi
9 Answers
There's a detailed and
step-by-step tutorial on CodeProject you might follow. It illustrates how you could serve an ASP.NET MVC View as PDF file using iTextSharp for the conversion. Bear in mind though that iTextSharp was not meant for converting HTML to PDF so it might not cope very well with complex HTML pages and CSS styles.
Download Itextsharp DllDarin DimitrovDarin Dimitrov
865k231231 gold badges30533053 silver badges27742774 bronze badges
Here is how you implement this solution using the Razor engine NOT with the weird
<itext. markup.
This way you have full control over the pdf presentation using standard html output.
The project with an example solution and source code is available here with nuget installation instructions:
This also uses the new itextsharp licence, so does not suffer from any of the negatives mentioned in the other answers.
hutchonoidhutchonoid
28.2k1414 gold badges8383 silver badges9494 bronze badges
You should check out RazorPDF which is using iText to generate the PDF, but in a friendlier way.
Rosdi KasimRosdi Kasim
12.6k1616 gold badges8888 silver badges125125 bronze badges
just pass Vinit PatelVinit Patel
html string in to parameter that string you will get by renderpartialview text = viewname..
1,31522 gold badges1717 silver badges4343 bronze badges
A good way to convert from MVC HTML View to PDF (even if it's not directly on the subject regarding iTextSharp) is using Rotativa :
This is based on meJustAndrewmeJustAndrew
wkhtmltopdf but it has better css support than iTextSharp has and is very simple to integrate with MVC as you can simply return the view as pdf:
3,32444 gold badges2727 silver badges5353 bronze badges
Here is a complete example for MVC Razor in C# using the evo html to pdf for .net to convert the current MVC view to PDF and send the resulted PDF to browser for download:
EvoPdfEvoPdf
here you can find a different approach in case you want to write plain xml, i find it much simpler and lighter.
alexoalexo
devlin carnate
5,57977 gold badges3737 silver badges6060 bronze badges
Vivek ShuklaVivek Shukla
Itextsharp Create Pdf
In case you are using ASP.NET Core and iTextSharp is not that important to you here is my solution using PhantomJS: http://nikolay.it/Blog/2018/03/Generate-PDF-file-from-Razor-view-using-ASP-NET-Core-and-PhantomJS/37
Get HTML string from a Razor view
This step is pretty straight-forward. There is a service called
IRazorViewEngine in ASP.NET Core which can be injected and then used to get the view. After providing the view with default ViewDataDictionary and ActionContext we can request the view to be rendered into StringWriter which can be easily converted to string. Here is ready-to-use code for getting a string from given Razor view file:
One important think here: if you use view compilation (pre-compiling views to
YourProject.Web.PrecompiledViews.dll ) then it is important to get the view using the GetView method instead of FindView . More information here.
Generate the PDF file from HTML using PhantomJS![]()
For this task we are going to use a headless browser which will render the HTML (with all CSS and JS included in it). There are many such tools but I will use PhantomJS (headless WebKit scriptable with a JavaScript API). PhantomJS can save the rendered page to small-sized PDF pretty fast. For the PDF export to work we are going to need a
.js file which will use the PhantomJS API to tell the tool that we want to export the file:
The next thing is to run the
phantomjs.exe process and pass the rasterize.js file along with paths for the HTML file and the output file name for the PDF result. This is done in HtmlToPdfConverter.cs :
If you are going to deploy your application in Azure it is important to have
UseShellExecute set to true .
Use the code together
Since we now have implemented both Nikolay KostovNikolay Kostov
IViewRenderService and IHtmlToPdfConverter we can start using them by first register them in the Startup.cs file where your ConfigureServices method should be located (services.AddScoped<IViewRenderService, ViewRenderService>() and services.AddScoped<IHtmlToPdfConverter, HtmlToPdfConverter>() ). Now lets see the code wrapped up together:
9,6581818 gold badges6666 silver badges109109 bronze badges
Not the answer you're looking for? Browse other questions tagged asp.netasp.net-mvcasp.net-mvc-4itexthtml-to-pdf or ask your own question.PLEASE NOTE: iTextSharp is EOL, and has been replaced by iText 7. Only security fixes will be added
Apple product serial number lookup. We HIGHLY recommend customers use iText 7 for new projects, and to consider moving existing projects from iTextSharp to iText 7 to benefit from the many improvements such as:
iTextSharp consists of several dlls.
The main release contains:
This project is hosted on https://github.com/itext/itextsharp
You can find the latest release here:
You can also build iTextSharp from source.
We also have RUPS — a Java tool that can help you debug PDFs. It's hosted on http://github.com/itext/rups
If you have an idea on how to improve iTextSharp and you want to submit code,please read our Contribution Guidelines.
Attila total war map. iTextSharp is licensed as AGPL software.
AGPL is a free / open source software license.
This doesn't mean the software is gratis!
Buying a license is mandatory as soon as you develop commercial activitiesdistributing the iText software inside your product or deploying it on a networkwithout disclosing the source code of your own applications under the AGPL license.These activities include:
Contact sales for more info: http://itextpdf.com/sales
Re: Convert html to pdf using iTextSharp
May 05, 2008 02:05 PM|DonChino|LINK
Ok? I guess if any other dumbasses are out there, please make sure you have the following at the top:
using iTextSharp.text; using iTextSharp.text.html; using iTextSharp.text.pdf; Seems I forgot the HTML one which is why I could not see HtmlParser, but I found this on my one although I swore I had it. Ugh, always double check your declarations so I hope this helps other idiots like me.. :)
ORIGINAL POST:
I think what he wants to say is that this does not work because HtmlParser does not seem to be part of iTextSharp. I keep seeing various examples floating around online about converting HTML to PDF but they allO reference HtmlParser which does NOT seem to exist within iTextSharp so where is this coming from? Do we have to install something else? Let me know, thanks..
To clarify before people start to say that HtmlParser is within iTextSharp.. I am using the .NET version from http://sourceforge.net/projects/itextsharp/ so this is NOT THE JAVA version but the .NET VERSION and it does not seem to have HtmlParser, so can someone explain to me if I am doing something wrong?
Comments are closed.
|
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |