Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.

Sun Apr 24, 2016 2:38 pm

Just been looking at Spire PDF as a solution for a major client of mine and have run into a few issues, before I discount the product as a viable solution I thought I would ask, in case I'm doing something wrong.

My aim is to generate a PDF from an HTML page (some .aspx and some via MVC Razor).

When I have tried this using the standard Spire.PDF.LoadFromHTML the quality of the PDF is, quite frankly, awful. The text is burred and of very poor quality, unlike the original.

I tried the new version HtmlConverter.Convert which works much better and is very clear and accurate to the original.

However, I wish to generate the resulting PDF as a Memory Stream or Byte array. I do not want to generate physical PDF files on the server. With the new process I can't find any way to do this, it only seems to generate to a physical file on the server. Therefor I will run into issues if multiple users create the same file at the same time unless I name the files uniquely and then I would get a huge number of files building up.

Am I missing something here...
a) Does the standard method have a was of improving the quality of the PDF?
b) Does the new method have a "SavetoStream" option?

Many thanks
Simon

simonmaltby
 
Posts: 1
Joined: Sun Apr 24, 2016 9:37 am

Mon Apr 25, 2016 7:07 am

Hello Simon,

Thanks for your posting.
Sorry for the inconvenience that the quality issue of LoadFromHtml method brought to you. At present the direct converting HTML to Stream or byte array method by HtmlConverter.Convert has not been supported but we have added it as new feature into our schedule. I provide you a solution as below to convert to byte array and it is to generate random file name and then delete it at last.
Code: Select all
string temp = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()) + ".pdf";
            HtmlConverter.Convert("https://www.wikipedia.org/", temp,

                //enable javascript
                true,

                //load timeout
                100 * 1000,

                //page size
                new SizeF(612, 792),

                //page margins
                new PdfMargins(0, 0));

            byte[] data = File.ReadAllBytes(temp);
            Response.ContentType = "application/pdf";
            Response.OutputStream.Write(data, 0, data.Length);
            Response.Flush();
            Response.Close();
            File.Delete(temp);


Sincerely,
Caroline
E-iceblue support team
User avatar

caroline.zhang
 
Posts: 291
Joined: Mon Mar 07, 2016 9:22 am

Mon Apr 25, 2016 7:44 pm

Hi There,

I have the same problem as the OP, but using the HtmlConverter is not giving me any better text quality at all. It's exactly the same, the text is still too blurry. What am I doing wrong?

Code: Select all
            // Generate the PDF from the html
            string pdfFilename = string.Format("C:\\temp\\{0}.pdf", order.OrderId);
            var doc = new PdfDocument();
            doc.CompressionLevel = PdfCompressionLevel.None;                                 
            var layout = new PdfTextLayout();                       
           
            // doc.LoadFromHTML(html, false, set, layout);                       
           
            var converter = new HtmlConverter();           
            var result = converter.Convert(html, pdfFilename, ImageType.Metafile, 640, 800, AspectRatio.FitPageSize);                       
            result.Render(doc.AppendPage(), layout);
            doc.SaveToFile(pdfFilename, FileFormat.PDF);


Thanks.

[email protected]
 
Posts: 3
Joined: Mon Apr 25, 2016 7:41 pm

Tue Apr 26, 2016 6:31 am

Hi,

Thanks for your posting.
There is some wrong with your code and you don't use HtmlConverter.Convert method correctly.
Please follow the below tutorial to try again.
http://www.e-iceblue.com/Tutorials/Spir ... lugin.html

If you still have the issue after trying, please share us your html for investigation. If it is inconvenient to attach it here, you can send it to [email protected].

Best Regards,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 3043
Joined: Wed Jun 27, 2012 8:50 am

Tue Apr 26, 2016 4:33 pm

Hi, thanks for the information. This works much better.

It seems I have one last hurdle. My image appears in the HTML file that I have generated (from XML and XSLT) but the image is lost once I render the PDF. I have a very simple image tag in the HTML.

Code: Select all
<IMG src="D:\Release\Service\Logo.bmp"/>

[email protected]
 
Posts: 3
Joined: Mon Apr 25, 2016 7:41 pm

Tue Apr 26, 2016 4:51 pm

Please ignore my previous post. It works fine with a properly formed URL.

Thanks!

[email protected]
 
Posts: 3
Joined: Mon Apr 25, 2016 7:41 pm

Wed Apr 27, 2016 1:53 am

Hi,

Thanks for your reply.
Welcome to write to us again for further problems.

Best Regards,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 3043
Joined: Wed Jun 27, 2012 8:50 am

Return to Spire.PDF