首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ Builder >

图片打印的代码

2013-01-05 
求一个图片打印的代码要求有3:1、能调出打印机设置窗口,选定打印机和纸张2、图片能适合纸张页面3、图片能按照

求一个图片打印的代码
要求有3:
1、能调出打印机设置窗口,选定打印机和纸张

2、图片能适合纸张页面

3、图片能按照1:1的打印,如果1:1超出了选定的纸张大小就自动分割到多个页面中打印
[解决办法]
http://topic.csdn.net/t/20020618/10/811871.html
http://topic.csdn.net/t/20050615/16/4084554.html
[解决办法]
图片类似

经常用Borland C++ Builder5编程,操作数据库时,报表打印是必不成少的。但BCB5自身所带的报表控件又显得贫窭矫捷性。所以,我想到了用TPrinter来打印报表。使用TPrinter必需要在轨范头部插手#include <vcl\Printers.hpp>
  因为对于不是链页打印纸来说,断页很坚苦,所以,我所需要设定每页打印的记实数。下面就是我自己编制的一个每页打印30条合适前提记实的代码,写给巨匠,以供参考。
  try{
  //定位打印头
    int x,y;
    x=170;
    y=150;
    Printer()->BeginDoc();//起头一个打印工作
  //打印标头
    Printer()->Canvas->Font->Size=24;
    Printer()->Canvas->Font->Name="黑体";
    Printer()->Canvas->TextOut(x,y," -----服装请领记实-----");
    Printer()->Canvas->Font->Size=10;
    Printer()->Canvas->Font->Name="宋体";
    x=190;
    y=y+300;
  //打印表格问题行
    Printer()->Canvas->TextOut(x,y," ◇"+Trim(Label12->Caption));
    y=y+80;
    Printer()->Canvas->TextOut(x,y,"┏━━━━━━━━━┳━━━━━━━━━━┳━━┳━━━━━┳━━━━━━━━━━━┳━━━━━━━┓");
    y=y+80;
    Printer()->Canvas->TextOut(x,y," 日 期 品 名 姓 名 部 门 职 务");
    Printer()->Canvas->TextOut(x+1820,y,"数目");
    Printer()->Canvas->TextOut(x,y,"┃");
    Printer()->Canvas->TextOut(x+830,y,"┃");
    Printer()->Canvas->TextOut(x+1742.1,y,"┃");
    Printer()->Canvas->TextOut(x+1991.2,y,"┃");
    Printer()->Canvas->TextOut(x+2491.73,y,"┃");
    Printer()->Canvas->TextOut(x+3487.61,y,"┃");
    Printer()->Canvas->TextOut(x+4151,y,"┃");
    ADOQuery1->First();
  //换页记实计数器初始化
    int i=0;
  //成立轮回,如不美观不是最后一标识表记标帜录则进行轮回
  while(!ADOQuery1->Eof)
  {
  //计数器加1
    i=i+1;
    y=y+80;
  //打印第一标识表记标帜录
    Printer()->Canvas->TextOut(x,y,"┣━━━━━━━━━╋━━━━━━━━━━╋━━╋━━━━━╋━━━━━━━━━━━╋━━━━━━━┫");
    y=y+80;
    Printer()->Canvas->TextOut(x,y,"┃"+ADOQuery1->FieldByName("请领日期")->AsString);
    Printer()->Canvas->TextOut(x+830,y,"┃"+ADOQuery1->FieldByName("品名")->AsString);
    Printer()->Canvas->TextOut(x+1742.1,y,"┃"+ADOQuery1->FieldByName("数目")->AsString);
    Printer()->Canvas->TextOut(x+1991.2,y,"┃"+ADOQuery1->FieldByName("请领人")->AsString);
    Printer()->Canvas->TextOut(x+2491.73,y,"┃"+ADOQuery1->FieldByName("部门")->AsString);
    Printer()->Canvas->TextOut(x+3487.61,y,"┃"+ADOQuery1->FieldByName("职务")->AsString);
    Printer()->Canvas->TextOut(x+4151,y,"┃");
    ADOQuery1->Next();
  //测试是否该换页,每30标识表记标帜录换一次页
    if(i%30==0)
    { 
  //如不美观已经是最后一标识表记标帜录,则退出轮回
   if(ADOQuery1->Eof)
    {
      break;
     }
  //如不美观不是最后一标识表记标帜录
    else
    {
  //如不美观该换页,则打印页尾和页码
    int p=Printer()->PageNumber;
    y=y+80;
    Printer()->Canvas->TextOut(x,y,"┗━━━━━━━━━┻━━━━━━━━━━┻━━┻━━━━━┻━━━━━━━━━━━┻━━━━━━━┛");
    Printer()->Canvas->TextOut(3800,y+200,"页码:"+IntToStr(p));
    Printer()->NewPage();
    Application->MessageBox("请改换纸张后按确定!","提醒",MB_OK);


    x=170;
    y=150;
    Printer()->Canvas->Font->Size=24;
    Printer()->Canvas->Font->Name="黑体";
    Printer()->Canvas->TextOut(x,y," -----服装请领记实-----");
    Printer()->Canvas->Font->Size=10;
    Printer()->Canvas->Font->Name="宋体"; 
    x=190; 
    y=y+300; 
    Printer()->Canvas->TextOut(x,y," ◇"+Trim(Label12->Caption)); 
    y=y+80; 
    Printer()->Canvas->TextOut(x,y,"┏━━━━━━━━━┳━━━━━━━━━━┳━━┳━━━━━┳━━━━━━━━━━━┳━━━━━━━┓"); 
    y=y+80; 
    Printer()->Canvas->TextOut(x,y," 日 期 品 名 姓 名 部 门 职 务"); 
    Printer()->Canvas->TextOut(x+1820,y,"数目"); 
    Printer()->Canvas->TextOut(x,y,"┃"); 
    Printer()->Canvas->TextOut(x+830,y,"┃"); 
    Printer()->Canvas->TextOut(x+1742.1,y,"┃"); 
    Printer()->Canvas->TextOut(x+1991.2,y,"┃");  
    Printer()->Canvas->TextOut(x+2491.73,y,"┃"); 
    Printer()->Canvas->TextOut(x+3487.61,y,"┃"); 
    Printer()->Canvas->TextOut(x+4151,y,"┃");
     }
    }
  //怀景死守
  }
  //打印完全数记实后,打印表格尾部
  y=y+80;
  Printer()->Canvas->TextOut(x,y,"┗━━━━━━━━━┻━━━━━━━━━━┻━━┻━━━━━┻━━━━━━━━━━━┻━━━━━━━┛");
  //取得总页数
  int pp=Printer()->PageNumber;
  //在表格尾部打印页码
  Printer()->Canvas->TextOut(3800,y+200,"页码:"+IntToStr(pp));
  Printer()->EndDoc();//竣事矣闽打印工作
  ShowMessage("打印完成!感谢使用!");
  }
  //异常措置
  catch(...)
  { 
    ShowMessage("打印犯错!请搜检打印机是否毗连好或者电源是否打开及其设置!");
  }

热点排行