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.

Thu Mar 04, 2021 3:05 pm

Hello,

What is the best way to create a PDF from an htmlstring? What we are seeing is it create the pdf, but as an image, which is causing the file size to be very large. Is there a way to use the method below but not have it create as an image? We are currently doing this:

Code: Select all
            PdfDocument doc = new PdfDocument();

            PdfPageSettings setting = new PdfPageSettings();

            setting.Size = new SizeF(595, 842);
            setting.Margins = new Spire.Pdf.Graphics.PdfMargins(60);

            Spire.Pdf.HtmlConverter.PdfHtmlLayoutFormat htmlLayoutFormat = new Spire.Pdf.HtmlConverter.PdfHtmlLayoutFormat();
            htmlLayoutFormat.IsWaiting = true;
            htmlLayoutFormat.Layout = PdfLayoutType.Paginate;

            Thread thread = new Thread(() =>
            {
                doc.LoadFromHTML(htmlString, true, setting, htmlLayoutFormat);
            });

            thread.SetApartmentState(ApartmentState.STA);

            thread.Start();

            thread.Join();
            //Save pdf file.
            doc.SaveToFile(filePath);




Also is there a way to add css styling when generating a pdf via a html string? I have been unable to find anything to do that.

jimr0217
 
Posts: 6
Joined: Thu Mar 04, 2021 2:59 pm

Fri Mar 05, 2021 3:11 am

Hello,

Thanks for your inquiry.
Our Spire.PDF also provide a plugin conversion method, which does not render the HTML pages into images, and has better support for CSS styles. Please refer to the tutorial (Convert HTML to PDF with New Plugin) to have a try.

If there are still any questions, please provide us with your html code for further investigation. Thanks in advance.

Sincerely,
Brian
E-iceblue support team
User avatar

Brian.Li
 
Posts: 1271
Joined: Mon Oct 19, 2020 3:04 am

Fri Mar 05, 2021 8:03 pm

I have tried using the plugin but I keep getting the same message. I have looked through several other posts on the forum and have done all of the following to try to resolve the issue:

1. I have the 2015 redistributable installed for VS
2. Copied the plugins folder into the same directory as the Spire PDF dll
3. Added plugin path in the code (code sample below)
4. Changed IIS Application Pool Settings to enable 32 bit applications to true

Still seeing message :
The conversion provider cann't be found.
Please make sure the folder "plugins" is under the same folder of Spire.Pdf.dll. For more help, please visit below website.

Code: Select all
            Spire.Pdf.HtmlConverter.Qt.HtmlConverter.PluginPath = @"C:\TFS2013\BALANCEworks\Source-Prod\AAP\AAPNEW\bin\plugins";

            Spire.Pdf.HtmlConverter.Qt.HtmlConverter.Convert(htmlString,

                             filePath,

                             false,

                             200,

                             new System.Drawing.SizeF(612, 792),

                             new Spire.Pdf.Graphics.PdfMargins(0), Spire.Pdf.HtmlConverter.LoadHtmlType.SourceCode);

jimr0217
 
Posts: 6
Joined: Thu Mar 04, 2021 2:59 pm

Mon Mar 08, 2021 10:54 am

Hello

Thanks for your feedback and sorry for the late reply as weekend.
You are using the x86 plugin, right? I created a project based on your description, then deployed it on IIS and tested it. but I didn't encounter any issues. Here I uploaded my testing project for your reference, please run it directly on your side and then please tell us your test results. Thanks in advance.

Sincerely,
Brian
E-iceblue support team
User avatar

Brian.Li
 
Posts: 1271
Joined: Mon Oct 19, 2020 3:04 am

Wed Mar 10, 2021 5:12 am

Hello Brian,

We are actually trying to use x64 and not x86. I was able to test your project below and it works fine with x86 but when I tried with x64 I got the same error I have been seeing:

The conversion provider cann't be found.
Please make sure the folder "plugins" is under the same folder of Spire.Pdf.dll. For more help, please visit below website


Is there something else I need to do for x64 to work? Thanks!

jimr0217
 
Posts: 6
Joined: Thu Mar 04, 2021 2:59 pm

Wed Mar 10, 2021 10:05 am

Hello,

Thanks for your inquiry.
For x64 plugins, please set the IIS Application Pool Settings "Enable 32-Bit Applications" to False.
If there are any other questions, please feel free to contact us.

Sincerely,
Brian
E-iceblue support team
User avatar

Brian.Li
 
Posts: 1271
Joined: Mon Oct 19, 2020 3:04 am

Fri Mar 12, 2021 2:03 am

Hi Brian,

I was able to get your test project working with no problems with both x86, x64, using iis express and local iis, but I am still getting the above error in my local development environment. Are there any other common problem configuration problems that might be causing this? Thanks!

jimr0217
 
Posts: 6
Joined: Thu Mar 04, 2021 2:59 pm

Fri Mar 12, 2021 9:36 am

Hello,

Are you testing the project I provided on your local development environment with Visual stoduo? By default, Visual Studio uses the 32 bit version of IIS Express. And my project used the x64-bit plugin, I suspect it should be caused by this.
Please try to enable the “Use the 64 bit version of IIS Express for web sites and projects” option by “Tools->Options->Projects and Solutions->Web projects”, as shown below. If there are still any questions, please feel free to contact us.
screenshot.png


Sincerely,
Brian
E-iceblue support team
User avatar

Brian.Li
 
Posts: 1271
Joined: Mon Oct 19, 2020 3:04 am

Fri Mar 19, 2021 7:18 am

Hello,

Has your issue been resolved? Any feedback will be greatly appreciated.

Sincerely,
Brian
E-iceblue support team
User avatar

Brian.Li
 
Posts: 1271
Joined: Mon Oct 19, 2020 3:04 am

Return to Spire.PDF

cron