C
C#10mo ago
Genti

CSHTML form to PDF File.

So i have some form in my cshtml view that saves all the data correctly inside the corresponding model, and i need to get these input data and display them inside a pdf file. I tried using QuestPDF, DinkToPDF and BouncyCastle methods and none really worked. This is the project : "https://github.com/GentiOsmani/DeklarimiPasurise" So the forms are filled inside this directory : "DeklarimiPasuris>Views>Declare>Create.cshtml". They Are saved at this directory : "DeklarimiPasuris>Models>DeclarationModel". And they are shown at this directory: "DeklarimiPasuris>Views>Declare>Details.cshtml". The pdf should download when this button is clicked : "<td><a class="btn btn-primary" asp-action="DownloadPdf" asp-controller="Declare">Shkarko</a></td>" (line 38), Inside of this directory : "DeklarimiPasuris>Views>Declare>Index.cshtml". If someone could help me it would be a blessing. Best Regards, Genti.
7 Replies
Gramore
Gramore10mo ago
What didn't work in the aforementioned PDF libraries?
Genti
GentiOP10mo ago
@Gramore i kept getting some bouncy castle errors when i executed the code even tho i installed all the right packages and tried it 100 times in all different ways
Gramore
Gramore10mo ago
$details
MODiX
MODiX10mo ago
When you ask a question, make sure you include as much detail as possible. Such as code, the issue you are facing, and what you expect the result to be. Upload code here https://paste.mod.gg/ (see $code for more information on how to paste your code)
Gramore
Gramore10mo ago
I assume that QuestPDF wasn't giving you bouncy castle errors for example, and it would be a lot easier to help fix whatever bouncy castle error you're getting if you listed it explicitly
Genti
GentiOP10mo ago
@Gramore let me see if i can find that error 1 sec
iText.Kernel.Exceptions.PdfException
HResult=0x80131500
Message=Unknown PdfException.
Source=itext.kernel
StackTrace:
at iText.Kernel.Pdf.SmartModePdfObjectsSerializer..ctor()
at iText.Kernel.Pdf.PdfWriter..ctor(Stream os, WriterProperties properties)
at iText.Kernel.Pdf.PdfWriter..ctor(Stream os)
at DeclarationPdf.GeneratePdf(DeclarationModel model, String user) in C:\Users\genti\OneDrive\Desktop\DeklarimiPasuris-master\DeklarimiPasuris\Controllers\DeclarationPdf.cs:line 18
at System.Dynamic.UpdateDelegates.UpdateAndExecuteVoid3[T0,T1,T2](CallSite site, T0 arg0, T1 arg1, T2 arg2)
at DeklarimiPasuris.Controllers.DeclareController.Convert() in C:\Users\genti\OneDrive\Desktop\DeklarimiPasuris-master\DeklarimiPasuris\Controllers\DeclareController.cs:line 344
at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.SyncActionResultExecutor.Execute(ActionContext actionContext, IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeActionMethodAsync()
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeNextActionFilterAsync()

This exception was originally thrown at this call stack:
[External Code]

Inner Exception 1:
NotSupportedException: Either com.itextpdf:bouncy-castle-adapter or com.itextpdf:bouncy-castle-fips-adapter dependency must be added in order to use BouncyCastleFactoryCreator
iText.Kernel.Exceptions.PdfException
HResult=0x80131500
Message=Unknown PdfException.
Source=itext.kernel
StackTrace:
at iText.Kernel.Pdf.SmartModePdfObjectsSerializer..ctor()
at iText.Kernel.Pdf.PdfWriter..ctor(Stream os, WriterProperties properties)
at iText.Kernel.Pdf.PdfWriter..ctor(Stream os)
at DeclarationPdf.GeneratePdf(DeclarationModel model, String user) in C:\Users\genti\OneDrive\Desktop\DeklarimiPasuris-master\DeklarimiPasuris\Controllers\DeclarationPdf.cs:line 18
at System.Dynamic.UpdateDelegates.UpdateAndExecuteVoid3[T0,T1,T2](CallSite site, T0 arg0, T1 arg1, T2 arg2)
at DeklarimiPasuris.Controllers.DeclareController.Convert() in C:\Users\genti\OneDrive\Desktop\DeklarimiPasuris-master\DeklarimiPasuris\Controllers\DeclareController.cs:line 344
at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.SyncActionResultExecutor.Execute(ActionContext actionContext, IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeActionMethodAsync()
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeNextActionFilterAsync()

This exception was originally thrown at this call stack:
[External Code]

Inner Exception 1:
NotSupportedException: Either com.itextpdf:bouncy-castle-adapter or com.itextpdf:bouncy-castle-fips-adapter dependency must be added in order to use BouncyCastleFactoryCreator
this was it i think
Gramore
Gramore10mo ago
Kewl, so do you have either of those dependencies added? presumably this: https://www.nuget.org/packages/itext7.bouncy-castle-adapter/8.0.1
itext7.bouncy-castle-adapter 8.0.1
Bouncy-castle adapter module
Want results from more Discord servers?
Add your server