DevExpress、FastReport 报表导出PDF, 字体不加粗

一、FastReport 效果展示

(1)fastReport报表中已设置仿宋加粗 如下图1:

                                                                     图1

(2)导出本地PDF 之后,显示效果。如下图2:

                                                                        图2

二、DevExpress.xtraReport 效果展示

(1)dev报表中已设置仿宋加粗 如下图3:

                                                                        图3

(2)导出本地PDF 之后,显示效果。如下图4:

                                                                        图4

三、 解决方案

        通过长时间的研究,发现最佳的方式是,通过在报表中使用图片元素(一定要使用报表工具中中自带图片元素,如果使用winfrom 的pictureBox 存在图片失真的问题) ,代替原来的文本元素。 在报表转PDF 的时候,把图片绘制到图片元素中。

        (1)fastReport 代码如下:

using FastReport;
using FastReport.Export.Pdf;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Imaging;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApp3
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            // 创建报表对象
            Report report = new Report();
            // 加载报表模板
            report.Load(@"C:\Users\wangjunjie\Desktop\test.frx");

            // 找到需要加粗显示的文本对象
            TextObject textObject = report.FindObject("test") as TextObject;
            PictureObject PicObject = report.FindObject("Picture1") as PictureObject;

            // 设置字体样式为仿宋加粗
            textObject.Font = new Font("仿宋", 20, FontStyle.Regular);

            //创建一个新的图片对象
            using (Bitmap bmp = new Bitmap(1000, 100))
            {
               // 使用 Graphics 对象在图片上绘制文字
                using (Graphics graphics = Graphics.FromImage(bmp))
                {
                    //设置背景色为白色
                    graphics.Clear(Color.White);

                    //设置文字样式
                   Font font = new Font("仿宋", 50, FontStyle.Bold);
                    Brush brush = new SolidBrush(Color.Black);

                  //  绘制文字
                    graphics.DrawString("白日依山尽,黄河入海流", font, brush, new PointF(0, 0));

                   // 释放资源
                    font.Dispose();
                    brush.Dispose();
                }

                //保存图片到文件
                bmp.Save("text_image.png", ImageFormat.Png);
            }
            // 把生成的图片添加到元素中
            PicObject.Image = Image.FromFile("text_image.png");
            // 准备报表
            report.Prepare();

            PDFExport pdfExport = new PDFExport();
            // 导出报表为 PDF
            report.Export(pdfExport, "OutputFileName.pdf");

            // 释放资源
            report.Dispose();
        }
    }
}



  效果图 ,如下图5:

                                                                        图5 

    (2)DevExpress.xtraReport代码如下:

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using DevExpress.XtraReports.UI;
using System.Data;
using System.Collections.Generic;
using System.Drawing.Imaging;

namespace JHEMR.JHDeadCertificate.Report
{
    public partial class Three : ThreeBase
    {
        public Three()
        {
            InitializeComponent();
            // 创建一个新的图片对象
            using (Bitmap bmp = new Bitmap(1000, 100))
            {
                // 使用 Graphics 对象在图片上绘制文字
                using (Graphics graphics = Graphics.FromImage(bmp))
                {
                    // 设置背景色为白色
                    graphics.Clear(Color.White);

                    // 设置文字样式
                    Font font = new Font("仿宋", 53, FontStyle.Bold);
                    Brush brush = new SolidBrush(Color.Black);

                    // 绘制文字
                    graphics.DrawString("白日依山尽,黄河入海流", font, brush, new PointF(0, 0));

                    // 释放资源
                    font.Dispose();
                    brush.Dispose();
                }
                // 保存图片到文件
                bmp.Save(DateTime.Now.ToString("YYYYMMddHHMMSS") + "text_image.png", ImageFormat.Png);
            }
            this.xRpictureBox1.Image = Image.FromFile(DateTime.Now.ToString("YYYYMMddHHMMSS") + "text_image.png");

        }
    }
}


 效果图 如下 图6

                                                                        图六

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值