Winnovative Html to PDF converter not rendering font-face fonts - c#

I'm using Winnovative's Html to PDF converter to print my page to PDF.
// Get a PDF of the URL.
Document document = new Document();
//document.LicenseKey = PDFUtility.LicenseKey;
PdfPage page = document.Pages.AddNewPage(PdfPageSize.A4, new Margins(10, 10, 0, 0), PdfPageOrientation.Portrait);
HtmlToPdfElement pageToPrint = new HtmlToPdfElement(sURL);
page.AddElement(pageToPrint);
// Setup response
context.Response.ContentType = "application/pdf";
context.Response.AddHeader("Content-Disposition", string.Format("attachment; filename ={0}", sPage + ".pdf"));
document.Save(context.Response.OutputStream);
My header tags have a font face on them. This works fine locally and renders with the custom font. However on my dev and test servers it does not render the header tags at all. It does leave space where the header tags should be.
When we changed our headers to Arial the PDF renders with the headers in all environments.
We've checked permission on the font files (set permissions to full control for everyone). That didn't change anything.
Something to do with the font face is not working on our server and we can't figure out what.

You have to check if your font files are accessible in a browser from the server itself. Put your HTML code in a HTML file and open that file from the test server in a browser. If the HTML file is displayed well in browser it should be rendered well in PDF too.
You should also make sure that the IIS from the server has the ttf or woff (not sure what exactly you reference in #font-face) set in accepted MIME types, otherwise these files will not be served by web server.

I had a similar problem showing web fonts in my solution as well.
It turns out that woff2 fonts did not get rendered at all.
Once I switched to the woff file format, everything worked as expected.
From what I saw, there is no setting that I haven't enabled in the converter, so I guess woff2 is not supported.

Yes, you have to make sure the font files are enabled in your web server MIME types. Winnovative HTML to PDF converter works well with all types of we fonts. There is a complete example with C# and HTML code using #ont-face rules in Convert HTML with Web Fonts to PDF demo .

Related

Sautfinsoft PDF Focus .Net Converter text issue

So I've been trying to use SautinSoft software to convert a pdf document to a docx document. However, whenever I run this code my word document ends up having squished text. I've attached the images below, any idea what is going on?
SautinSoft.PdfFocus f = new SautinSoft.PdfFocus()
f.OpenPdf(#source);
if (f.PageCount > 0){
string path = Path.ChangeExtension(source, ".docx");
f.WordOptions.Format = SautinSoft.PdfFocus.CWordOptions.eWordDocument.Docx;
f.ToWord(#path);
}
This is a docx file after conversion. The image rendered fine, but the text is all squished for some reason. I'm also running on macOS (if that makes a difference). Thank you for anyone that can help!
I found the answer. You have to make sure to set
f.WordOptions.KeepCharScaleAndSpacing = false;
Because by default, the converter will scale the font widths based on the PDF fonts rather than your default word doc fonts.
Just load your fonts which you are using in the PDF in "C:/Windows/Fonts" and reboot your PC.
Then to convert your PDF to WORD again.
If it doesn't work for you. Try to use an another way. Specify the path to your folder's font for PDF Focus like :
f.WordOptions.Fonts = D:/Fonts;

Create PDF from HTML using TheArtOfDev.HtmlRenderer.PdfSharp

I need to convert a well-formatted HTML string to a PDF document.
I found this DLL that should do what I need, but it isn't working fine on formatting.
That's the HTML code I'm trying to convert, and viewing it on browser works fine (I've used Bootstrap CSS, that's been correctly referenced as cdn).
But once converted to PDF this is the result:
And that's the code I'm using to convert it:
string html = "";
if (File.Exists(pathIN))
{
html = File.ReadAllText(pathIN);
}
PdfDocument pdfDocument = new PdfDocument();
PdfDocument pdf = PdfGenerator.GeneratePdf(html, PageSize.A4, 60);
pdf.Save(pathOUT);
Does anyone have any suggestion?
I also had issues with this when using HtmlRenderer/PdfSharp with Bootstrap controlling the layout.
Although it goes against the grain, I resorted to using tables for the layout. Given that the destination (pdf) was a obviously a fixed width, being responsive was not a requirement.
Try using https://wkhtmltopdf.org, works well for bootstrap pages.
I know its a little late but this can help someone
The problem with bootstrap is that to align the columns use float: left and pdfsharp cannot read this property instead use display: inline-block and define the width in pixels.
To avoid useless effort to other people, it doesn't work for Bootstrap like the Table even using display: inline-block to define the width. Right side of table is always trimmed, the size unfitting the letter size in my case.

PDF Clown does not render text

I use PDF Clown to create PDF files containing text and different shapes. Saving the files brings the desired result. But when I print the pages or render them to bitmaps, only the shapes are visible and the text elements are missing.
I tried already different versions of the library with multiple files, always getting the same result.
Maybe someone can give me a hint on this issue.
EDIT:
This is a simplified form of the source code I use (with same result as described above; see the image at the end):
File file = new File();
Document document = file.Document;
document.PageSize = PageFormat.GetSize(PageFormat.SizeEnum.A4, PageFormat.OrientationEnum.Portrait);
Page page = new Page(document);
document.Pages.Add(page);
PrimitiveComposer composer = new PrimitiveComposer(page);
//draw a rectangle
composer.SetFillColor(DeviceRGBColor.Get(System.Drawing.Color.LightSalmon));
composer.DrawRectangle(new RectangleF(30, 42, 300, 32));
composer.Fill();
//draw some text
composer.SetFillColor(DeviceRGBColor.Get(System.Drawing.Color.Black));
composer.SetFont(new StandardType1Font(document, StandardType1Font.FamilyEnum.Courier, true, false), 32);
composer.ShowText("Hello World!", new PointF(32, 48));
composer.Flush();
//save the file
file.Save(#"..\document.pdf", SerializationModeEnum.Standard);
//and print it
Renderer renderer = new Renderer();
renderer.Print(file.Document, false);
Result of the above code (the printed version was created with virtual printer Adobe PDF; also tested with XPS Document Writer):
(I don't have enough points to add a comment so I put this comment as an answer.) If you look in the source for the RenderingSample class, you will see this comment:
This sample demonstrates how to render a PDF page as a raster image.
Note: rendering is currently in pre-alpha stage; therefore this sample is
nothing but an initial stub (no assumption to work!).
I don't think Stephano Chizzolini got around to finishing it.
There is another NuGet download, PDFClown.Net version 2.0.0, by Matthieu. It has tags for PDF-To-Image, Rasterizer and PDF, but I have not been able to get it to work either. I cannot find documentation for it. Inspection of the properties for the downloaded NuGET assembly shows version 0.1.2.0 instead of 2.0.0.

set html img src from byte array

I am working on an email client application in C#.
I want to display an html email on the page with embedded images.
Now, I use a div and set mail bodyhtml to div innerhtml property.
I have a problem with display embedded images.
I know everything about embedded images (content-type, name, content-id, base64string or byte[] as content)
I used image data uri, but unfortunately it is not too perfect, for example (ie8-32KB limitation).
I tried to ihttphandler as imagehandler, but it is not run on a simple postback, when I set div inner html.
I don't want to save these images on the server.
Any idea or suggestion?
Sorry, my english is not too good.
Thanks.
For doing this, you would need to do something like:
(In your .ashx file)
Response.ContentType = "image/png";
Response.BinaryWrite( <bytes> );

Preview the text contents from HtmlEditor control(ajax) on A4 size paper and save it as .txt

I am doing asp.net project using C#.I want to display the contents that are being typed in HtmlEditor control onto a A4 size as preview and i also want to save this content to a file(.doc or .txt).
How do i do it??
Please help
You can bind html editor content in variable and then display variable in client side.
server side:
Private static string abc=string.empty;
abc=htmlcontrolname.content;
databind();
on client side:
<%= abc%>
Set page size
There is no way with JavaScript, HTML, CSS currently to set the page size for printing. It is in the CSS spec, but there is very limited support for it.
Save file
There is no IO in JavaScript. The best bet is to send the content to the server and return headers that force a downoad of the file.

Categories

Resources