asp.net-coreiis

QuestPDF GeneratePdf works locally but not when implemented on a remote server in IIS


I'm using QuestPdf in ASP.NET Core 6. The method generates a dynamic PDF. When I click a button, the method is triggered, and the PDF is automatically downloaded to the PC. It works perfectly locally. After implementing the code on the IIS server, it stops working. Everything else works perfectly – editing, creating, and deleting – so it's not a database connection issue. When I click the button that triggers the method, I get: 'This page isn't working (remoteServerIp:8080) can't process this request at the moment. HTTP ERROR 500.' In the headers, it only shows '500 Internal Server Error,' and in the browser console, I see: 'The server responded with a status of 500 ().' That's all. I gave full control to the IIS_IUSRS users on MIME types; the .pdf MIME type 'application/pdf' is there. I'm not sure what else it could be.

This is the method to generate the PDF:

public IActionResult ImprimirProyectoPartidaOVERHEAD(int id)
        {
            var data = Document.Create(document =>
            {
                document.Page(page =>
                {
                    var pageSize = new PageSize(612f, 840f);
                    page.Size(pageSize);
                    page.MarginLeft(60);
                    page.MarginRight(60);
                    page.MarginTop(30);
                    page.MarginBottom(30);
                    page.Background()
                    .AlignBottom()
                    .ExtendHorizontal()
                    .Height(115)
                    .Background("#000000");

                    page.Header().Height(240).Row(row =>
                    {
                        
                    })


                    page.Content().PaddingVertical(10).Column(col1 =>
                    {
                        
                    });


                    page.Footer()
                    .Column(txt =>
                    {
                       
                    });
                });
            }).GeneratePdf();



            MemoryStream stream = new MemoryStream(data);
            return File(stream, "application/pdf", ".pdf");
        }

Solution

  • In the end, I managed to access the IIS logs, and there I saw that the issue was because I was using a font in the PDF for a word, and this font was not installed on the machine. It was resolved by simply downloading and installing this font on the server.