PDF盖章效果

    private void AddPDF(string pdfPath, float x, float y)
        {
            //新建PDF文档,添加一页
            PdfDocument doc = new PdfDocument();
            doc.LoadFromFile(pdfPath);

            if (doc.Pages.Count > 0)
            {
                foreach (PdfPageBase p in doc.Pages)
                {
                    //Image image = Image.FromFile(imgUrl);

                    //加载缩放后的图片到PdfImage对象
                    //PdfImage pdfImage = PdfImage.FromImage(image);

                    //float x = PdfPageSize.A4.Width;

                    //在指定位置绘入图片
                    // p.Canvas.DrawImage(pdfImage, x, y, fwidth, fheight);
                    // PdfLinearGradientBrush linearGradientBrush = new PdfLinearGradientBrush(rect1, new PdfRGBColor(Color.Red ), new PdfRGBColor(Color.Transparent), PdfLinearGradientMode.Horizontal);//填充图形颜色

                    //创建Rectangle2D对象,并指定图形在PDF页面中的大小、位置


                    PdfTrueTypeFont font1 = new PdfTrueTypeFont(new Font("宋体", 12f), true);
                    PdfFontBase font = new PdfFont(PdfFontFamily.Symbol, 12);
                    PdfPen pen = new PdfPen(Color.Red);

                    //审批级别--------------------------------------------------------------------------------------
                    Rectangle rectAudit1 = new Rectangle((int)x, (int)y + 15 * 0, 35, 15);
                    p.Canvas.DrawRectangle(pen, rectAudit1);//绘制矩形到页面
                    p.Canvas.DrawString("设计:", font1, PdfBrushes.Red, new PointF(x + 2, y + 15 * 0));

                    Rectangle rectAudit2 = new Rectangle((int)x, (int)y + 15 * 1, 35, 15);
                    p.Canvas.DrawRectangle(pen, rectAudit2);//绘制矩形到页面
                    p.Canvas.DrawString("审核:", font1, PdfBrushes.Red, new PointF(x + 2, y + 15 * 1));

                    Rectangle rectAudit3 = new Rectangle((int)x, (int)y + 15 * 2, 35, 15);
                    p.Canvas.DrawRectangle(pen, rectAudit3);//绘制矩形到页面
                    p.Canvas.DrawString("批准:", font1, PdfBrushes.Red, new PointF(x + 2, y + 15 * 2));

                    //审批人--------------------------------------------------------------------------------------
                    Rectangle rectName1 = new Rectangle((int)x + 35, (int)y + 15 * 0, 42, 15);
                    p.Canvas.DrawRectangle(pen, rectName1);//绘制矩形到页面
                    p.Canvas.DrawString("赵志丽", font1, PdfBrushes.Red, new PointF(x + +35 + 2, y + 15 * 0));

                    Rectangle rectName2 = new Rectangle((int)x + 35, (int)y + 15 * 1, 42, 15);
                    p.Canvas.DrawRectangle(pen, rectName2);//绘制矩形到页面
                    p.Canvas.DrawString("何文静", font1, PdfBrushes.Red, new PointF(x + +35 + 2, y + 15 * 1));

                    Rectangle rectName3 = new Rectangle((int)x + 35, (int)y + 15 * 2, 42, 15);
                    p.Canvas.DrawRectangle(pen, rectName3);//绘制矩形到页面
                    p.Canvas.DrawString("吕小波", font1, PdfBrushes.Red, new PointF(x + 35 + 2, y + 15 * 2));

                    //审批日期--------------------------------------------------------------------------------------
                    Rectangle rectTime1 = new Rectangle((int)x + 35 + 42, (int)y + 15 * 0, 100, 15);
                    p.Canvas.DrawRectangle(pen, rectTime1);//绘制矩形到页面
                    p.Canvas.DrawString("2022-03-14 07:63", font1, PdfBrushes.Red, new PointF(x + 35 + 42 + 2, y + 15 * 0));

                    Rectangle rectTime2 = new Rectangle((int)x + 35 + 42, (int)y + 15 * 1, 100, 15);
                    p.Canvas.DrawRectangle(pen, rectTime2);//绘制矩形到页面
                    p.Canvas.DrawString("2022-03-14 09:23", font1, PdfBrushes.Red, new PointF(x + 35 + 42 + +2, y + 15 * 1));

                    Rectangle rectTime3 = new Rectangle((int)x + 35 + 42, (int)y + 15 * 2, 100, 15);
                    p.Canvas.DrawRectangle(pen, rectTime3);//绘制矩形到页面
                    p.Canvas.DrawString("2022-03-14 10:41", font1, PdfBrushes.Red, new PointF(x + 35 + 42 + +2, y + 15 * 2));
                }
            }

            //保存文档
            string newpath = "g:\\a.pdf";
            doc.SaveToFile(newpath);

        }
 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值