【问题标题】:PDF Excel export client and serversidePDF Excel 导出客户端和服务器端
【发布时间】:2018-08-16 05:08:14
【问题描述】:

HTML 表格、图表、图像可以是报告内容。用户可以下载看到的报告,或者他可以安排这些报告在电子邮件中恢复。 需要一个引擎在客户端和服务器端以 PDF 和 Excel 格式输出。 使用 Angular 5 前端和 Spring Boot 支持。

尝试过 Kendo UI ..它会生成客户端 PDF,但不确定如何在 Spring 引导调度程序中使用 kendo 进行此操作

【问题讨论】:

标签: spring-boot kendo-ui export-to-pdf


【解决方案1】:

我多次遇到这个问题,在 JavaScript、C# 或 Java 中都是一样的,通常要求是相同的。为了允许创建报告,其中一些仅基于文本,但其他似乎更复杂,具有格式化的文本、表格、图像甚至图表。众所周知,报告工具有很多,例如 DevExpress XtraReportsCrystal ReportsJasper ReportsMS Reporting Services ,甚至更多用于创建 Docx / PDF 自定义报告的 MS Word InteropMS Excel Interop,但没有一种技术像 iText(用于 Java)或 iTextSharp(用于 .Net)。 该库允许您创建功能强大的 PDF 文档、报告、书籍等。查看iText in Action 一书,了解您可以使用 iText 做的所有事情。将 PDF 下载到客户端只需使用适当的 MIME 类型:“application/pdf刷新 PDF 流。。 p>

    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);
    }

见:https://itextpdf.com/

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-08-13
    • 1970-01-01
    • 1970-01-01
    • 2011-09-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多