hDC转PostScript转PDF

来源:互联网 发布:2017淘宝补单 编辑:程序博客网 时间:2024/06/06 03:49
软件:
    PDFCreater 或 PrimoPDF 或 BullZip PDF Printer 等PDF打印机软件.
    GhostScript 9.10

hDC转PS:
1. 使用打印机名创建hDC.
2. StartDoc()时,设定PS文件路径名.

PS转PDF:
调用GhostScript的ps2pdf.bat. 注意: 调用时可能会提示找不到"gswin32c.exe".把它所在路径放到path里即可.

例子代码:
void hDC2PDF_Demo( const CString& strPSFileName = _T("c:\\PostScript.ps"),    const CString& strPDFFileName= _T("c:\\PostScript.pdf"),    const CString& strPrinterName= _T("PrimoPDF"), // 打印机名字,来自"控制面板/打印机和传真   const CString& strHelloWorld = _T("Hello world!!!") ){/// 1. hDC -> PostScript/// 1.1. 使用打印机名创建hDC.HDC hDC = ::CreateDC(NULL, strPrinterName, NULL,NULL);/// 1.2. StartDoc()时,设定PS文件路径名.DOCINFO DocInfo={0};DocInfo.cbSize      = sizeof(DOCINFO);DocInfo.lpszOutput  = strPSFileName;::StartDoc(hDC, &DocInfo);::StartPage(hDC);TextOut( hDC, 200, 200, strHelloWorld, strHelloWorld.GetLength() );::EndPage(hDC);::EndDoc(hDC);::DeleteDC(hDC);/// 2. PostScript -> PDFCString strParameters;strParameters.Format(_T("-q -P- -dSAFER -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=%s -dCompatibilityLevel=1.4 -c .setpdfwrite -f%s "), strPDFFileName, strPSFileName );SHELLEXECUTEINFO ShExecInfo = {0};ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);ShExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS;ShExecInfo.hwnd = NULL;ShExecInfo.lpVerb = NULL;ShExecInfo.lpFile = _T("gswin32c.exe");ShExecInfo.lpParameters = strParameters;ShExecInfo.nShow = SW_HIDE;ShExecInfo.hInstApp = NULL;ShellExecuteEx(&ShExecInfo);WaitForSingleObject(ShExecInfo.hProcess,INFINITE);}



   
0 0
原创粉丝点击