目前急需写一个网页打印控件请大家帮帮忙,告诉一下应该用什么技术(是不是用OCX)?哪里有好的例子或者文档介绍?谢谢先!

解决方案 »

  1.   

    那个打印接口是什么我真的想不起来了。你看看这个例子对你有没有帮助:
    http://www.moon-soft.com/download/soft/2026.htm
      

  2.   

    如果要是控制打印的一些操作,下面是我记录的一些,希望能帮助你:
    Q:vc/mfc 单文档项目。默认提供了“打印/打印预览”的功能。在点击“打印”的时候,会自动弹出一个“Print Dialog”,我现在需要在程序中判断,
    用户点击的按钮,是“确定”还是“取消”。
    A:
    BOOL CXXXView::OnPreparePrinting(CPrintInfo* pInfo)
    {
    // default preparation
        BOOL bRet=DoPreparePrinting(pInfo);
        if(bRet==false)//点了取消
        {
          ...
        }
    }
    //=====================================================================================//
    Q:为什么打印机只能打A4大小的纸
    CPrintDialog printDlg(FALSE);
    CDC dc;
    printDlg.GetDefaults ();
    DEVMODE *dm = printDlg.GetDevMode(); 
    dm->dmOrientation = DMORIENT_PORTRAIT;
    dm->dmFields |= DM_ORIENTATION; //将打印纸大小设为自定义
    dm->dmPaperSize=NULL;
    //定义打印纸的长宽
    dm->dmPaperLength= m_pf.uiPageHeight / 10 ;
    dm->dmPaperWidth = m_pf.uiPageWidth / 10; 
    if( m_pDC ){
    m_pDC->Detach();
    delete(m_pDC);
    m_pDC = NULL;
    }
    m_pDC = new CDC;
    if(m_pDC->Attach(printDlg.CreatePrinterDC()) ){
    GetPtrOffset();
    return TRUE;
    }
       ....我通过以上语句将打印纸设成自定义的(37cm *52cm)打印机也可以打这么大的纸,但我随后打印的东西中,超过A4的那部分就显示不出来了,烦请各位高手指教!!A:
    http://www.china-askpro.com/msg22/qa25.shtml
    http://community.csdn.net/Expert/topic/3776/3776227.xml?temp=.9028894//===================================================================================////打印机的初始化设置
    CPrintDialog dlg(FALSE,PD_ALLPAGES | PD_USEDEVMODECOPIES | PD_NOPAGENUMS | PD_HIDEPRINTTOFILE | PD_NOSELECTION,this); 
       
    CRuixingZJApp* pApp = static_cast<CRuixingZJApp*>( ::AfxGetApp() );
    long Len;
    WORD nWord = 0;
    HANDLE hPrinter;DEVMODE* pDevMode;
    DEVNAMES* lpDevNames;
    LPTSTR lpszDeviceName;    ///////////////////////////////////////////////////////////////////
        if(pApp->GetPrinterDeviceDefaults(&dlg.m_pd) == 0)
    {
    ::AfxMessageBox("错误!当前没有连接打印机!",MB_OK);
    return;
    }
    pDevMode = (DEVMODE*)GlobalLock(dlg.m_pd.hDevMode);
    lpDevNames = (LPDEVNAMES)GlobalLock(dlg.m_pd.hDevNames);
    lpszDeviceName = (LPTSTR )lpDevNames + lpDevNames->wDeviceOffset;if (::OpenPrinter((char *) pDevMode->dmDeviceName, &hPrinter, NULL) == FALSE)
    return;
    Len = DocumentProperties(NULL, NULL, lpszDeviceName, pDevMode, NULL, 0);
    pDevMode->dmPaperSize = DMPAPER_A4;
    lstrcpy((char *)pDevMode->dmFormName,"A4 210 *297 mm");    Len = DocumentProperties(NULL, hPrinter, lpszDeviceName, NULL, pDevMode, DM_IN_BUFFER);
    GlobalUnlock(dlg.m_pd.hDevMode);
    GlobalUnlock(dlg.m_pd.hDevNames);////////////////////////////////////////////////////////////////////////////////
        if (dlg.CreatePrinterDC() == NULL) 
    return ;
    if (dlg.DoModal() == IDOK)
    {   
    m_pPrintDC.Attach(dlg.m_pd.hDC); 
    if(m_pPrintDC.GetSafeHdc() == NULL)
    {
    ::AfxMessageBox("当前没有连接打印机!", MB_OK);
    return;
    }pDC = &m_pPrintDC;
    ASSERT_VALID( pDC );DOCINFO di; 
    di.cbSize = sizeof(DOCINFO);
    di.lpszDocName = "微机监测实时数据表格";
    di.lpszOutput = NULL; 
    di.lpszDatatype = NULL;
    di.fwType = 0;
    //取打印机的横方向和纵方向的分辨率
    //即每英寸点数
    cxInch = pDC->GetDeviceCaps(LOGPIXELSX);
    cyInch = pDC->GetDeviceCaps(LOGPIXELSY);
    //取打印纸张高度和宽度
    nPageHeight = pDC->GetDeviceCaps(VERTRES);
    nPageWidth = pDC->GetDeviceCaps(HORZRES);m_CharWidth = (long)((float)(nPageWidth*37/40)/(float)80);
    m_LineHeight = (long)((float)(nPageHeight*19/20)/(float)80);//==================================================================================//Q:如何保证图片和文本同时打印比例协调? 
    A:把图片处理成设备无关位图,然后使用这个函数想拉伸多大就拉伸多大喽
    http://blog.csdn.net/bluebohe/archive/2004/01/14/21061.aspx
    http://blog.csdn.net/bluebohe/archive/2004/01/14/21062.aspx//==================================================================================//
      

  3.   

    Q:如何检测打印机打印是否完成 
    A:http://community.csdn.net/Expert/topic/3726/3726548.xml?temp=.8084986
    Q: How can I determine the status of the printer programmatically?A: The answer has several parts. The good part is that calling GetPrinter() at level 2 will return the printer status in PRINTER_INFO_2::Status. The bad part is twofold: While on Win9x you can get detailed information of the printer status in this member, on WinNT you'll only find out if the printer is paused or pending deletion, which is obviously not enough.To further complicate things, it turns out that Windows only queries the printer for its status when there's a print job for the it, which means that if you are not printing you probably can't find out the real printer status. If you are not concerned about this, you'll be glad to know that you can obtain the same information on WinNT and Win9x by querying the print job instead of the printer for the status, via the GetJob() api.//=================================================================================//Q:做一个自定义打印纸张的,类似 金堞 k3 打印自定义的功能
    A:http://www.vckbase.com/code/listcode.asp?mclsid=5&sclsid=511//==================================================================================//Q:如何取得打印作业的所属的打印机名?
    A:从EnumJobs的第五个参数得到一个JOB_INFO_2结构的变量,这个结构的JOB_INFO_2的第三个成员
    就是打印机名.//==================================================================================//Q:打印设置对话框中打印方向的问题 
    A:
    http://community.csdn.net/Expert/topic/3364/3364546.xml?temp=9.711856E-02
    http://search.csdn.net/Expert/topic/691/691080.xml?temp=.3176844DEVMODE *pUserDevMode = NULL; 
    pUserDevMode = pInfo->m_pVchPD->GetDevMode();// 得到系统默认的打印参数
    /* 设置用户纸宽 */
    pUserDevMode->dmFields |= DM_PAPERWIDTH|DM_ORIENTATION|DM_PAPERLENGTH; 
    /* 设置用户纸高 */ 
    pUserDevMode->dmPaperWidth = (short)pInfo->m_pParams->GetParamIntValue(163);
    /* 设置输出方向 */ 
    pUserDevMode->dmPaperLength = (short)pInfo->m_pParams->GetParamIntValue164);  
    /* 使修改后的内容生效 */
    pUserDevMode->dmOrientation = DMORIENT_LANDSCAPE;  
    pDC->ResetDC(pUserDevMode);
    /////////////////////////////////////////
    在OnPreparePrinting函数中,添加如下代码
    if(横向打印)
    {
    CWinApp* pApp = AfxGetApp();
    if(pApp->GetPrinterDeviceDefaults(&pInfo->m_pPD->m_pd))
    {
    LPDEVMODE lpDevmode = pInfo->m_pPD->GetDevMode();
    lpDevmode->dmOrientation = DMORIENT_LANDSCAPE;
    }
    }
    else
    {
    CWinApp* pApp = AfxGetApp();
    if(pApp->GetPrinterDeviceDefaults(&pInfo->m_pPD->m_pd))
    {
    LPDEVMODE lpDevmode = pInfo->m_pPD->GetDevMode();
    lpDevmode->dmOrientation = DMORIENT_PORTRAIT;
    }
    }//===================================================================================//Q:求助,请问如何不显示printdialog,直接把内容打印出来?
    A:http://search.csdn.net/Expert/topic/2037/2037370.xml?temp=.7349512//===================================================================================//Q:十分经典的VC对话框程序的打印预览
    A:http://www.vczx.com/article/show.php?id=269//==================================================================================//Q:在VC中可以利用IE实现打印预览功能吗?
    A:http://community.csdn.net/Expert/topic/3597/3597568.xml?temp=.7409326//===================================================================================//Q:如何编程设置打印机默认打印纸
    A:http://community.csdn.net/Expert/topic/3596/3596676.xml?temp=.8077204//===================================================================================//Q:有什么函数可以设置打印机横向打还是纵向打的??? 
    A:http://community.csdn.net/Expert/FAQ/FAQ_Index.asp?id=186073//===================================================================================//Q:打印CListCtrl控件的类
    A:
    http://community.csdn.net/Expert/topic/3559/3559232.xml?temp=.3827478
    CGridCtrl的例子,很强大
    http://www.codeproject.com/miscctrl/gridctrl.asp//====================================================================================//Q:DDB打印的问题 
    A:http://community.csdn.net/Expert/topic/3514/3514801.xml?temp=5.421084E-02//===================================================================================//A:怎样使用命令行方式来进行文件打印?
    Q:语法
    print [/d:Printer] [Drive:][Path] FileName [ ...]参数
    /d:Printer 
    指定要执行打印作业的打印机。可以通过指定打印机连接的计算机端口来指定本地打印机。并行端口的有效值为 LPT1、LPT2 和 LPT3。串行端口的有效值为 COM1、COM2、COM3 和 COM4。也可以通过队列名(\\ServerName\ShareName)指定网络打印机。如果未指定打印机,则打印作业将发送到 LPT1。 
    Drive: 
    指定待打印文件所在的逻辑或物理驱动器。如果待打印的文件位于当前驱动器上,则不需指定该参数。 
    Path 
    指定待打印文件在驱动器上的位置。如果待打印的文件位于当前目录,则不需指定该参数。 
    FileName [...] 
    必需按名称指定要打印的文件。一个命令中可以包括多个文件。 
    /? 
    在命令提示符显示帮助。 
    注释
    如果将文件发送到连上本地计算机的串口或并口打印机,则可以后台方式打印文件。 
    许多程序都拥有自己的打印命令。应该使用程序的 print 命令打印使用该程序创建的文件。 
    可以利用 mode 命令从命令行执行多种配置任务。有关配置连接到计算机并口、串口的打印机,以及显示打印机状态,或准备打印机的代码页切换的详细信息,请参阅“相关主题”中的 mode。 
    范例
    要将当前目录中的 Report.txt 发送到连上本地计算机的 LPT2,请键入: print /d:LPT2 report.txt要将 c:\Accounting 目录中的 Report.txt 文件发送到服务器 \\CopyRoom 上的 Printer1 打印队列,请键入: print /d:\\copyroom\printer1 c:\accounting\report.txt
    //===================================================================================//
      

  4.   

    PRINTDLG  pd;
    memset ((void *) &pd, 0, sizeof(PRINTDLG));pd.lStructSize = sizeof(PRINTDLG);
    pd.hwndOwner   = hWnd;
    pd.Flags       = PD_RETURNDC;
    pd.hInstance   = NULL;
    PrintDlg(&pd);if (pd.hDevMode)
        GlobalFree (pd.hDevMode);
    if (pd.hDevNames)
        GlobalFree (pd.hDevNames);DOCINFO di;
    memset(&di,0,sizeof(DOCINFO));
    di.cbSize      = sizeof(DOCINFO);
    di.lpszDocName = _T("送货单");
    di.lpszOutput  = NULL;
    ::StartDoc(pd.hDC, &di);
    ::StartPage(pd.hDC);
    RECT rc = {100,100,200,200};
    ::DrawText(pd.hDC, _T("Test"), -1, &rc, DT_LEFT);
    ::EndPage(pd.hDC);
    ::EndDoc(pd.hDC);------------------------------------------------------------------
    以上的代码在单独的Hello上可以执行,但是如果放到OCX里,在网页端调用执行就会发生异常,调查了一下是StartDoc发生了异常,有谁知道在网页端调用会有什么限制吗?