C#版 iText7——画发票PDF(完整)

news2025/7/9 0:08:51

显示描述:
1、每页显示必须带有发票头、“销售方和购买方信息”
2、明细填充为:当n≤8 行时,发票总高度140mm,每条发票明细行款高度4.375mm;
当8<n≤12行时,发票高度增加17.5mm,不换页;
以此类推
根据实际情况能放下“应税明细信息”和“票尾”信息后换页,注意是否为最后一行
3、超过一页,则每页显示小计

显示效果:
1、只有一页的情况:
在这里插入图片描述
2、有两页的且刚好能放下所有明细的情况(超过一页后,开票日期下显示页数):
这是第一页
在这里插入图片描述

代码实现:

步骤一、创建主方法,可传入需要的参数模型

public static void InvoicePage(NaturalSystemPdfModel model) //NaturalSystemPdfModel为传入的需要用到的参数模型
{
	//创建pdf的保存位置
	//model.filePath为传入模型中存放的文件保存路径,model.kprq为开票日期,model.fileName为文件名
	//model.filePath = Path.Combine(_webHostEnvironment.WebRootPath, “.pdf”);获取当前服务器下的文件路径
	string outputPath = Path.Combine(model.filePath,model.kprq.ToString("yyyyMMdd"), model.fileName + ".pdf");
   //判断文件夹是否存在,不存在则创建一个新的
    if (!Directory.Exists(Path.Combine(model.filePath, model.kprq.ToString("yyyyMMdd"))))
        Directory.CreateDirectory(Path.Combine(model.filePath, model.kprq.ToString("yyyyMMdd")));
        
    // 创建一个新的PDF文档
    var cc = new PdfWriter(outputPath);
    //设置 PdfStream默认压缩级别。
    cc.SetCompressionLevel(CompressionConstants.BEST_COMPRESSION);
    PdfDocument pdf = new PdfDocument(cc);
    
    model.jshjdx = MoneyToUpper(model.jshj.ToString()); //价税合计大写转换(转换方法MoneyToUpper())
    model.gmfmc = model.gmfmc == "个人" ? model.gmfmc + "(个人)" : model.gmfmc;//购方名称
    
    字体
    //model.webHost为模型中的发布服务器中的文件所在位置:IWebHostEnvironment _webHostEnvironment.WebRootPath
    PdfFont KT = PdfFontFactory.CreateFont(System.IO.Path.Combine(model.webHost, "fonts", "SIMKAI.TTF"), PdfEncodings.IDENTITY_H, PdfFontFactory.EmbeddingStrategy.PREFER_NOT_EMBEDDED);
    PdfFont ST = PdfFontFactory.CreateFont(System.IO.Path.Combine(model.webHost, "fonts", "SIMFANG.TTF"), PdfEncodings.IDENTITY_H, PdfFontFactory.EmbeddingStrategy.PREFER_NOT_EMBEDDED);
    PdfFont CN = PdfFontFactory.CreateFont(System.IO.Path.Combine(model.webHost, "fonts", "COUR.TTF"), PdfEncodings.IDENTITY_H, PdfFontFactory.EmbeddingStrategy.PREFER_NOT_EMBEDDED);

    //添加页眉页脚||或者需要每页显示的票头
    //创建类PdfEventHandler,在步骤二中
    PdfEventHandler handler = new PdfEventHandler(model, KT, ST, CN);//发票中的票头、购买方信息、表头都放在PdfEventHandler类中
    pdf.AddEventHandler(PdfDocumentEvent.START_PAGE, handler);
    ComputeValue computeValue = new ComputeValue();
    try
    {
        using (Document document = new Document(pdf, iText.Kernel.Geom.PageSize.A4, false))
        {
            //document.SetMargins(0, 0, 0, 0);
            //默认宽210mm=8.2677英寸=595磅
            //默认高29.7mm=11.6929英寸=842磅
            //默认边距36磅=0.5英寸=12.7mm

             // 定义自定义RGB颜色(例如,红色)
            DeviceRgb customColor = new DeviceRgb(128, 0, 0);
            //发票固定高度pt:票头,ht:购买方信息,et:票尾备注,kp:开票人
            float pt = 30, ht = 22, et = 20, kp = 8.5f;
		
		
            //下面代码中大量用到的computeValue.computeUnit()方法作用为:毫米转换磅
            #region 表中列表 
            //添加表格
            Table BodyTable = new Table(9, false);
            Cell cel11 = new Cell(1, 1)
                .SetTextAlignment(TextAlignment.CENTER)
                .SetWidth(computeValue.computeUnit(37))
                .SetHeight(computeValue.computeUnit(4.5f))
                .SetBorderRight(Border.NO_BORDER)
                .SetBorderBottom(Border.NO_BORDER)
                .SetBorderTop(Border.NO_BORDER)
                .SetFont(KT)
                .SetFontSize(9)
                .SetFontColor(customColor)
                .Add(new Paragraph("项目名称"));
            Cell cel12 = new Cell(1, 2)
                .SetTextAlignment(TextAlignment.LEFT)
                .SetWidth(computeValue.computeUnit(24))
                .SetBorder(Border.NO_BORDER)
                .SetFont(KT)
                .SetFontSize(9)
                .SetFontColor(customColor)
                .Add(new Paragraph("规格型号"));
            Cell cel13 = new Cell(1, 1)
                .SetTextAlignment(TextAlignment.CENTER)
                .SetWidth(computeValue.computeUnit(12))
                .SetBorder(Border.NO_BORDER)
                .SetFont(KT)
                .SetFontSize(9)
                .SetFontColor(customColor)
                .Add(new Paragraph("单位"));
            Cell cel14 = new Cell(1, 1)
                .SetTextAlignment(TextAlignment.RIGHT)
                .SetWidth(computeValue.computeUnit(25))
                .SetBorder(Border.NO_BORDER)
                .SetFont(KT)
                .SetFontSize(9)
                .SetFontColor(customColor)
                .Add(new Paragraph("数量"));
            Cell cel15 = new Cell(1, 1)
                .SetTextAlignment(TextAlignment.RIGHT)
                .SetWidth(computeValue.computeUnit(25))
                .SetBorder(Border.NO_BORDER)
                .SetFont(KT)
                .SetFontSize(9)
                .SetFontColor(customColor)
                .Add(new Paragraph("单价"));
            Cell cel16 = new Cell(1, 1)
                .SetTextAlignment(TextAlignment.RIGHT)
                .SetWidth(computeValue.computeUnit(26))
                .SetBorder(Border.NO_BORDER)
                .SetFont(KT)
                .SetFontSize(9)
                .SetFontColor(customColor)
                .Add(new Paragraph("金额"));
            Cell cel17 = new Cell(1, 1)
                .SetTextAlignment(TextAlignment.CENTER)
                .SetBorder(Border.NO_BORDER)
                .SetWidth(computeValue.computeUnit(25))
                .SetFont(KT)
                .SetFontSize(9)
                .SetFontColor(customColor)
                .Add(new Paragraph("税率/征收率"));
            Cell cel18 = new Cell(1, 1)
                .SetTextAlignment(TextAlignment.RIGHT)
                .SetWidth(computeValue.computeUnit(27))
                .SetBorderLeft(Border.NO_BORDER)
                .SetBorderBottom(Border.NO_BORDER)
                .SetBorderTop(Border.NO_BORDER)
                .SetFont(KT)
                .SetFontSize(9)
                .SetFontColor(customColor)
                .Add(new Paragraph("税额"));
            BodyTable.AddCell(cel11.SetBorder(new SolidBorder(customColor, 1)));
            BodyTable.AddCell(cel12);
            BodyTable.AddCell(cel13);
            BodyTable.AddCell(cel14);
            BodyTable.AddCell(cel15);
            BodyTable.AddCell(cel16);
            BodyTable.AddCell(cel17);
            BodyTable.AddCell(cel18.SetBorder(new SolidBorder(customColor, 1)));
            BodyTable.StartNewRow();

            //合计小计列
           
            //合计
            Cell cel41 = new Cell(1, 2)
                .SetTextAlignment(TextAlignment.CENTER)
                .SetHeight(computeValue.computeUnit(4.5f))
                .SetPaddingBottom(-5)
                .SetFont(KT)
               .SetFontSize(9)
                .SetFontColor(customColor)
                .Add(new Paragraph("合\t\t计").SetFixedLeading(11));
            Cell cel42 = new Cell(1, 5)
                .SetTextAlignment(TextAlignment.RIGHT)
                .SetHeight(computeValue.computeUnit(4.5f))
                .SetFont(ST)
                .SetFontSize(9)
                .Add(new Paragraph("¥" + model.hjje).SetFixedLeading(11));
            Cell cel43 = new Cell(1, 2)
               .SetTextAlignment(TextAlignment.RIGHT)
               .SetHeight(computeValue.computeUnit(4.5f))
               .SetFont(ST)
               .SetFontSize(9)
               .Add(new Paragraph("¥" + model.hjse).SetFixedLeading(11));

            //价税合计大小写
            ImageData data = ImageDataFactory.Create(Path.Combine(model.webHost, "images", "jiashuiheji.png"));
            Image img = new Image(data).SetWidth(15).SetHeight(15);

            Cell cel51 = new Cell(1, 2)
                .SetHeight(computeValue.computeUnit(8))
                .SetWidth(computeValue.computeUnit(50))
                .SetBorderBottom(Border.NO_BORDER)
                .SetVerticalAlignment(VerticalAlignment.MIDDLE)
                .SetTextAlignment(TextAlignment.CENTER)
                .SetFont(KT)
                .SetFontSize(9)
                .SetFontColor(customColor)
               .Add(new Paragraph("价税合计(大写)"));
           
            Cell cel53 = new Cell(1, 4)
                .SetBorderLeft(Border.NO_BORDER)
                .SetBorderRight(Border.NO_BORDER)
                .SetBorderBottom(Border.NO_BORDER)
                .SetHeight(computeValue.computeUnit(8))
                .SetVerticalAlignment(VerticalAlignment.MIDDLE)
                .SetTextAlignment(TextAlignment.LEFT)
                .Add(new Paragraph(model.jshjdx).SetFont(ST).SetFontSize(10).SetFirstLineIndent(18))
                .Add(new Image(ImageDataFactory.Create(Path.Combine(model.webHost, "images", "jiashuiheji.png"))).SetWidth(15).SetHeight(15));
            Cell cel55 = new Cell(1, 1)
                .SetBorderLeft(Border.NO_BORDER)
                .SetBorderRight(Border.NO_BORDER)
                .SetBorderBottom(Border.NO_BORDER)
                .SetVerticalAlignment(VerticalAlignment.MIDDLE)
                .SetHeight(computeValue.computeUnit(8))
                .SetTextAlignment(TextAlignment.RIGHT)
                .Add(new Paragraph("(小写)").SetFont(KT).SetFontSize(9).SetFontColor(customColor));
            Cell cel54 = new Cell(1, 2)
                .SetBorderLeft(Border.NO_BORDER)
                .SetHeight(computeValue.computeUnit(8))
               .SetBorderBottom(Border.NO_BORDER)
               .SetVerticalAlignment(VerticalAlignment.MIDDLE)
               .SetTextAlignment(TextAlignment.LEFT)
               .Add(new Paragraph("¥" + model.jshj).SetFont(ST).SetFontSize(10));


            #region 表尾
            //添加表格
            Table endTable = new Table(2, false);
            Cell cel61 = new Cell(1, 1)
                .SetWidth(computeValue.computeUnit(6))
                .SetHeight(computeValue.computeUnit(20))
                .SetVerticalAlignment(VerticalAlignment.MIDDLE)
                .SetFont(KT)
                .SetFontSize(9)
                .SetFontColor(customColor)
                .Add(new Paragraph("备注"));
            Cell cel62 = new Cell(1, 8)
                .SetTextAlignment(TextAlignment.LEFT)
                .SetVerticalAlignment(VerticalAlignment.MIDDLE)
                .SetWidth(computeValue.computeUnit(195))
                .SetHeight(computeValue.computeUnit(20))
                .SetFont(ST)
                .SetFontSize(10)
                .Add(new Paragraph(model.bz));

            #endregion

            #region 开票人
            // 添加发票内容
            Paragraph ending = new Paragraph()
                .Add("开票人:")
                .SetFont(KT)
                .SetFontSize(9)
                .SetFontColor(customColor)
                .SetTextAlignment(TextAlignment.LEFT);
            Paragraph endingname = new Paragraph()
                .Add( model.kpr)
                .SetFont(ST)
                .SetFontSize(10)
                .SetTextAlignment(TextAlignment.LEFT);
            #endregion


            //循环存放数据
            int i = 0, j = model.medis.Count;
            float XJJE=0,XJSE=0,sumh=0,oldsumh=0;
            float gh = pt + ht + et + kp;
            bool flag=false;
            for (i = 0; i < j; i++)
            {
                //计算每行高度
                //商品名长度
                int mcleng =computeValue.GetStrLength(model.medis[i].xmmc)-1;//方法computeValue.GetStrLength()作用为获取字符串长度
                int ggleng= computeValue.GetStrLength(model.medis[i].ggxh);
                float higth = (mcleng % 8 == 0 ? mcleng / 8 : mcleng / 8 + 1)>(ggleng % 6 == 0 ? ggleng / 6 : ggleng / 6 + 1)? (mcleng % 8 == 0 ? mcleng / 8 : mcleng / 8 + 1): (ggleng % 6 == 0 ? ggleng / 6 : ggleng / 6 + 1);
                sumh += higth;

                Cell cel121 = new Cell(1, 1)
                    .SetTextAlignment(TextAlignment.CENTER)
                    .SetWidth(computeValue.computeUnit(37))
                    .SetHeight(computeValue.computeUnit((float)(higth * 4.375)))
                    .SetFont(ST)
                    .SetFontSize(10)
                    .Add(new Paragraph(model.medis[i].xmmc).SetFixedLeading(12));
                Cell cel122 = new Cell(1, 2)
                    .SetTextAlignment(TextAlignment.LEFT)
                    .SetWidth(computeValue.computeUnit(24))
                    .SetHeight(computeValue.computeUnit((float)(higth * 4.375)))
                    .SetFont(ST)
                    .SetFontSize(10)
                    .SetSplitCharacters(new KeepAllSplitCharacters())
                    .Add(new Paragraph(model.medis[i].ggxh).SetFixedLeading(12).SetWidth(computeValue.computeUnit(24)));
                Cell cel123 = new Cell(1, 1)
                    .SetTextAlignment(TextAlignment.CENTER)
                    .SetWidth(computeValue.computeUnit(12))
                    .SetHeight(computeValue.computeUnit((float)(higth * 4.375)))
                    .SetFont(ST)
                    .SetFontSize(10)
                    .Add(new Paragraph(model.medis[i].dw).SetFixedLeading(12));
                Cell cel124 = new Cell(1, 1)
                    .SetTextAlignment(TextAlignment.RIGHT)
                    .SetWidth(computeValue.computeUnit(25))
                    .SetHeight(computeValue.computeUnit((float)(higth * 4.375)))
                    .SetFont(ST)
                    .SetFontSize(10)
                    .Add(new Paragraph(model.medis[i].sl).SetFixedLeading(12));
                Cell cel125 = new Cell(1, 1)
                    .SetTextAlignment(TextAlignment.RIGHT)
                    .SetWidth(computeValue.computeUnit(25))
                   .SetHeight(computeValue.computeUnit((float)(higth * 4.375)))
                    .SetFont(ST)
                    .SetFontSize(10)
                    .Add(new Paragraph(model.medis[i].dj).SetFixedLeading(12));
                Cell cel126 = new Cell(1, 1)
                    .SetTextAlignment(TextAlignment.RIGHT)
                    .SetWidth(computeValue.computeUnit(26))
                    .SetHeight(computeValue.computeUnit((float)(higth * 4.375)))
                    .SetFont(ST)
                    .SetFontSize(10)
                    .Add(new Paragraph(model.medis[i].je).SetFixedLeading(12));
                Cell cel127 = new Cell(1, 1)
                    .SetTextAlignment(TextAlignment.CENTER)
                    .SetWidth(computeValue.computeUnit(25))
                    .SetHeight(computeValue.computeUnit((float)(higth * 4.375)))
                    .SetFont(ST)
                    .SetFontSize(10)
                    .Add(new Paragraph(model.medis[i].slv).SetFixedLeading(12));
                Cell cel128 = new Cell(1, 1)
                    .SetTextAlignment(TextAlignment.RIGHT)
                    .SetWidth(computeValue.computeUnit(27))
                    .SetHeight(computeValue.computeUnit((float)(higth * 4.375)))
                    .SetFont(ST)
                    .SetFontSize(10)
                    .Add(new Paragraph(model.medis[i].se).SetFixedLeading(12));

                BodyTable.AddCell(cel121.SetBorder(new SolidBorder(customColor, 1)).SetBorderRight(Border.NO_BORDER).SetBorderBottom(Border.NO_BORDER).SetBorderTop(Border.NO_BORDER));
                BodyTable.AddCell(cel122.SetBorder(Border.NO_BORDER));
                BodyTable.AddCell(cel123.SetBorder(Border.NO_BORDER));
                BodyTable.AddCell(cel124.SetBorder(Border.NO_BORDER));
                BodyTable.AddCell(cel125.SetBorder(Border.NO_BORDER));
                BodyTable.AddCell(cel126.SetBorder(Border.NO_BORDER));
                BodyTable.AddCell(cel127.SetBorder(Border.NO_BORDER));
                BodyTable.AddCell(cel128.SetBorder(new SolidBorder(customColor, 1)).SetBorderLeft(Border.NO_BORDER).SetBorderBottom(Border.NO_BORDER).SetBorderTop(Border.NO_BORDER));
                BodyTable.StartNewRow();//创建新行

                // 添加分页
                //不足一页或刚好一页得情况
                //小计
                XJJE += float.Parse(model.medis[i].je);
                XJSE+= float.Parse(model.medis[i].se);
                
                if (sumh <= 35&& i+1==j)
                {
                    //中间高度
                    float nh = 140 - gh + 25;
                    //有分页的情况
                    if (flag)
                    {
                        //中间高度加8
                        //小计
                        Cell cel411 = new Cell(1, 2)
                               .SetTextAlignment(TextAlignment.CENTER)
                               .SetHeight(computeValue.computeUnit(4.5f))
                               .SetFont(KT)
                               .SetFontSize(9)
                               .SetFontColor(customColor)
                               .SetPaddingBottom(-5)
                               .Add(new Paragraph("小\t\t计").SetFixedLeading(11));
                        Cell cel421 = new Cell(1, 5)
                            .SetBorder(Border.NO_BORDER)
                            .SetTextAlignment(TextAlignment.RIGHT)
                            .SetHeight(computeValue.computeUnit(4.5f))
                            .SetFont(ST)
                            .SetFontSize(9)
                            .Add(new Paragraph("¥" + XJJE).SetFixedLeading(11));
                        Cell cel431 = new Cell(1, 2)
                           .SetTextAlignment(TextAlignment.RIGHT)
                           .SetHeight(computeValue.computeUnit(4.5f))
                           .SetFont(ST)
                           .SetFontSize(9)
                           .Add(new Paragraph("¥" + XJSE).SetFixedLeading(11));
                        //合计小计列
                        BodyTable.AddCell(cel411.SetBorder(new SolidBorder(customColor, 1)).SetBorderBottom(Border.NO_BORDER).SetBorderTop(Border.NO_BORDER).SetBorderRight(Border.NO_BORDER));
                        BodyTable.AddCell(cel421.SetBorder(Border.NO_BORDER));
                        BodyTable.AddCell(cel431.SetBorder(new SolidBorder(customColor, 1)).SetBorderLeft(Border.NO_BORDER).SetBorderBottom(Border.NO_BORDER).SetBorderTop(Border.NO_BORDER));
                        BodyTable.StartNewRow();
                    }
                    //不够一页的情况
                    //合计列
                    BodyTable.AddCell(cel41.SetBorder(new SolidBorder(customColor, 1)).SetBorderBottom(Border.NO_BORDER).SetBorderTop(Border.NO_BORDER).SetBorderRight(Border.NO_BORDER));
                    BodyTable.AddCell(cel42.SetBorder(Border.NO_BORDER));
                    BodyTable.AddCell(cel43.SetBorder(new SolidBorder(customColor, 1)).SetBorderLeft(Border.NO_BORDER).SetBorderBottom(Border.NO_BORDER).SetBorderTop(Border.NO_BORDER));

                    BodyTable.StartNewRow();//新增行
                    //价税合计大小写
                    BodyTable.AddCell(cel51.SetBorder(new SolidBorder(customColor, 1)));
                    
                    //BodyTable.AddCell(cel52.SetBorder(new SolidBorder(customColor, 1)));
                    BodyTable.AddCell(cel53.SetBorder(new SolidBorder(customColor, 1)));
                    BodyTable.AddCell(cel55.SetBorder(new SolidBorder(customColor, 1)));
                    BodyTable.AddCell(cel54.SetBorder(new SolidBorder(customColor, 1)));
                    BodyTable.StartNewRow();//新增行

                    
                    float lasth=0;
                    if (sumh <= 8)
                    {
                        lasth = 8-sumh;
                    }
                    else if (sumh <= 12)
                    {
                        nh += 17.5f*1;
                        lasth = 12 - sumh;
                    }
                    else if (sumh <= 16)
                    {
                        nh += 17.5f * 2;
                        lasth = 16 - sumh;
                    }
                    else if (sumh <= 20)
                    {
                        nh += 17.5f * 3;
                        lasth = 20 - sumh;
                    }
                    else if (sumh <= 24)
                    {
                        nh += 17.5f * 4;
                        lasth = 24 - sumh;
                    }
                    else if (sumh <= 28)
                    {
                        nh += 17.5f * 5;
                        lasth = 28 - sumh;
                    }
                    else if (sumh <= 32)
                    {
                        nh += 17.5f * 6;
                        lasth = 32 - sumh;
                    }
                    else if (sumh <= 36)
                    {
                        nh += 17.5f * 7;
                        lasth = 36 - sumh;
                    }
                    else if (sumh <= 40)
                    {
                        nh += 17.5f * 8;
                        lasth = 40 - sumh;
                    }

                    //设置最后一行行高,因为不足一页时,最后一行可能需要占用多行行高
                    var bzh = computeValue.computeUnit((higth + lasth) * 4.375f);
                    cel121.SetHeight(bzh);
                    cel122.SetHeight(bzh);
                    cel123.SetHeight(bzh);
                    cel124.SetHeight(bzh);
                    cel125.SetHeight(bzh);
                    cel126.SetHeight(bzh);
                    cel127.SetHeight(bzh);
                    cel128.SetHeight(bzh);

                    BodyTable.SetHeight(computeValue.computeUnit(nh));//给表设置高度

                    document.Add(BodyTable.SetFixedPosition(computeValue.computeUnit(4.5f), computeValue.computeUnit(243- nh) , computeValue.computeUnit(201)));
                   

                    //表尾备注
                    endTable.AddCell(cel61.SetBorder(new SolidBorder(customColor, 1)));
                    endTable.AddCell(cel62.SetBorder(new SolidBorder(customColor, 1)));
                    float b = computeValue.computeUnit(241 - 20- nh) ;
                    document.Add(endTable.SetFixedPosition(computeValue.computeUnit(4.5f), b, computeValue.computeUnit(201)));

                    //价税合计图片
                    //document.Add(img.SetFixedPosition(computeValue.computeUnit(51.5f), b + computeValue.computeUnit(24)));
                    //开票人
                    document.Add(ending.SetFixedPosition(computeValue.computeUnit(18), b - computeValue.computeUnit((float)8.5), computeValue.computeUnit(183)));
                    document.Add(endingname.SetFixedPosition(computeValue.computeUnit(29), b - computeValue.computeUnit((float)8.5), computeValue.computeUnit(183)));
                    sumh = 0;
                }
                //分页的情况
                else if (((sumh-higth >= 36) && (sumh - higth <= 39)&& i != 0 && i + 1 != j)|| (sumh>= 33)&& i + 2 == j)
                {
                    //小计
                    Cell cel411 = new Cell(1, 2)
                       .SetTextAlignment(TextAlignment.CENTER)
                       .SetHeight(computeValue.computeUnit(4.5f))
                       .SetFont(KT)
                       .SetFontSize(9)
                       .SetFontColor(customColor)
                       .SetPaddingBottom(-5)
                       .Add(new Paragraph("小\t\t计").SetFixedLeading(11));
                    Cell cel421 = new Cell(1, 5)
                        .SetBorder(Border.NO_BORDER)
                        .SetTextAlignment(TextAlignment.RIGHT)
                        .SetHeight(computeValue.computeUnit(4.5f))
                        .SetFont(ST)
                        .SetFontSize(9)
                        .Add(new Paragraph("¥" + XJJE).SetFixedLeading(11));
                    Cell cel431 = new Cell(1, 2)
                       .SetTextAlignment(TextAlignment.RIGHT)
                       .SetHeight(computeValue.computeUnit(4.5f))
                       .SetFont(ST)
                       .SetFontSize(9)
                       .Add(new Paragraph("¥" +XJSE).SetFixedLeading(11));
                    //合计小计列
                    BodyTable.AddCell(cel411.SetBorder(new SolidBorder(customColor, 1)).SetBorderBottom(Border.NO_BORDER).SetBorderTop(Border.NO_BORDER).SetBorderRight(Border.NO_BORDER));
                    BodyTable.AddCell(cel421.SetBorder(Border.NO_BORDER));
                    BodyTable.AddCell(cel431.SetBorder(new SolidBorder(customColor, 1)).SetBorderLeft(Border.NO_BORDER).SetBorderBottom(Border.NO_BORDER).SetBorderTop(Border.NO_BORDER));
                    BodyTable.StartNewRow();
                    BodyTable.AddCell(cel41.SetBorder(new SolidBorder(customColor, 1)).SetBorderTop(Border.NO_BORDER).SetBorderRight(Border.NO_BORDER));
                    BodyTable.AddCell(cel42.SetBorder(new SolidBorder(customColor, 1)).SetBorderLeft(Border.NO_BORDER).SetBorderTop(Border.NO_BORDER).SetBorderRight(Border.NO_BORDER));
                    BodyTable.AddCell(cel43.SetBorder(new SolidBorder(customColor, 1)).SetBorderLeft(Border.NO_BORDER).SetBorderTop(Border.NO_BORDER));
                    BodyTable.StartNewRow();

                    //float nh =(sumh-oldsumh)*4.375f+13.5f+38;//判断中间列表占用高度--> i * computeValue.computeUnit(10):每行数据的高度;+ computeValue.computeUnit(10):表头高度+合计行的高度;(i*15):每行数据的行间距
                    float nh = (sumh) * 4.375f + 13.5f + 38;

                    BodyTable.SetHeight(computeValue.computeUnit(nh));
                    BodyTable.SetBorderBottom(new SolidBorder(customColor, 1));
                    document.Add(BodyTable.SetFixedPosition(computeValue.computeUnit(4.5f), computeValue.computeUnit(243- nh) , computeValue.computeUnit(201)));

                    //开票人
                    document.Add(ending.SetFixedPosition(computeValue.computeUnit(18), computeValue.computeUnit(243- nh- 9) , computeValue.computeUnit(183)));
                    document.Add(endingname.SetFixedPosition(computeValue.computeUnit(29), computeValue.computeUnit(243- nh- 9) , computeValue.computeUnit(183)));
                    
                    //分页
                    document.Add(new AreaBreak());
                    
                    BodyTable = new Table(9, false);
                    #region 表头
                    Cell cel110 = new Cell(1, 1)
                          .SetTextAlignment(TextAlignment.CENTER)
                          .SetWidth(computeValue.computeUnit(37))
                          .SetHeight(computeValue.computeUnit(4.5f))
                          .SetBorderRight(Border.NO_BORDER)
                          .SetBorderBottom(Border.NO_BORDER)
                          .SetBorderTop(Border.NO_BORDER)
                          .SetFont(KT)
                          .SetFontSize(9)
                          .SetFontColor(customColor)
                          .Add(new Paragraph("项目名称"));
                    Cell cel120 = new Cell(1, 2)
                        .SetTextAlignment(TextAlignment.LEFT)
                        .SetWidth(computeValue.computeUnit(24))
                        .SetBorder(Border.NO_BORDER)
                        .SetFont(KT)
                        .SetFontSize(9)
                        .SetFontColor(customColor)
                        .Add(new Paragraph("规格型号"));
                    Cell cel130 = new Cell(1, 1)
                        .SetTextAlignment(TextAlignment.CENTER)
                        .SetWidth(computeValue.computeUnit(12))
                        .SetBorder(Border.NO_BORDER)
                        .SetFont(KT)
                        .SetFontSize(9)
                        .SetFontColor(customColor)
                        .Add(new Paragraph("单位"));
                    Cell cel140 = new Cell(1, 1)
                        .SetTextAlignment(TextAlignment.RIGHT)
                        .SetWidth(computeValue.computeUnit(25))
                        .SetBorder(Border.NO_BORDER)
                        .SetFont(KT)
                        .SetFontSize(9)
                        .SetFontColor(customColor)
                        .Add(new Paragraph("数量"));
                    Cell cel150 = new Cell(1, 1)
                        .SetTextAlignment(TextAlignment.RIGHT)
                        .SetWidth(computeValue.computeUnit(25))
                        .SetBorder(Border.NO_BORDER)
                        .SetFont(KT)
                        .SetFontSize(9)
                        .SetFontColor(customColor)
                        .Add(new Paragraph("单价"));
                    Cell cel160 = new Cell(1, 1)
                        .SetTextAlignment(TextAlignment.RIGHT)
                        .SetWidth(computeValue.computeUnit(26))
                        .SetBorder(Border.NO_BORDER)
                        .SetFont(KT)
                        .SetFontSize(9)
                        .SetFontColor(customColor)
                        .Add(new Paragraph("金额"));
                    Cell cel170 = new Cell(1, 1)
                        .SetTextAlignment(TextAlignment.CENTER)
                        .SetBorder(Border.NO_BORDER)
                        .SetWidth(computeValue.computeUnit(25))
                        .SetFont(KT)
                        .SetFontSize(9)
                        .SetFontColor(customColor)
                        .Add(new Paragraph("税率/征收率"));
                    Cell cel180 = new Cell(1, 1)
                        .SetTextAlignment(TextAlignment.RIGHT)
                        .SetWidth(computeValue.computeUnit(27))
                        .SetBorderLeft(Border.NO_BORDER)
                        .SetBorderBottom(Border.NO_BORDER)
                        .SetBorderTop(Border.NO_BORDER)
                        .SetFont(KT)
                        .SetFontSize(9)
                        .SetFontColor(customColor)
                        .Add(new Paragraph("税额"));
                    BodyTable.AddCell(cel110.SetBorder(new SolidBorder(customColor, 1)));
                    BodyTable.AddCell(cel120);
                    BodyTable.AddCell(cel130);
                    BodyTable.AddCell(cel140);
                    BodyTable.AddCell(cel150);
                    BodyTable.AddCell(cel160);
                    BodyTable.AddCell(cel170);
                    BodyTable.AddCell(cel180.SetBorder(new SolidBorder(customColor, 1)));
                    BodyTable.StartNewRow();
                    #endregion

                    XJJE = 0; XJSE = 0;
                    //oldsumh = sumh;
                    sumh = 0;
                    flag = true;
                    continue;
                }
                

            //添加页码
            int n=pdf.GetNumberOfPages();
            if (n>1)
            {
                for (int p = 2; p <= n; p++)
                {
                    document.ShowTextAligned(new Paragraph(String
                    .Format("共" + n + "页 第" + p+"页")).SetFontSize(10).SetFont(ST),
                    computeValue.computeUnit(200), computeValue.computeUnit(272), p, TextAlignment.RIGHT,
                    VerticalAlignment.TOP, 0);
                }
            }
            // 关闭文档
            document.Close();

            Console.WriteLine("PDF发票已生成:" + outputPath);
        }
    }
    catch (Exception e)
    {
        Console.WriteLine(e.Message);
        throw;
    }
    
}


/// <summary>
/// 金额转换成中文大写金额
/// </summary>
/// <param name="LowerMoney">eg:10.74</param>
/// <returns></returns>
private static string MoneyToUpper(string LowerMoney)
{
    string functionReturnValue = null;
    bool IsNegative = false; // 是否是负数
    if (LowerMoney.Trim().Substring(0, 1) == "-")
    {
        // 是负数则先转为正数
        LowerMoney = LowerMoney.Trim().Remove(0, 1);
        IsNegative = true;
    }
    string strLower = null;
    string strUpart = null;
    string strUpper = null;
    int iTemp = 0;
    // 保留两位小数 123.489→123.49  123.4→123.4
    LowerMoney = Math.Round(double.Parse(LowerMoney), 2).ToString();
    if (LowerMoney.IndexOf(".") > 0)
    {
        if (LowerMoney.IndexOf(".") == LowerMoney.Length - 2)
        {
            LowerMoney = LowerMoney + "0";
        }
    }
    else
    {
        LowerMoney = LowerMoney + ".00";
    }
    strLower = LowerMoney;
    iTemp = 1;
    strUpper = "";
    while (iTemp <= strLower.Length)
    {
        switch (strLower.Substring(strLower.Length - iTemp, 1))
        {
            case ".":
                strUpart = "圆";
                break;
            case "0":
                strUpart = "零";
                break;
            case "1":
                strUpart = "壹";
                break;
            case "2":
                strUpart = "贰";
                break;
            case "3":
                strUpart = "叁";
                break;
            case "4":
                strUpart = "肆";
                break;
            case "5":
                strUpart = "伍";
                break;
            case "6":
                strUpart = "陆";
                break;
            case "7":
                strUpart = "柒";
                break;
            case "8":
                strUpart = "捌";
                break;
            case "9":
                strUpart = "玖";
                break;
        }

        switch (iTemp)
        {
            case 1:
                strUpart = strUpart + "分";
                break;
            case 2:
                strUpart = strUpart + "角";
                break;
            case 3:
                strUpart = strUpart + "";
                break;
            case 4:
                strUpart = strUpart + "";
                break;
            case 5:
                strUpart = strUpart + "拾";
                break;
            case 6:
                strUpart = strUpart + "佰";
                break;
            case 7:
                strUpart = strUpart + "仟";
                break;
            case 8:
                strUpart = strUpart + "万";
                break;
            case 9:
                strUpart = strUpart + "拾";
                break;
            case 10:
                strUpart = strUpart + "佰";
                break;
            case 11:
                strUpart = strUpart + "仟";
                break;
            case 12:
                strUpart = strUpart + "亿";
                break;
            case 13:
                strUpart = strUpart + "拾";
                break;
            case 14:
                strUpart = strUpart + "佰";
                break;
            case 15:
                strUpart = strUpart + "仟";
                break;
            case 16:
                strUpart = strUpart + "万";
                break;
            default:
                strUpart = strUpart + "";
                break;
        }

        strUpper = strUpart + strUpper;
        iTemp = iTemp + 1;
    }

    strUpper = strUpper.Replace("零拾", "零");
    strUpper = strUpper.Replace("零佰", "零");
    strUpper = strUpper.Replace("零仟", "零");
    strUpper = strUpper.Replace("零零零", "零");
    strUpper = strUpper.Replace("零零", "零");
    strUpper = strUpper.Replace("零角零分", "整");
    strUpper = strUpper.Replace("零分", "整");
    strUpper = strUpper.Replace("零角", "零");
    strUpper = strUpper.Replace("零亿零万零圆", "亿圆");
    strUpper = strUpper.Replace("亿零万零圆", "亿圆");
    strUpper = strUpper.Replace("零亿零万", "亿");
    strUpper = strUpper.Replace("零万零圆", "万圆");
    strUpper = strUpper.Replace("零亿", "亿");
    strUpper = strUpper.Replace("零万", "万");
    strUpper = strUpper.Replace("零圆", "圆");
    strUpper = strUpper.Replace("零零", "零");
    Console.WriteLine("零角零分");
    // 对壹圆以下的金额的处理
    if (strUpper.Substring(0, 1) == "圆")
    {
        strUpper = strUpper.Substring(1, strUpper.Length - 1);
    }
    if (strUpper.Substring(0, 1) == "零")
    {
        strUpper = strUpper.Substring(1, strUpper.Length - 1);
    }
    if (strUpper.Substring(0, 1) == "角")
    {
        strUpper = strUpper.Substring(1, strUpper.Length - 1);
    }
    if (strUpper.Substring(0, 1) == "分")
    {
        strUpper = strUpper.Substring(1, strUpper.Length - 1);
    }
    if (strUpper.Substring(0, 1) == "整")
    {
        strUpper = "零圆整";
    }
    functionReturnValue = strUpper;

    if (IsNegative == true)
    {
        return "负" + functionReturnValue;
    }
    else
    {
        return string.Format(functionReturnValue, Encoding.GetEncoding("GB2312"));
    }
}

public class ComputeValue
{
    /// <summary>
    /// 毫米转换磅
    /// </summary>
    /// <param name="millimetre"></param>
    /// <returns></returns>
    public float computeUnit(float millimetre)
    {
        return millimetre / 10 / 2.54f * 72;
    }
    /// <summary>
    /// 获取字符串长度
    /// </summary>
    /// <param name="str"></param>
    /// <returns></returns>
    public int GetStrLength(string str)
    {
        double length = 0;
        str = str.Replace(" ", "");
        for (int i = 0; i < str.Length; i++) 
        {
            if (str[i] >= 0x4E00 && str[i] <= 0x9FA5)
            {
                length += 1;
            }
            else
            {
                length += 0.5;
            }
        }
        return (int)Math.Ceiling(length);
    }
}

步骤二:创建PdfEventHandler类:

/// <summary>
/// 需要继承IEventHandler
/// </summary>
public class PdfEventHandler : IEventHandler
{
    private NaturalSystemPdfModel _model;
    private PdfFont KT;
    private PdfFont ST;
    private PdfFont CN;
    //构造方法:带入模型以及字体
    public PdfEventHandler(NaturalSystemPdfModel model, PdfFont kt, PdfFont st, PdfFont cn) 
    {
        _model = model;
        KT = kt;
        ST = st;
        CN = cn;
    }
    public void HandleEvent(Event e)
    {
        PdfDocumentEvent docEvent = (PdfDocumentEvent)e;
        PdfDocument pdfDoc = docEvent.GetDocument();
        PdfPage page = docEvent.GetPage();
        PdfCanvas pdfCanvas = new PdfCanvas(page.NewContentStreamBefore(), page.GetResources(), pdfDoc);
        Rectangle pageSize = page.GetPageSize();


        ComputeValue computeValue = new ComputeValue();
        // 定义自定义RGB颜色(例如,红色)
        DeviceRgb customColor = new DeviceRgb(128, 0, 0);

        Canvas canvas = new Canvas(pdfCanvas, pageSize);

		#region 票头
        
        #region 双横线
        //添加横线
        pdfCanvas.MoveTo(computeValue.computeUnit(141), computeValue.computeUnit(278.5f));
        pdfCanvas.LineTo(computeValue.computeUnit(69), computeValue.computeUnit(278.5f));
        pdfCanvas.SetStrokeColor(new DeviceRgb(128, 0, 0));
        pdfCanvas.MoveTo(computeValue.computeUnit(141), computeValue.computeUnit(277.5f));
        pdfCanvas.LineTo(computeValue.computeUnit(69), computeValue.computeUnit(277.5f));
        pdfCanvas.SetStrokeColor(new DeviceRgb(128, 0, 0));
        pdfCanvas.ClosePathStroke();
        #endregion
        
        #region 票头左边 二维码、标签码
        // 添加动态二维码
        Image EWM = new Image(ImageDataFactory.Create(_model.qrCode))
            .SetWidth(computeValue.computeUnit(20))
            .SetHeight(computeValue.computeUnit(20));
        canvas.Add(EWM.SetFixedPosition(1, computeValue.computeUnit(7), computeValue.computeUnit(271)));
        //二维码中间的“税”字图标
        Image S = new Image(ImageDataFactory.Create(System.IO.Path.Combine(_model.webHost, "images", "Shui.png")))
            .SetWidth(computeValue.computeUnit(4))
            .SetHeight(computeValue.computeUnit(4));
        canvas.Add(S.SetFixedPosition(1, computeValue.computeUnit(15), computeValue.computeUnit((float)279)));

        //Image EWM = new BarcodeQRCode("", 54, 56, null);

        //添加标签
        //Image BQM = new Image(ImageDataFactory.Create("E://111.png"))
        //    .SetWidth(computeValue.computeUnit(28))
        //    .SetHeight(computeValue.computeUnit(20));
        //canvas.Add(BQM.SetFixedPosition(1, computeValue.computeUnit(29), computeValue.computeUnit(271)));
        #endregion

        #region 票头文字及印章
        // 添加发票内容
        Paragraph heading = new Paragraph(_model.type)
            .SetTextAlignment(TextAlignment.CENTER)
            .SetFont(KT)
            .SetFontColor(customColor)
            .SetFontSize(19);
        if (_model.type.Contains("增值税"))
        {
            canvas.Add(heading.SetFixedPosition(computeValue.computeUnit(56), computeValue.computeUnit(280.35f), computeValue.computeUnit(100)));
        }
        else 
        {
            canvas.Add(heading.SetFixedPosition(computeValue.computeUnit(72), computeValue.computeUnit(280.35f), computeValue.computeUnit(70)));
        }

        // 添加发票章图片./Images/fapiaozhang.png
        Image stamp = new Image(ImageDataFactory.Create(System.IO.Path.Combine(_model.webHost, "images", "fapiaozhang.png")))
            .SetWidth(computeValue.computeUnit(28))
            .SetHeight(computeValue.computeUnit(20));
        canvas.Add(stamp.SetFixedPosition(1, computeValue.computeUnit(92), computeValue.computeUnit(269)));
        #endregion

        #region 票头右上角信息
        // 发票号码:
        Paragraph invoiceInfo_Num = new Paragraph()
            .Add("发票号码:")
            .SetFont(KT)
            .SetFontSize(9)
            .SetFontColor(customColor)
            .SetTextAlignment(TextAlignment.LEFT);
        canvas.Add(invoiceInfo_Num.SetFixedPosition(computeValue.computeUnit(155), computeValue.computeUnit(280.65f), computeValue.computeUnit(19.06f)));
        Paragraph invoiceInfo_Numc = new Paragraph()
           .Add(_model.fphm)
           .SetFont(ST)
           .SetFontSize(9)
           .SetTextAlignment(TextAlignment.LEFT);
        canvas.Add(invoiceInfo_Numc.SetFixedPosition(computeValue.computeUnit(170), computeValue.computeUnit(280.65f), computeValue.computeUnit(33.36f)));
        // 开票日期:
        Paragraph invoiceInfo_Date = new Paragraph()
            .Add("开票日期: ")
            .SetFont(KT)
            .SetFontSize(9)
            .SetFontColor(customColor)
            .SetTextAlignment(TextAlignment.LEFT);
        canvas.Add(invoiceInfo_Date.SetFixedPosition(computeValue.computeUnit(155), computeValue.computeUnit(274.5f), computeValue.computeUnit(19.06f)));
        Paragraph invoiceInfo_Datec = new Paragraph()
           .Add(_model.kprq.ToString("yyyy年MM月dd日"))
           .SetFont(ST)
           .SetFontSize(9)
           .SetTextAlignment(TextAlignment.LEFT);
        canvas.Add(invoiceInfo_Datec.SetFixedPosition(computeValue.computeUnit(170), computeValue.computeUnit(274.5f), computeValue.computeUnit(33.36f)));
        #endregion
		#endregion

        #region 购买方信息
        //添加表格
        Table HeadTable = new Table(4, false);
        Cell cel01 = new Cell(1, 1)
            .SetTextAlignment((TextAlignment)TextAlignment.CENTER)
            .SetWidth(computeValue.computeUnit(6))
            .SetHeight(computeValue.computeUnit(22))
            .Add(new Paragraph("购买方信息").SetFixedLeading(12).SetFontColor(customColor).SetFont(KT).SetFontSize(9).SetFontColor(customColor));
        Cell cel02 = new Cell(1, 1)
            .SetTextAlignment(TextAlignment.LEFT)
            .SetVerticalAlignment(VerticalAlignment.MIDDLE)
            .SetWidth(computeValue.computeUnit(94.5f))
            .SetHeight(computeValue.computeUnit(22))
            .Add(new Paragraph("名称:").SetFontColor(customColor).SetFont(KT).SetFontSize(9).SetFontColor(customColor).Add(new Text(_model.gmfmc).SetFontSize(10).SetFont(ST).SetFontColor(ColorConstants.BLACK)))
            .Add(new Paragraph("统一社会信用代码/纳税人识别号:").SetFontColor(customColor).SetFont(KT).SetFontSize(9).SetFontColor(customColor).Add(new Text(_model.gmfnsrsbh).SetFontSize(10).SetFont(ST).SetFontColor(ColorConstants.BLACK)));
        Cell cel03 = new Cell(1, 1)
            .SetTextAlignment(TextAlignment.CENTER)
            .SetWidth(computeValue.computeUnit(6))
            .SetHeight(computeValue.computeUnit(22))
            .Add(new Paragraph("销售方信息").SetFixedLeading(12).SetFontColor(customColor).SetFont(KT).SetFontSize(9).SetFontColor(customColor));
        Cell cel04 = new Cell(1, 1)
           .SetTextAlignment(TextAlignment.LEFT)
            .SetVerticalAlignment(VerticalAlignment.MIDDLE)
            .SetWidth(computeValue.computeUnit(94.5f))
            .SetHeight(computeValue.computeUnit(22))
            .Add(new Paragraph("名称:").SetFontColor(customColor).SetFont(KT).SetFontSize(9).SetFontColor(customColor).Add(new Text(_model.xsfmc).SetFontSize(10).SetFont(ST).SetFontColor(ColorConstants.BLACK)))
            .Add(new Paragraph("统一社会信用代码/纳税人识别号:").SetFontColor(customColor).SetFont(KT).SetFontSize(9).SetFontColor(customColor).Add(new Text(_model.xsfnsrsbh).SetFontSize(10).SetFont(ST).SetFontColor(ColorConstants.BLACK)));

        HeadTable.AddCell(cel01.SetBorder(new SolidBorder(customColor, 1)));
        HeadTable.AddCell(cel02.SetBorder(new SolidBorder(customColor, 1)));
        HeadTable.AddCell(cel03.SetBorder(new SolidBorder(customColor, 1)));
        HeadTable.AddCell(cel04.SetBorder(new SolidBorder(customColor, 1)));
        canvas.Add(HeadTable.SetFixedPosition(computeValue.computeUnit(4.5f), computeValue.computeUnit(243), computeValue.computeUnit(201)));
        #endregion

        // 添加页脚页码
        //if (pdfDoc.GetNumberOfPages() > 1)
        //{
        //    #region 页眉
        //    Paragraph p = new Paragraph("共" + pdfDoc.GetNumberOfPages() + "页 第" + pdfDoc.GetPageNumber(page) + "页")
        //    .SetFontSize(9)
        //    .SetFont(ST)
        //    .SetFixedPosition(computeValue.computeUnit(186), computeValue.computeUnit(266.5f), computeValue.computeUnit(141));
        //    canvas.Add(p);
        //    #endregion

        //}

        //canvas.Add(p);
        canvas.Close();
    }
}

完成!(创作不易,点赞鼓励_

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1822200.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

人工智能内容生成元年-AI绘画原理解析

随着人工智能技术的飞速发展&#xff0c;AI绘画作为其引人注目的应用领域&#xff0c;正在以惊人的速度崭露头角。从最初的生成对抗网络&#xff08;GAN&#xff09;到如今的深度学习&#xff0c;AI绘画技术在艺术创作、设计等领域展现出了无限的可能性。其独特的算法和智能化特…

构建 deno/fresh 的 docker 镜像

众所周知, 最近 docker 镜像的使用又出现了新的困难. 但是不怕, 窝们可以使用曲线救国的方法: 自己制作容器镜像 ! 下面以 deno/fresh 举栗, 部署一个简单的应用. 目录 1 创建 deno/fresh 项目2 构建 docker 镜像3 部署和测试4 总结与展望 1 创建 deno/fresh 项目 执行命令…

情侣飞行棋系统微信小程序+H5+微信公众号+APP 源码

情侣飞行棋系统&#xff1a;浪漫与策略并存的双人游戏 &#x1f3b2; 一、引言&#xff1a;寻找爱情的乐趣 在繁忙的生活中&#xff0c;情侣们总是渴望找到一种既能增进感情又能带来乐趣的活动。而“情侣飞行棋系统”正是这样一个完美的选择。它结合了传统飞行棋的玩法和情侣…

接口自动化测试工程化——了解接口测试

什么是接口测试 接口测试也是一种功能测试 我理解的接口测试&#xff0c;其实也是一种功能测试&#xff0c;只是平时大家说的功能测试更多代指 UI 层面的功能测试&#xff0c;而接口测试更偏向于服务端层面的功能测试。 接口测试的目的 测试左移&#xff0c;尽早介入测试&a…

失眠焦虑?这些小妙招助你重拾宁静之夜

在这个快节奏的时代&#xff0c;失眠与焦虑似乎成了不少人的“常客”。每当夜幕降临&#xff0c;躺在床上却辗转反侧&#xff0c;思绪万千&#xff0c;仿佛整个世界的喧嚣都涌入了脑海。&#x1f4ad; 其实&#xff0c;放松心情&#xff0c;调整心态&#xff0c;是缓解失眠焦虑…

【MATLAB源码-第225期】基于matlab的计算器GUI设计仿真,能够实现基础运算,三角函数以及幂运算。

操作环境&#xff1a; MATLAB 2022a 1、算法描述 界面布局 计算器界面的主要元素分为几大部分&#xff1a;显示屏、功能按钮、数字按钮和操作符按钮。 显示屏 显示屏&#xff08;Edit Text&#xff09;&#xff1a;位于界面顶部中央&#xff0c;用于显示用户输入的表达式和…

Java聚合快递系统对接云洋系统快递小程序APP公众号系统源码

聚合快递对接云洋系统小程序&#xff1a;一键解决物流难题 一、引言&#xff1a;为何选择聚合快递对接&#xff1f; 在电商日益繁荣的今天&#xff0c;物流成为了连接卖家与买家的关键桥梁。然而&#xff0c;面对市场上琳琅满目的快递公司&#xff0c;如何高效、便捷地进行快…

Fluid 1.0 版发布,打通云原生高效数据使用的“最后一公里”

作者&#xff1a;顾荣 前言 得益于云原生技术在资源成本集约、部署运维便捷、算力弹性灵活方面的优势&#xff0c;越来越多企业和开发者将数据密集型应用&#xff0c;特别是 AI 和大数据领域应用&#xff0c;运行于云原生环境中。然而&#xff0c;云原生计算与存储分离架构虽…

低代码组件扩展方案在复杂业务场景下的设计与实践

组件是爱速搭的前端页面可视化模块的核心能力之一&#xff0c;它将前端研发人员从无休止的页面样式微调和分辨率兼容工作中解放了出来。 目前&#xff0c;爱速搭通过内置的上百种功能组件&#xff08;120&#xff09;&#xff0c;基本可以覆盖大部分中后台页面的可视化设计场景…

什么是数字人大?一分钟带你了解!

在数字化浪潮席卷全球的今天&#xff0c;中国作为数字经济的领跑者&#xff0c;正积极推动数字技术与国家治理体系的深度融合。其中&#xff0c;“数字人大”作为新时代国家治理体系和治理能力现代化的重要一环&#xff0c;正逐步成为推动民主法治建设、提升人大工作效能的新引…

ThinkPHP5.0 apache服务器配置URL重写,index.php去除

本地环境wamp .htaccess文件代码 <IfModule mod_rewrite.c>Options FollowSymlinks -MultiviewsRewriteEngine onRewriteCond %{REQUEST_FILENAME} !-dRewriteCond %{REQUEST_FILENAME} !-fRewriteRule ^(.*)$ index.php?/$1 [QSA,PT,L] </IfModule> 踩过这个坑&a…

不用下软件,51建模网上传模型就能直接在网页预览!

在数字化时代&#xff0c;3D建模和渲染技术日益成为各行各业不可或缺的工具。然而&#xff0c;传统的建模和预览流程往往需要用户安装复杂的软件&#xff0c;这不仅增加了技术门槛&#xff0c;也限制了模型在不同设备间的共享和查看。 为了解决这一痛点&#xff0c;51建模网凭…

【在线OJ】发帖功能前后段代码实现

一、页面布局 二、前端代码 <template><div id"app"><div style"height: 100vh"><div style"display: flex" ><el-input style"width: 95%" v-model"title" placeholder"输入标题"&g…

光储充一体化,开启绿色出行新篇章

一、追光逐梦&#xff0c;绿色能源点亮未来 在蔚蓝的天空下&#xff0c;光伏发电板如同一片片金色的叶子&#xff0c;静静地捕捉着太阳的光芒。它们不仅为大地带来光明&#xff0c;更是绿色出行的强大后盾。光储充一体化充电站&#xff0c;以光伏为源&#xff0c;储能为桥&…

蓝牙模块的不同版本迭代发展与技术趋势

蓝牙技术自1999年首次亮相以来&#xff0c;已经历了从1.0到5.0的多个版本迭代&#xff0c;每一次的更新都带来了显著的性能提升和广泛的应用前景。本文将综述蓝牙模块的版本迭代&#xff0c;分析其主要改进点&#xff0c;并探讨蓝牙模块在物联网、医疗、穿戴式设备等领域的应用…

Luma AI 推出梦幻机:据说吊打Sora和快手可灵(KLING)|TodayAI

近日&#xff0c;美国初创公司 Luma AI 宣布推出其最新的文本生成视频工具——梦幻机&#xff08;Dream Machine&#xff09;。这一消息发布的时间正好在中国科技公司快手推出其文本生成视频模型可灵&#xff08;KLING&#xff09;几天之后&#xff0c;标志着视频生成领域的又一…

560亿美元薪酬获批!马斯克:特斯拉未来市值将不止5万亿美元

KlipC报道&#xff1a;6月13日&#xff0c;美国电动汽车制造商特斯拉公司举办年度股东大会&#xff0c;其CEO马斯克对特斯拉生产销售、未来车型计划和在无人驾驶能等领域的发展进行了报告。此外&#xff0c;特斯拉股东批准了马斯克的560亿美元薪酬方案以及特斯拉总部迁至得克萨…

qt如何在linux平台上设置编译生成windows程序文件,跨平台?

在开始前刚好我有一些资料&#xff0c;是我根据网友给的问题精心整理了一份「qt的资料从专业入门到高级教程」&#xff0c; 点个关注在评论区回复“888”之后私信回复“888”&#xff0c;全部无偿共享给大家&#xff01;&#xff01;&#xff01;QT本来目标就是跨平台&#xf…

【PL理论】(23) 函数式语言:let-in 示例的分解 | 谁在使用动态作用域?

&#x1f4ad; 写在前面&#xff1a;本章我们将对函数式语言的讲解进行收尾&#xff0c;分解一下之前讲的 let-in 示例。然后讨论一下谁在使用动态作用域。 目录 0x00 let-in 示例的分解 0x01 谁使用动态作用域&#xff1f; 0x00 let-in 示例的分解 让我们详细检查这个示例…

Kafka流计算培训:打造Kafka技术专家,引领大数据未来

Kafka流计算培训课程是一门旨在帮助大数据从业人员和欲从事Kafka技术的人员快速掌握Kafka核心技术的专业培训项目。 在这个3天的课程中&#xff0c;我们将全面细致地讲解Kafka流计算软件的配置、Kafka流计算开发和流计算管道设计等内容&#xff0c;让学员能够在实际工作中灵活…