Creating a PDF invoice in medium trust environments - a solution

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
14 years ago
I've read posts which suggest it is not possible to generate PDFs on servers running in medium trust. This restriction is imposed by the fact that the PDF library used (iTextSharp) requires full trust. Well in fact it doesn't require full trust to function - it's just that the library is built that way.

This atricle http://instantdevelopment.blogspot.com/2009/10/itextsharp-pdf-rendering-in-medium.html explains how to rebuild itextsharp with medium trust.

I performed the following steps, and it works fine for me:

1) Download iTextSharp v4.1.6 source
2) Add the following to AssemblyInfo.cs

[assembly: AllowPartiallyTrustedCallers()]

3) Rebuild iTextSharp in VS
4) Open nopCommerce solution in VS
5) In Nop.BusinessLogic project, reference the newly built iTextSharp DLL
6) Rebuild Nop.BusinessLogic project
7) Copy the new  iTextSharp and  Nop.BusinessLogic DLLs to your website bin folder

It would be great if the NopCommerce team could distribute the modified DLL in a future release, as from what I've seen this is the only limitation I've come across which prevents running in medium trust.

Regards, Chris.
14 years ago
Good work Chris thanks for sharing your solution!
14 years ago
Thanks

https://www.nopcommerce.com/Boards/Topic.aspx?TopicID=2257&p=2
14 years ago
I'm at the step where I need to rebuild the project.  Can someone help me out here.  I do not know where to go after I add [assembly: AllowPartiallyTrustedCallers()] to the assemblyinfo.cs
14 years ago
You need to open the iTextSharp solution file in Visual studio then simply select the rebuild option.
14 years ago
I had a little issue when uploading only the newly compiled itextsharp.dll and Nop.BusinessLogic.dll files.

I uploaded those and I still got an error.

FYI - You also have to upload the Nop.DataAccess files and Nop.Common.....Thats what worked for me....
14 years ago
To rebuild iTextSharp

1) Download the source from http://sourceforge.net/projects/itextsharp/files/itextsharp/itextsharp-4.1.6/itextsharp-4.1.6.zip/download
2) Extract it to a folder
3) Open up itextsharp.sln in Visual Studio
4) Modify AssemblyInfo.cs
5) Rebuild it

You will have to rebuild Nop.BusinessLogic project referencing the newly built iTextSharp DLL as described above and copy both DLLs to your website. I can't remember having to copy the other two DLLs mentioned, but do so if neccessary ...
13 years ago
ChrisOwczarek wrote:
To rebuild iTextSharp

1) Download the source from http://sourceforge.net/projects/itextsharp/files/itextsharp/itextsharp-4.1.6/itextsharp-4.1.6.zip/download
2) Extract it to a folder
3) Open up itextsharp.sln in Visual Studio
4) Modify AssemblyInfo.cs
5) Rebuild it

You will have to rebuild Nop.BusinessLogic project referencing the newly built iTextSharp DLL as described above and copy both DLLs to your website. I can't remember having to copy the other two DLLs mentioned, but do so if neccessary ...


I may be missing something here I have downloaded and built the new version of itextsharp, with the additional attribute in the AssemblyInfo.cs, but I'm not finding any references to the ORIGINAL itextsharp assembly ANYWHERE in the nopCommerce dev environment that I have (it's V1.5). I have references to PdfSharp, and PdfSharp.Charting, but no iTextSharp??? Any ideas?
13 years ago
iTextSharp was changed to PDFSharp between version 1.4 to 1.5. If you want to use iTextSharp you need to use version 1.4 of nopcommerce. PDFSharp is the only PDF maker is 1.5
13 years ago
mcspartan017 wrote:
iTextSharp was changed to PDFSharp between version 1.4 to 1.5. If you want to use iTextSharp you need to use version 1.4 of nopcommerce. PDFSharp is the only PDF maker is 1.5


So, does this still work?

Have the instructions to make the change, changed?

Thanks
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.