正常行驶的bitmap类型的二维码格式,加载到PDF中,将会导致二维码失真,无法扫描。

矢量图可根据尺寸大小进行调节,不会出现失真模糊情况

所用依赖

<PackageReference Include="FreeSpire.PDF" Version="8.6.0" />//操作PDF依赖

<PackageReference Include="QRCoder" Version="1.4.3" />//生成二维码SVG依赖

//以下为代码说明

        #region 生成svg格式的矢量二维码

        public static string GetSvgQRCode(string plainText, int pixel)
{
var generator = new QRCodeGenerator();
var qrCodeData = generator.CreateQrCode(plainText, QRCodeGenerator.ECCLevel.Q);
var qrcode = new SvgQRCode(qrCodeData);
return qrcode.GetGraphic(pixel);
}
#endregion
        #region
public IActionResult GetSvgQRPic()
{
var svgText = QRCodeService.GetSvgQRCode("http://www.baidu.com", 15); string svgName = $"{Guid.NewGuid().ToString()}.svg";
string filePath = "E:\\ZGQM\\QRCODE\\"+ svgName;
System.IO.File.WriteAllText(filePath, svgText);
byte[] byts = System.IO.File.ReadAllBytes(filePath);
return File(byts, "image/svg", svgName);
}
public IActionResult SvgTOPdf()
{
string pdfname = "shuangcengSingle.pdf";
string rootPath = "E:\\ZGQM\\QRCODE\\";
//加载示例SVG图片
PdfDocument doc1 = new PdfDocument();
doc1.LoadFromSvg(rootPath + "a2.svg");
//加载示例PDF文档
PdfDocument doc2 = new PdfDocument();
doc2.LoadFromFile(rootPath + pdfname);
//设置图片在文档中的位置和大小59
var pdfwidth = doc2.Pages[0].Size.Width;
var pdfheight = doc2.Pages[0].Size.Height;
//计算两厘米二维码的磅值
double zb = 0;
if(pdfwidth<=pdfheight)
zb = 20 / (pdfwidth * 25.4 / 72);
else
zb = 20/ (pdfheight * 25.4 / 72);
double twocodezb = zb * (pdfwidth<= pdfheight?pdfwidth:pdfheight);
int twotruecode = Convert.ToInt32(Math.Round(twocodezb));
var doctemp = doc1.Pages[0].CreateTemplate();
var p2 = new System.Drawing.PointF(0, 0);
var di = new System.Drawing.SizeF(twotruecode, twotruecode);
PdfCanvas d2z = doc2.Pages[0].Canvas;
d2z.DrawTemplate(doctemp, p2, di);
//保存PDF文档
doc2.SaveToFile(rootPath + "AddSVGImagetoPDF-"+pdfname+".pdf", FileFormat.PDF);
doc1.Close();
doc2.Close();
return null;
}
#endregion

以上可实现将矢量图进行绑定到PDF中,并且保证不失真。

参考部分连接

https://www.e-iceblue.cn/pdf_java_conversion/convert-svg-to-pdf-and-add-a-svg-image-to-pdf-in-java.html

https://cloud.tencent.com/developer/article/1518580?from=15425&areaSource=102001.24&traceId=X5ThA0l7o2dpqbZKzQB2_

