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 Apr 12, 2021 5:51 pm

Hi !
I would like to know if Spire.PDF (Free) works within a C# MVC web app.
I can make it work as a stand alone app, but I keep having a COM error inside a web controller.

Thanks !

sebastianpmb
 
Posts: 3
Joined: Mon Apr 12, 2021 5:47 pm

Tue Apr 13, 2021 10:05 am

Hello,

Thanks for your inquiry.
Our Free Spire.PDF can be used in a C# MVC web application. Here I created a sample project for your better reference. You can also replace it with your code for testing.

If you encounter any issues during the test, please provide your test code to help us investigate further. Looking forward to your feedback.

Sincerely,
Brian
E-iceblue support team
User avatar

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

Tue Apr 13, 2021 11:51 am

Thanks for the reply Brian,

your code works fine.

I´m trying to convert from an HTML page.

Here is the code:

String url = "xxxxxxxxxxxxxxx";

PdfDocument document2 = new PdfDocument();

Thread thread = new Thread(() =>
{


PdfPageBase page2 = document2.AppendPage();
PdfPageSettings setting = new PdfPageSettings();
setting.Size = PdfPageSize.A4;

PdfHtmlLayoutFormat htmlLayoutFormat = new PdfHtmlLayoutFormat();
htmlLayoutFormat.IsWaiting = true;


document2.LoadFromHTML(url, false, false, false, setting, htmlLayoutFormat);
});

thread.SetApartmentState(ApartmentState.STA);
thread.Start();
thread.Join();
//Save pdf file.
document2.SaveToFile(Server.MapPath("result.pdf"));

document2.Close();

but i receive this COM error (sorry for the portuguese)

System.Runtime.InteropServices.COMException
HResult=0x80004005
Message=Erro HRESULT E_FAIL foi retornado de uma chamada para o componente COM.
Source=<Cannot evaluate the exception source>
StackTrace:
<Cannot evaluate the exception stack trace>

sebastianpmb
 
Posts: 3
Joined: Mon Apr 12, 2021 5:47 pm

Wed Apr 14, 2021 9:48 am

Hello,

Thanks for your response.
I tested your code but did not encounter any issue. This is my test project, please run it directly on your side and then let us know your test result.

Besides, our Spire.PDF provides a new plugin method to convert HTML to PDF, which has a better performance than the method you used. You can give it a try.

Sincerely,
Brian
E-iceblue support team
User avatar

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

Wed Apr 14, 2021 12:37 pm

Thanks Brian,

I tried your code and gave the same error as mine, a COM error.
So I guess I have an installation issue, some DLL or component may be missigng.

sebastianpmb
 
Posts: 3
Joined: Mon Apr 12, 2021 5:47 pm

Thu Apr 15, 2021 6:40 am

Hello,

Thanks for your feedback.

I tried to run my project on several computers but still didn’t encounter any issue. I’m afraid this issue may be related to your Visual Studio or your system settings. Or as you said, this may be caused by missing some dlls or components. Thus, I recommend you can run the project on other computers or other version of Visual Studio to see if the issue still occurs.

Besides, I also tried to search on some technology forums based on your error message, and I found this solution: https://social.msdn.microsoft.com/Forum ... 0x80004005 . Hope it can help you.

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