PDF Excel export client and serverside
Asked Answered
I

1

6

HTML table, Charts , images could be the report content. User can download seen report or he can schedule these reports to revive on email. Need an engine to give out in PDF and Excel format at client side as well as server side. Using Angular 5 fronted and Spring Boot backed.

Tried Kendo UI ..it does client side PDF generation but not sure how to do it in Spring boot scheduler using kendo

Ignorance answered 16/8, 2018 at 5:8 Comment(1)
Are you open to a Laravel based micro service api that then uses a package like this (github.com/Maatwebsite/Laravel-Excel) to serve your needsTam
A
1

I have faced this problem lots of times, the same in JavaScript, C#, or in Java, normally the requirements are the same. To allow create reports some of them being text based only, but other seems to be more complex, having formatted text, tables, images and even charts. It is well know that there are many reporting tools, for example, DevExpress XtraReports, Crystal Reports, Jasper Reports, MS Reporting Services, and even more MS Word Interop for creating Docx / PDF custom reports, MS Excel Interop, but none of that technologies is as simple and powerful as iText (for Java) or iTextSharp (for .Net). That library allow you to create powerful PDF documents, reports, books, etc. Take a look at iText in Action book to have a good idea of all the things you can do with iText. Downloading the PDF to the client side is a matter of flushing the PDF stream using the appropiate MIME type: "application/pdf".

    public Image CreateNewLogo()
    {
        string imageURL = HttpContext.Current.Server.MapPath(PDFResources.ImagesPath) + "/Logo.png";
        Image img = Image.GetInstance(imageURL);
        img.ScaleToFit(270f, 90f);
        img.SpacingBefore = 5f;
        img.SpacingAfter = 5f;
        img.Alignment = Element.ALIGN_LEFT;

        return img;
    }

    public void CreateHeader()
    {
        string div = Resources.OFR_Resources.h1_div + " " + data.DescDivision;
        string zona = Resources.OFR_Resources.h1_zona + " " + data.DescZona;
        Image logo = CreateNewLogo();

        PdfPTable table = new PdfPTable(2);         table.DefaultCell.Border = Rectangle.NO_BORDER;
        PdfPCell cellDZ = new PdfPCell();           cellDZ.Border = Rectangle.NO_BORDER;

        Paragraph pd = NewParagraphHeader(div);     pd.Alignment = Element.ALIGN_RIGHT;
        Paragraph pz = NewParagraphHeader(zona);    pz.Alignment = Element.ALIGN_RIGHT;
        cellDZ.AddElement(pd);                      cellDZ.AddElement(pz);            
        table.AddCell(logo);                     table.AddCell(cellDZ);

        document.Add(table);
    }

    public void CreateContent()
    {
        string s1_p1 = Resources.OFR_Resources.s1_p1.Replace("[FECHA_SOLICITUD]", string.Format("{0: dd MM yyyy}", data.Solicitud.fechaAlta));
        s1_p1 = s1_p1.Replace("[RAZON_SOCIAL]", data.Solicitud.dsNombreDenRS);
        s1_p1 = s1_p1.Replace("[DIRECCION_SOLICITANTE]", data.DireccionSolicitante);

        PdfPTable table = new PdfPTable(2); table.DefaultCell.Border = Rectangle.NO_BORDER;
        Paragraph p_fecha       = NewParagraphN(Resources.OFR_Resources.s1_fecha.Replace("[FECHA_ACTUAL]", DateTime.Now.ToLongDateString()));
        Paragraph p_oficio      = NewParagraphN(Resources.OFR_Resources.s1_oficio);
        Paragraph p_asunto      = NewParagraphN(Resources.OFR_Resources.s1_asunto);

        PdfPCell cellRigth = new PdfPCell();
        cellRigth.AddElement(p_fecha);
        cellRigth.AddElement(p_asunto);
        cellRigth.Border = Rectangle.NO_BORDER;

        table.AddCell("");
        table.AddCell(cellRigth);
        document.Add(table);
    }

See: https://itextpdf.com/

Anny answered 7/9, 2018 at 17:58 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.