Itextsharp and css - c#

I am using iTextSharp to generate a pdf invoice.
I have a template for the invoice which is very simple, but uses CSS3 for the formatting and styling.
when I display the page in a browser it works fine, but when I try to generate the page into a pdf using itextsharp it seems to ignore all the CSS3 formatting for some reason.
My question is: Is there a way to get it to work with CSS? Or is that a limitation of iTextSharp ?

Are your stylesheets linked with an absolute path or a relative one? PDF converters don't tend to work too well with relative paths.

Related

C# OpenHtmlToPdf missing styles

I'm using OpenHtmlToPdf to convert a html file to a pdf file. This works, but it doesn't support css grid and also doesn't render the svg which is embedded in the html file.
Do you have an idea of how fix this or know any alternative libraries which support svgs and css grid?
Best regards

Convert asp.net page to Word document

I have built several PDF documents dynamically from ASP.NET pages (HTML/CSS) using plugins like Winnovative HtmlToPDFconverter. It has always been a successful outcome using the built-in functionality for those plugins, like merging existing PDF documents with dynamic content and adding pre-defined headers and footers, adding page margins, page numbers and so forth. The HTML content has overall been rendered as expected in the final PDF document(s).
Is there any way/any advice for a similar .NET plugin that can render HTML/CSHTML to a Microsoft Word document (.docx) in the same way – or is it too difficult to render native HTML5 and CSS into a desirable layout for a Microsoft Word Document?
I have googled around and found some suggestions, but I'm looking for recommendations for maybe a specific plugin – or a warning if it is a no-go
and too difficult to get the desired layout 1:1 from HTML to a Word document because of incompatibility between markups?
Devexpress HTML editor can export its HTML content to different formats including docx and rtf. Not sure about its limitations (e.g. script and canvas export, etc.), but in the common case it works well.

Page counter for HTML Renderer for PDF using PDFSharp

I would like to put the page number of each page of a pdf file generated by HTML Renderer for PDF using PDFSharp which is an amazing plugin using PDFSharp and giving the possibility to render a pdf file from html string, moreover it supports CSS 2 to style the generated pdf.
Thanks to this pull request, which is available in the beta version, it is possible to have a proper paging with elements not being cut when they are taller than the page format.
I tried using this in the css:
.footer:after
{
counter-increment: page;
content: counter(page);
}
with no success (the footer being in a fixed position). I would like to know if someone achieved a proper page count with this plugin or if someone knew another way.
I already tried to simulate the pages count the document would take but the styling in browser is quite different from the generated pdf file (lines height, margins management, etc).

Maintain CSS styling when converting HTML to Docx in ASP.NET

I am trying to convert HTM to docx without using interop dll. I have tried with Dynamically generate a MS Word document using HTML & CSS and also with Html to OpenXml.
I don't find a way to convert with HTML to Docx with all the styles and images intact. Openxml does support styles but only when styles are inline. If I have the styles defined in CSS file then the styles does not get reflected.
What alternative can I go for to achieve this?
Queston 1 - Preserve Styling
Pre-process the HTML to inline the styles from the css file before using html2openxml to convert the document.
Question 2 - Preserve Images
Images are supposed to work in that converter according to here http://html2openxml.codeplex.com/wikipage?title=ImageProcessing&referringTitle=Documentation
maybe you need to debug this a bit / post more info
Edit
Maybe you forgot to set the base path
converter.BaseImageUrl = new Uri("http://myserver:8080/");

Convert webpage to PDF document using ASP.NET C#

Is it possible to convert a webpage along with images and preserving styles into PDF document using open libraries like iTextSharp using C#.
Yes but.
iText[Sharp]'s style support is spotty at best. Your absolute best html->pdf bet is wkhtmltopdf. I haven't tried it personally, but it seems to have all its ducks in a row.

Categories