nopSolutions / nopCommerce

ASP.NET Core eCommerce software. nopCommerce is a free and open-source shopping cart.
https://www.nopcommerce.com
Other
9.2k stars 5.29k forks source link

Replace iTextSharp with a new PDF library #4622

Closed AndreiMaz closed 1 year ago

AndreiMaz commented 4 years ago

iTextSharp is EOL. So we have to find a replacement

let's just ensure that iText 7 has an appropriate license for us. For example, please see https://itextpdf.com/en/how-buy/agpl-license. One important note: "When using iText 7 Community under AGPL, you must prominently mention iText and include the iText copyright and AGPL license in output file metadata, and also retain the producer line in every PDF that is created or manipulated using iText."

Originally suggested by @ecommerce-tester in https://github.com/nopSolutions/nopCommerce/issues/196#issuecomment-620625998

Let's also investigate the approach with conversion to HTML and then to PDF (so we have to find a library that supports export from HTML to PDF)

DmitriyKulagin commented 3 years ago

After some investigation, we came to the conclusion that iText 7 is not suitable for us, since RTL support for this library is in the paid pdfCalligraph module. I think that we need to move away from the principle of generating PDF directly, and first generate HTML and then convert it to PDF with some tool.

Here is a benchmark test of some of the tools. This is just for thought.

purplepiranha commented 2 years ago

I've been doing a lot of work with writing customised reports this week and have faced quite a few challenges trying to use iTextSharp 5. Looking at iText 7, as well as the RTL support mentioned above being a problem, I think there is a bigger issue that developers working on NopCommerce sites may well want to use in library in their own implementations and this wouldn't be covered by the license unless those implementations were also open-sourced.

I was quite surprised that there seems to be a lack of open source PDF generation libraries for C#. There are a few about but most haven't been updated for several years and aren't compatible with NET5/6.

I have though found QuestPDF which is open-source and available under MIT license. In 4 hours I've managed to recreate using QuestPDF what has taken me over 3 days using iTextSharp 5. It seems quite impressive and uses a simple FluentAPI syntax.

iwhp commented 1 year ago

The current implementation for creating PDF invoices etc. does not follow separation of concerns. There are many calculations that are performed site by site with creating the PDF files. To be more flexible it would be helpful if the calculation of the values were separated from the output to be created. I hope this will be taken into account when implementing a replacement for iTextSharp 5.

purplepiranha commented 1 year ago

The current implementation for creating PDF invoices etc. does not follow separation of concerns. There are many calculations that are performed site by site with creating the PDF files. To be more flexible it would be helpful if the calculation of the values were separated from the output to be created. I hope this will be taken into account when implementing a replacement for iTextSharp 5.

I fully agree with this. I find this a big problem in a lot of other areas in NopCommerce too.

The logic for the invoice calculation needs to be totally decoupled from the logic to generate the final invoice document.

exileDev commented 1 year ago

I hope this is what you mean :)

Closed #4622

alextretij commented 1 year ago

I tried to find the convertor from HTML to PDF and I could not do it. This convertor has to work on Windows/Linux/Azure application, etc. But .... I found only wrappers for l wkhtmltopdf Example https://github.com/rdvojmoc/DinkToPdf But they work only common (simple HTML markups) Example for links in Linux https://stackoverflow.com/questions/73342471/dinktopdf-on-linux-doesnt-show-images/73527372#73527372

jaroslav-sykora commented 11 months ago

I've been doing a lot of work with writing customised reports this week and have faced quite a few challenges trying to use iTextSharp 5. Looking at iText 7, as well as the RTL support mentioned above being a problem, I think there is a bigger issue that developers working on NopCommerce sites may well want to use in library in their own implementations and this wouldn't be covered by the license unless those implementations were also open-sourced.

I was quite surprised that there seems to be a lack of open source PDF generation libraries for C#. There are a few about but most haven't been updated for several years and aren't compatible with NET5/6.

I have though found QuestPDF which is open-source and available under MIT license. In 4 hours I've managed to recreate using QuestPDF what has taken me over 3 days using iTextSharp 5. It seems quite impressive and uses a simple FluentAPI syntax.

This QuestPDF MIT free license is applicable only for companies and individuals with less than $1M USD annual gross revenue, or projects using the library as a transitive dependency, or non-profit projects.

I'm confused about iTextSharp 5 licence. Does it mean if i create website for my customer based on nopCommerce do i have to buy iTextSharp licence or not? Lets say i do some customizations to original nopCommerce design and i create some plugin do i have to make my source public?

purplepiranha commented 11 months ago

I've been doing a lot of work with writing customised reports this week and have faced quite a few challenges trying to use iTextSharp 5. Looking at iText 7, as well as the RTL support mentioned above being a problem, I think there is a bigger issue that developers working on NopCommerce sites may well want to use in library in their own implementations and this wouldn't be covered by the license unless those implementations were also open-sourced. I was quite surprised that there seems to be a lack of open source PDF generation libraries for C#. There are a few about but most haven't been updated for several years and aren't compatible with NET5/6. I have though found QuestPDF which is open-source and available under MIT license. In 4 hours I've managed to recreate using QuestPDF what has taken me over 3 days using iTextSharp 5. It seems quite impressive and uses a simple FluentAPI syntax.

This QuestPDF MIT free license is applicable only for companies and individuals with less than $1M USD annual gross revenue, or projects using the library as a transitive dependency, or non-profit projects.

I'm confused about iTextSharp 5 licence. Does it mean if i create website for my customer based on nopCommerce do i have to buy iTextSharp licence or not? Lets say i do some customizations to original nopCommerce design and i create some plugin do i have to make my source public?

QuestPDF licensing unfortunately changed a while back. Before then it was all under MIT license. If your customer's revenue is above $1M USD then I doubt they would have a problem paying it though.

The iTextSharp license is a pain. As the library is a dependency of your project (note: Nop isn't packaged, so it's not part of Nop) then yes you project has to be open source.

Also, QuestPDF is far easier to use than iTextSharp. There is a problem though with larger files due to the lack of font subsetting.

AndreiMaz commented 11 months ago

nopCommerce does not use the latest version of QuestPDF that introduced dual licensing. Hence this the new license with the requirement of $1M is not applicable to nopCommerce