Software: PDF printer software such as Pdfcreater or PrimoPDF or Bullzip PDF Printer. Ghostscript 9.10
HDC to ps:1. Use the printer name to create the HDC. 2. StartDoc (), set the PS file path name.
PS to PDF: Call Ghostscript's ps2pdf.bat. Note: You may be prompted to find "Gswin32c.exe" when you call. Place the path where it is located.
Example code:
void Hdc2pdf_demo (const cstring& strpsfilename = _t ("c:\\postscript.ps"), const cstring& strpdffilename= _T ("C:\\postscript.pdf"), const cstring& strprintername= _t ("PrimoPDF"),//printer name, from "Control Panel/printer and fax const Cstrin" g& Strhelloworld = _t ("Hello world!!!"))
{///1. HDC, POSTSCRIPT///1.1. Use the printer name to create the HDC.
HDC HDC =:: CreateDC (NULL, Strprintername, null,null); 1.2.
StartDoc (), set the PS file path name.
DocInfo docinfo={0};
docinfo.cbsize = sizeof (DocInfo);
Docinfo.lpszoutput = Strpsfilename;
:: StartDoc (HDC, &docinfo);
:: StartPage (HDC);
TextOut (HDC, $, Strhelloworld, Strhelloworld.getlength ());
:: EndPage (HDC);
:: EndDoc (HDC);
::D Eletedc (HDC); 2.
PostScript--PDF CString 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); }