惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

I
Intezer
V
Vulnerabilities – Threatpost
Google Online Security Blog
Google Online Security Blog
T
The Exploit Database - CXSecurity.com
C
CXSECURITY Database RSS Feed - CXSecurity.com
AWS News Blog
AWS News Blog
G
GRAHAM CLULEY
P
Privacy & Cybersecurity Law Blog
www.infosecurity-magazine.com
www.infosecurity-magazine.com
C
Cybersecurity and Infrastructure Security Agency CISA
N
News | PayPal Newsroom
T
Tenable Blog
Spread Privacy
Spread Privacy
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
S
Secure Thoughts
P
Privacy International News Feed
IT之家
IT之家
Project Zero
Project Zero
T
The Blog of Author Tim Ferriss
Engineering at Meta
Engineering at Meta
大猫的无限游戏
大猫的无限游戏
博客园_首页
GbyAI
GbyAI
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
量子位
雷峰网
雷峰网
Apple Machine Learning Research
Apple Machine Learning Research
Hacker News: Ask HN
Hacker News: Ask HN
Google DeepMind News
Google DeepMind News
MongoDB | Blog
MongoDB | Blog
N
Netflix TechBlog - Medium
Martin Fowler
Martin Fowler
NISL@THU
NISL@THU
I
InfoQ
D
DataBreaches.Net
有赞技术团队
有赞技术团队
K
Kaspersky official blog
Security Latest
Security Latest
The Register - Security
The Register - Security
Hugging Face - Blog
Hugging Face - Blog
S
Security @ Cisco Blogs
P
Proofpoint News Feed
M
MIT News - Artificial intelligence
H
Hackread – Cybersecurity News, Data Breaches, AI and More
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
AI
AI
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
P
Proofpoint News Feed
Security Archives - TechRepublic
Security Archives - TechRepublic
N
News and Events Feed by Topic

博客园 - 飘扬De黑夜

SqlServer 批量修改某个字段类型 U8数据库表汇总 elementui关于表单校验validator Vue.js 2 使用 extends 扩展 element-ui 组件 FastReport-Barcode/QRCode 控件总是存在白色空白区域 双网卡同时访问内外网 vs项目启动后总是提示ID为XXX的进程当前未运行 Vue2全局管理格式化器和Filter uniapp 以npm模式安装插件的项目,如何让自定义组件支持easycom方式自动导入 Http请求中 Content-Type 常用格式说明 WPF入门基础之双向数据绑定 WPF入门之设置样式 ElementUI-如何给 el-dropdown 的 command 事件传递多个参数 TortoiseGit使用 管理系统中台示例参照 淘宝源安装npm visual studio 2022 自定义组件和自定义控件和用户控件的区别 SqlServer GoupBy 分组后对于非分组的某个字符串进行拼接 SQL Server 实现类似CountIF的函数
FastReport 使用JSON作为数据源,手工赋值和导出PDF
飘扬De黑夜 · 2025-06-12 · via 博客园 - 飘扬De黑夜

需要用到的Nuget包

FastReport.OpenSource

FastReport.Compat

FastReport.OpenSource.Export.PdfSimple

目前使用的版本:2023.3.10

代码参照如下:设置JSON数据源(frx模板一定注意对应)--实现的时标签打印,实际是一个对象的格式

{

  Data1:{},

      Data2:{}

}

JsonSchemaGenerator generator = new JsonSchemaGenerator();
var myJsonSchema = generator.Generate(typeof(LabelPrintModel));
var datasource=report.Dictionary.Connections[0] as JsonDataSourceConnection;
var strBuilder = new FastReport.Data.JsonConnection.JsonDataSourceConnectionStringBuilder();
strBuilder.JsonSchema = myJsonSchema.ToString();
var jstr = JsonConvert.SerializeObject(result, typeof(LabelPrintModel), new JsonSerializerSettings() { ReferenceLoopHandling = ReferenceLoopHandling.Ignore });
// 输出json方便设计器设计使用
StreamWriter sw = new StreamWriter(@"C:\FastReport\jsondata.json");
sw.WriteLine(jstr);
sw.Flush();
sw.Close();

strBuilder.Json = jstr;
datasource.ConnectionString = strBuilder.ConnectionString;

  导出pdf

FastReport.Export.PdfSimple.PDFSimpleExport export = new FastReport.Export.PdfSimple.PDFSimpleExport();
report.Export(export, $@"C:\FastReport\temp_{DateTime.Now.ToString("yyyyMMddHHmmss")}.pdf");