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.

Mon Jun 11, 2018 5:34 pm

Second attempt.

Side note, if I am not allowed to post URL's. Then the forum's URL option should be disabled. In addition, previewing the post would be a good idea to tell me so I don't have to retype the whole thing again.

I have an MVC controller that we generate on the fly to render a customized form. We use Spire.PDF to translate the HTML into a PDF document. The result is a mess. The font's don't scale when zooming and appear to be grainy and hard read when printed. I've followed the examples on the site:

e-iceblue.com/Tutorials/Spire.PDF/Spire.PDF-Program-Guide/Convert-HTML-to-PDF-Customize-HTML-to-PDF-Conversion-by-Yourself.html

It seems like a default setting might be set like "Fit/Scale to Page" or a default DPI setting.

I've tried the following:
- Increasing the font size.
- Changing the fonts.
- Increasing the page size.

Nothing seems to be working. Zooming in the document or printing it results in a grainy mess. Are there any other settings I might be overlooking?

Thanks,

daniel.dority
 
Posts: 14
Joined: Thu Jan 11, 2018 2:57 pm

Mon Jun 11, 2018 5:53 pm

In addition, I can't even highlight any of the text in the PDF viewer where I can in another provider.

daniel.dority
 
Posts: 14
Joined: Thu Jan 11, 2018 2:57 pm

Mon Jun 11, 2018 8:15 pm

Looks like generating PDF's from that link is a terrible way of doing it. There's another way:

Spire.Pdf.HtmlConverter.Qt.HtmlConverter.Convert(html, $@"C:\temp\foo.pdf", true, 60000, new System.Drawing.SizeF(612, 792), new Spire.Pdf.Graphics.PdfMargins(0), LoadHtmlType.SourceCode);

The unfortunate thing about this way is there is no way to do multiple pages. You need to create them individually then merge them with the tool. Boooo.

Any other suggestions are welcomed.

daniel.dority
 
Posts: 14
Joined: Thu Jan 11, 2018 2:57 pm

Mon Jun 11, 2018 9:52 pm

Last bit of advice, the 4th parameter is bugged. Sometimes the conversion takes up to the timeout which in my case was 60 seconds per page. Not desired for web application performance. I dropped it down to a second which my PDF will never exceed 3 pages so that works for me. Play around with it - maybe there's a reason.

Also, the plugin conversion automatically prints to the debug stream or output window when debugging. Might help someone find the root cause.

daniel.dority
 
Posts: 14
Joined: Thu Jan 11, 2018 2:57 pm

Tue Jun 12, 2018 3:37 am

Dear daniel.dority,

Thanks for your inquiry and sorry for late reply as different timezone.
1. As for posting URL issue, there is a rule that the permission of posting a URL is allowed after posting three times, which used for avoiding spam threads on our forum. So sorry for the inconvenience caused. Now you could post a URL, as you have posted 4 times.

2. For the LoadFromHtml method in this guide, it is based on the IE kernel. If the version of your IE is 9 or above version, the converted pdf will be rendered in image way. From your description, I guess the generated PDF only has images in it, so it is impossible to search text in PDF reader. If you zoom the PDF, the image will be distorted, that is why you got grainy result.

3. We suggest you use the plugin to convert html to PDF, the html needs to be loaded first and then convert to pdf, let me explain the timeout parameter:
a. If the actual time of loading html is less than the setting timeout, once html data loading is complete, then enter the conversion.
b. If the actual time of loading html exceeds the setting timeout, the process would stop loading when loading html time reaches to the timeout, then enter the conversion process directly no matter whether html data is complete or not. Hence I suggest setting the right timeout when loading a large html.

If you cannot generate a pdf with multiple pages or have other issues, please share your html and entire code to help us do further investigation.

Many thanks,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Wed Jun 13, 2018 1:58 pm

Betsy,

How is image rendering handled for a resource that doesn't allow anonymous access? Can I pass the user context over to the PDF generation so they can access the image? For instance,

1: Anonymous users tries to access an image.
2: Server rejects users, forces a challenge.
3: Anonymous users authenticates.
4: User requests an image.
5: Server grants access and renders image.
6: User requests PDF generation.
7: Spire.PDF generates PDF from HTML containing image but image is broken.

Checking the logs, the server issued a 401 for the image because the request was anonymous. I need to pass the request context to Spire.PDF. How can I achieve this?

Passing the request cookie container should be enough to keep the context but I don't see any supporting documentation to do that.

Thoughts?

daniel.dority
 
Posts: 14
Joined: Thu Jan 11, 2018 2:57 pm

Wed Jun 13, 2018 1:59 pm

Also your explanation of the timeout setting makes sense. Thanks for that. The reason why the time is increasing is because of the 401 challenges. And I am stuck on trying to figure out how to pass the security context.

daniel.dority
 
Posts: 14
Joined: Thu Jan 11, 2018 2:57 pm

Thu Jun 14, 2018 6:46 am

Dear daniel.dority,

Thanks for your information.
If the image in your html cannot be accessed, I am afraid there is no way to get correct image result on PDF via Spire.
About the 401 error, sorry that I don't have any good advice.
Any question, please feel free to contact us.

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Return to Spire.PDF