找回密码
 立即注册

QQ登录

只需一步,快速开始

zxfreg

初级会员

42

主题

132

帖子

352

积分

初级会员

积分
352

微信认证勋章

[已处理] 导出pdf文件问题

zxfreg
初级会员   /  发表于:2018-12-27 13:12  /   查看:2899  /  回复:3
怎样控制导出pdf文件页面的大小?也就是一页A4的大小就是21*29.7cm导出的大小都不固定, image.png791383361.png 页边距就没法固定,导出代码如下:
string st = "@1.5@1.5@2.5@1.5@0.5@0.5@0@0@0@1@0@Hide@Hide";
            string[] ss = st.Substring(1).Split('@');
            FarPoint.Web.Spread.PrintInfo prinf = new FarPoint.Web.Spread.PrintInfo();
            prinf.Margin = new PrintMargin(0, 0, 0, 0, 0, 0);//.Top = int.Parse(ss[0]);
            prinf.Margin.Top = Convert.ToInt32(Convert.ToDouble(ss[0]) * 100 / 2.54);
            prinf.Margin.Left = Convert.ToInt32(Convert.ToDouble(ss[2]) * 100 / 2.54);
            prinf.Margin.Right = Convert.ToInt32(Convert.ToDouble(ss[3]) * 100 / 2.54);
            prinf.Margin.Bottom = Convert.ToInt32(Convert.ToDouble(ss[1]) * 100 / 2.54);
            prinf.HeaderHeight = Convert.ToInt32(Convert.ToDouble(ss[4]) * 100 / 2.54);
            prinf.FooterHeight = Convert.ToInt32(Convert.ToDouble(ss[5]) * 100 / 2.54);
            if (ss[6] == "0")
            {
                prinf.Centering = FarPoint.Web.Spread.Centering.None;
            }
            else if (ss[6] == "1")
            {
                prinf.Centering = FarPoint.Web.Spread.Centering.Horizontal;
            }
            else if (ss[6] == "2")
            {
                prinf.Centering = FarPoint.Web.Spread.Centering.Vertical;
            }
            else if (ss[6] == "3")
            {
                prinf.Centering = FarPoint.Web.Spread.Centering.Both;
            }
            if (ss[7] == "1")
            {
                prinf.Orientation = PrintOrientation.Landscape;
            }
            else prinf.Orientation = PrintOrientation.Portrait;
            if (ss[8] == "1")
            {
                prinf.ShowBorder = true;
            }
            else prinf.ShowBorder = false;
            if (ss[9] == "1")
            {
                prinf.ShowColor = true;
            }
            else prinf.ShowColor = false;
            if (ss[10] == "1")
            {
                prinf.ShowGrid = true;
            }
            else prinf.ShowGrid = false;
            if (ss[11] == "Hide")
            {
                prinf.ShowRowHeader = PrintHeader.Hide;
            }
            else if (ss[11] == "Inherit")
            {
                prinf.ShowRowHeader = PrintHeader.Inherit;
            }
            else if (ss[11] == "Show")
            {
                prinf.ShowRowHeader = PrintHeader.Show;
            }
            if (ss[12] == "Hide")
            {
                prinf.ShowColumnHeader = PrintHeader.Hide;
            }
            else if (ss[12] == "Inherit")
            {
                prinf.ShowColumnHeader = PrintHeader.Inherit;
            }
            else if (ss[12] == "Show")
            {
                prinf.ShowColumnHeader = PrintHeader.Show;
            }
            prinf.SmartPrintPagesTall = Convert.ToInt32(29.7 * 100 / 2.54);
            prinf.SmartPrintPagesWide = Convert.ToInt32(21 * 100 / 2.54);
            prinf.UseSmartPrint = true;
            prinf.ZoomFactor = 1.0f;
            prinf.BestFitRows = false;
            prinf.BestFitCols = false;
            FpSpread1.Sheets[0].PrintInfo = prinf;
            filepath = dataDir + "aa.pdf";
         
            FpSpread1.SavePdf(filepath);

3 个回复

倒序浏览
dexteryao讲师达人认证 悬赏达人认证 SpreadJS 开发认证
超级版主   /  发表于:2019-1-3 11:13:16
沙发
您好,这个和页面内容有关,spread web没有办法直接指定最终生成PDF的大小,这个是前端的一个限制。
回复 使用道具 举报
zxfreg
初级会员   /  发表于:2019-1-3 11:32:43
板凳
prinf.SmartPrintPagesTall = Convert.ToInt32(29.7 * 100 / 2.54);
             prinf.SmartPrintPagesWide = Convert.ToInt32(21 * 100 / 2.54);
这不是设置页面内容大小了吗,怎么生成pdf的大小还会超了呢
回复 使用道具 举报
dexteryao讲师达人认证 悬赏达人认证 SpreadJS 开发认证
超级版主   /  发表于:2019-1-3 11:35:45
地板
还有margin , 您需要考虑将margin 去掉或者剪掉margin
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 立即注册
返回顶部