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 Aug 17, 2020 3:26 pm

I am following this example here: https://www.e-iceblue.com/Tutorials/Spi ... B.NET.html

Where are PdfHTMLTextElement and PdfMetafileLayoutFormat classes contained in the SpirePDF library?

I'm getting "the type or namespace could not be found" for both of them.

I've imported:

Code: Select all
using Spire.Pdf;
using Spire.Pdf.Widget;
using Spire.Pdf.Graphics;


Having a class library document for the entire SpirePDF.dll would be nice to have.

I'm running SpirePDF 6.8.1, on a Mac. Project is .NET Core 3.1 running in VSCode.

djarmoluk
 
Posts: 9
Joined: Fri Jul 31, 2020 7:13 pm

Tue Aug 18, 2020 10:22 am

Hello,

Thanks for your inquiry.
Sorry that our Spire.PDF for .net core library does not support the two classes PdfHTMLTextElement and PdfMetafileLayoutFormat.
If there is anything else we can do for you, just feel free to contact us.

Sincerely
Elena
E-iceblue support team
User avatar

Elena.Zhang
 
Posts: 279
Joined: Thu Jul 23, 2020 1:18 am

Fri Aug 21, 2020 3:26 am

Would have been nice if you would have CLEARLY called that out in your docs. I likely would not have bought a license if I knew that.

What work around do you suggest? I need to be able to do some kind of HTML rendering... which is a common feature of most PDF libraries.

djarmoluk
 
Posts: 9
Joined: Fri Jul 31, 2020 7:13 pm

Fri Aug 21, 2020 10:29 am

Hello,

Sorry for the inconvenience caused by us, we have improved the description on our website, please check.
Besides, we provide a plugin method to convert HTML to PDF. You can first use our plugin method to convert your HTML text to PDF, then use the DrawTemplate method to draw it on an existing PDF file, as shown below.

Code: Select all
 static void Main(string[] args)
        {
            string input = @"<strong>This is a test for converting HTML string to PDF </strong>
                 <ul><li>Spire.PDF supports to convert HTML in URL into PDF</li>
                 <li>Spire.PDF supports to convert HTML string into PDF</li>
                 <li>With the new plugin</li></ul>";
            PdfDocument pdf = new PdfDocument();
            pdf.LoadFromFile("test.pdf");

            PdfDocument html = new PdfDocument();
            html.LoadFromStream(ConvertHtmlStringToPDF(input, new SizeF(400,200)));

            pdf.Pages[0].Canvas.DrawTemplate(html.Pages[0].CreateTemplate(), new PointF(10,10), html.Pages[0].Size);
            pdf.SaveToFile("out.pdf", FileFormat.PDF);
        }

        private static MemoryStream ConvertHtmlStringToPDF(string htmlString, SizeF pageSize)
        {
            MemoryStream ms = new MemoryStream();
            //Spire.Pdf.HtmlConverter.Qt.HtmlConverter.PluginPath = "";
            Spire.Pdf.HtmlConverter.Qt.HtmlConverter.Convert(htmlString,

            ms,
            //enable javascript
            true,
            //load timeout
            10 * 1000,
            //page size
            pageSize,
            //page margins
            new Spire.Pdf.Graphics.PdfMargins(0),
            //load from content type
            LoadHtmlType.SourceCode
            );
            return ms;
        }


Sincerely,
Elena
E-icceblue support team
User avatar

Elena.Zhang
 
Posts: 279
Joined: Thu Jul 23, 2020 1:18 am

Fri Aug 21, 2020 1:08 pm

What should I have for PluginPath? I've got it set to "plugins". And I've placed the plugins folder in the same directory as the Spire.PDF.dll.

When I run the app, I get:

Code: Select all
HTMLConverter: System.Exception: Fail to load /Users/djarmoluk/Projects/premier.api.utilities/bin/Debug/netcoreapp3.1/plugins/libHTMLConverter.dylib : error
   at Spire.Pdf.HtmlConverter.Qt.QtPluginLibrary.LoadLibrary(String pluginDirectory)
   at Spire.Pdf.HtmlConverter.Qt.Proxy.Init()
   at Spire.Pdf.HtmlConverter.Qt.Proxy.ConversionService.Init0()


Also, I've downloaded the plugin from here (http://www.e-iceblue.com/downloads/HTML ... .2.3.3.zip) but I assume there is a newer version available?

Again, I'm doing development on macOs 10.15.6, .NET core 3.1.

djarmoluk
 
Posts: 9
Joined: Fri Jul 31, 2020 7:13 pm

Fri Aug 21, 2020 1:42 pm

I found the correct plugins folder to download here.

https://www.e-iceblue.com/Knowledgebase ... o-PDF.html

I see there is a different download for Mac and Linux. Which is going to be a pain since I'm deploying my app to a Linux server.

djarmoluk
 
Posts: 9
Joined: Fri Jul 31, 2020 7:13 pm

Fri Aug 21, 2020 3:14 pm

Using the code example you provided, I am now getting the following exception:

Code: Select all
Exception has occurred: CLR/System.IndexOutOfRangeException
An unhandled exception of type 'System.IndexOutOfRangeException' occurred in Spire.Pdf.dll: 'Index was outside the bounds of the array.'
   at sprᢶ.ᜀ(Stream A_0)
   at sprᢶ.ᜀ(Stream A_0, Boolean A_1)
   at sprᢶ..ctor(Stream A_0)
   at Spire.Pdf.PdfDocument.LoadFromStream(Stream stream)
   at premier.pdf.testing.Program.SetContentAreaValue(String content, PdfPageBase page) in /Users/djarmoluk/Projects/premier.api.utilities/Program.cs:line 113
   at premier.pdf.testing.Program.CreateFax(Int32 followUpId, Int32 coverPageId) in /Users/djarmoluk/Projects/premier.api.utilities/Program.cs:line 74
   at premier.pdf.testing.Program.Main(String[] args) in /Users/djarmoluk/Projects/premier.api.utilities/Program.cs:line 32


The `ConvertHtmlStringToPDF` method is returning a memory stream... but the `LoadFromStream` method on the html object is bombing out.

Would appreciate a solution that works here.

djarmoluk
 
Posts: 9
Joined: Fri Jul 31, 2020 7:13 pm

Mon Aug 24, 2020 9:54 am

Hello,

Thanks for your response and sorry for the late reply as weekend.
Yes, the plugins for Mac and Linux are different. We are very sorry for the inconvenience caused.
Besides, the code I provided works fine on my side. This is my test project, please run it directly and then tell us your testing result. Looking forward to your feedback.

Sincerely,
Elena
E-iceblue support team
User avatar

Elena.Zhang
 
Posts: 279
Joined: Thu Jul 23, 2020 1:18 am

Return to Spire.PDF