svg矢量二维码加盖在PDF文件中的更多相关文章

  1. 微信长按识别二维码,在 vue 项目中的实现

    微信长按识别二维码是 QQ 浏览器的内置功能,该功能的基础一定要使用 img 标签引入图片,其他方式的二维码无法识别. 在 vue 中使用 QrcodeVue 插件 demo1 在 template ...

  2. 钉钉登录二维码嵌套在vue页面中

    转自 https://www.csdn.net/tags/OtDacg3sMjQ2NTgtYmxvZwO0O0OO0O0O.html 钉钉登录二维码嵌套在vue页面中 2021-09-04 14:42 ...

  3. C#生成二维码,把二维码图片放入Excel中

    /// <summary> /// 把图片保存到excel中 /// </summary> /// <param name="excelFilePath&quo ...

  4. 基于nginx实现二维码下载安装apk文件

    将apk文件置于nginx目录下 <!--进入nginx安装路径--> /usr/local/nginx <!--新建放apk的目录--> mkdir -p resources ...

  5. Java 添加条码、二维码到PDF文档

    本文介绍如何通过Java程序在PDF文档中添加条码和二维码.创建条码时,可创建多种不同类型的条码,包括Codebar.Code11.Code128A.Code128B.Code32.Code39.Co ...

  6. Asp.Net Core 生成二维码(NuGet使用QRCoder)

    前言 功能:调用web api 接口 1.获取 jpeg 格式的二维码 2.获取中间带有logo 的二维码 3. 下载 jpeg,svg 格式的二维码 需要的NuGet 包: > QRCoder ...

  7. 【C#】发票助手二维码生成

    之前一起吃饭听说了发票助手这个东西,可以生成发票抬头的二维码,扫码就可以开票了. 官方也有个小程序的 [税务发票助手],微信中搜这个名字就可以了. 我准备在自己的小程序中也尝试一下,本来觉得只要拼接一 ...

  8. C#/VB.NET 在Word中添加条码、二维码

    本文介绍如何通过C# 和VB.NET代码实现在Word文档中添加条码和二维码.代码中将分为在Word正文段落中.页眉页脚中等情况来添加. 使用工具:Free Spire.Office for .NET ...

  9. C#运用GmaQrCode生成二维码

    项目中需要生成二维码,方法比较多,可以采用JS插件,也可以采用第三方插件后台生成二维码,在后台方法中可以采用QRCode或者GmaQrCode,现在介绍一种C#在后台生成二维码的方法: /// < ...

  10. phpqrcode 生成二维码

    这个项目需要根据信息来自动生成二维码,到网上搜了下,发现php有生成二维码的类库phpqrcode,所以打算就用这个来生成二维码 从官网下载类库源码http://sourceforge.net/pro ...

随机推荐

  1. uniapp与原生交互

    1.项目中引入 DSBridge.js 文件 var bridge = { default: this, call: function(b, a, c) { var e = ""; ...

  2. [js函数] shallowEqual

    const isBasicType = (t: any) => { return t === "number" || t === "string" || ...

  3. Scala集合总结

    Scala同时支持可变集合和不可变集合,包含两个包: 可变集合:scala.collection.mutable 不可变集合:scala.collection.immutable Scala默认采用不 ...

  4. 安装nginx依赖库

    nginx安装headers-more-nginx-module,推荐下面这篇贴,步骤简洁明了,本人ubutu18.0.04版本一次性安装成功: https://www.jianshu.com/p/8 ...

  5. 学习-Vue3-绑定内联样式

    <template> <div> <!-- 绑定内联样式--绑定对象 --> <!-- <div :style="{color: active ...

  6. 越权检测 burp插件 autorize 使用

    Autorize 官方描述 Autorize 是 Burp Suite 的自动授权强制检测扩展.它是由应用程序安全专家 Barak Tawily 用 Python 编写的.Autorize 旨在通过执 ...

  7. 【git】3.3 git分支-分支管理

    资料来源 (1) https://git-scm.com/book/zh/v2/Git-%E5%88%86%E6%94%AF-%E5%88%86%E6%94%AF%E7%AE%A1%E7%90%86 ...

  8. Google big query - 怎么创建临时表/create temp table

    Creating a temporary table The following example creates a temporary table named Example and inserts ...

  9. 永久免费泛域名证书: letsencrypt 

    项目地址: https://github.com/Neilpang/acme.sh

  10. 实验室服务器运维踩坑o.0

    先说背景:实验室新配了一台Dell T640服务器,双3090, 512G内存, 5 x 8T硬盘(RAID5),2 x 1T固态(RAID1),配置很够用但就是搭建运维踩了很多坑,以下是主要完成的几 ...