2.修改DDK 里面的例子 genprint, 并使用ddk里的build命令直接build.
(顺带说一下,执行build程序要先执行Windows XP Checked Build Environment 这样的环境设置BAT)
修改的地方是:winprint.c 里的 PrintDocumentOnPrintProcessor 函数,将其中 调用PrintEMFJob的地方更改为我们处理的函数.
一般会将这个函数放在另一个DLL中.
3.更改注册表,使其spl文件名根据job id生成.这样我们通过其JOB ID就可以得到相应的SPL文件.
参考:http://www.undocprint.org/winspool/spool_files#reading_job_data 里面的 Force JobID in Spoolfile names
4.通过spl文件结构,获取EMF文件。
5.把EMF文件转换为其它图片文件。
QA:
Q:如何修改打印驱动?我对里面的驱动格式一点都不熟悉。
A:不用改了,我用的是HP LaserJet 4驱动,下载地址:
http://h50176.www5.hp.com/support/C2001A/more_info_soar_lj631sc.html
以下是inf内容:
inf start///
;Hewlett-Packard LaserJet combined printer driver INF file for Windows XP and 2000
;Copyright Hewlett-Packard 2001
; List of supported printers, manufacturers
[Version]
Signature="$Windows NT$"
Provider=%虚拟打印%
ClassGUID={4D36E979-E325-11CE-BFC1-08002BE10318}
Class=Printer
DriverVer=1/18/2002,02.00.12.02
; Manufacturer section.
;
; This section lists all of the manufacturers
; that we will display in the Dialog box
[Manufacturer]
%虚拟打印%=DefaultInstall
;
; MS Driver Core installs
;
; These sections are used by Printer OEMs to install MS provided drivers
; Installer Sections
;
; These sections control file installation, and reference all files that
; need to be copied. The section name will be assumed to be the driver
; file, unless there is an explicit DriverFile section listed.
;
; Note: Pulling HPLJ4.GPD via Needs= directive to get pcl5eres.dll from XP
; drivers.cab file due to XP defect whereby this file wasn't listed
; This also takes care of pjlmon.dll, ttfsub.gpd, UNIDRV sections
; but unavoidably brings with it the unneeded hplj4.gpd file.
;
; In the case of the LJ4 install does Needs=HPLJ4.GPD overwrite the
; just copied newer version of hplj4.gpd??? In this case perhaps, use
; Needs=HPLJ4L.GPD to avoid this issue?
;
; Phase II GPDs
[DefaultInstall]
"虚拟打印机" = HPLJ4L.GPD.XP ,Hewlett-PackardLaserC029,HP_LaserJet_4L
;Hewlett-PackardLaserC029是设备的ID
;
; XP
;Old CopyFiles statement before use of Includes= & Needs= ...
;CopyFiles=HPPRPROC,UI,RENDER,@HPLJ4.GPD,@hpc02.ini,RES_COMMON,HELP,UNIDRV,PJLMON.DLL,@TTFSUB.GPD
[HPLJ4L.GPD.XP]
CopyFiles=HPPRPROC,@HPLJ4L.GPD,@hpcstr02.dll
Include=NTPRINT.INF
Needs=HPLJ4.GPD
DataSection=HP_UNIDRV_BIDI_DATA
DataFile=HPLJ4L.GPD
PrintProcessor=%PRINT_PROCESSOR%
; Copy Sections
;
; Lists of files that are actually copied. These sections are referenced
; from the installer sections, above. Only create a section if it contains
; two or more files (if we only copy a single file, identify it in the
; installer section, using the @filename notation) or if it's a color
; profile (since the DestinationDirs can only handle sections, and not
; individual files).
[RES_COMMON]
pcl5eres.dll
hpcstr02.dll
[HPPRPROC]
genprint.dll,,,0x00000020
;
; Data Sections
;
[HP_UNIDRV_DATA]
DriverFile=UNIDRV.DLL
ConfigFile=UNIDRVUI.DLL
HelpFile=UNIDRV.HLP
; Data section that attaches PJLMON as the driver Lang Monitor
[HP_UNIDRV_BIDI_DATA]
DriverFile=UNIDRV.DLL
ConfigFile=UNIDRVUI.DLL
HelpFile=UNIDRV.HLP
LanguageMonitor=%PJL_MONITOR%
;
; Call SetupSetDirectoryId with 66000 to set the target directory at runtime
; (depending on which environment drivers are getting installed)
;
[DestinationDirs]
DefaultDestDir=66000
HPPRPROC=66001
PJLMON.DLL=66002
;
; Control Flags
;
[ControlFlags]
ExcludeFromSelect = HWP20D0, HWP21A0, HWP2140, HWP20F0
;
; Source Disk Section
; This was added to enable Web Point&Print.
; All files added to this must also be added to Layout.INF
;
[SourceDisksNames]
1=%DiskID1%,,,""
[SourceDisksFiles]
;
; MS Files
;
PCL5ERES.DLL = 1
UNIDRV.DLL = 1
UNIRES.DLL = 1
UNIDRVUI.DLL = 1
STDNAMES.GPD = 1
UNIDRV.HLP = 1
TTFSUB.GPD = 1
;
; Phase II
;
HPCUI02.DLL = 1
HPCRD02.DLL = 1
HPCFNT02.DLL = 1
HPCSTR02.DLL = 1
genprint.dll = 1
HPCLJX02.HLP = 1
HPC02.INI = 1
HPOEMUI.DLL = 1
HPCMBOX.INI = 1
HPLJ4L.GPD = 1
;
; Localizable Strings
;
[Strings]
PrinterClassName="Printers"
DiskID1="虚拟打印安装盘"
PJL_MONITOR="PJL Language Monitor,PJLMON.DLL"
;PRINT_PROCESSOR="HPPRN02,hpprn02.dll"
PRINT_PROCESSOR="Vprint,genprint.dll"
虚拟打印="虚拟打印"
//inf end//
Q:为什么我在打印的时候, PrintDocumentOnPrintProcessor 没有被调用?
A:可能是因为在你的虚拟打印机设了脱机的原故,当时我就碰到了.
Q:如何方便调试.
A:因为genprint.dll是被Print服务占用的,因此,替换的时候需要停止改服务.
Net Start "Print Spooler"
Copy file file
Net Stop "Print Spooler"
Q:从SPL中分离出EMF文件需要注意什么吗?
A:一定会用到的三个结构 SPL_HEADER(SPL头)、SMR(SPL记录)、ENHMETAHEADER(EMF头).
Q:我不能用acdsee等软件打开分离出的EMF,但为什么用IE是可以打得开的?
也许你用的是SMR::nSize 来做为EMF的write size
而不是使用ENHMETAHEADER::nBytes 来做为EMF的write size
Q:我想通过GDI+把EMF文件转为BMP,为什么文字部份显视黑屏?
A:不知道,我是用IPicture 读取,并且Render到DC后再保存为BMP的,这样也不行,在Render内存的时候就不行了。
最后我用的是CXImage 这个库做的转换.
Q:最后我的OFFICE 2007里面的文字打印出来被挤得变形了。
A:嘿嘿嘿,其实我已经放弃了这个方案了。使用OEMDLL里面的Bitmap例子来实现了。
网上的资料:
http://www.undocprint.org 95%以上的资料来源.
http://www.microsoft.com/india/msdn/articles/130.aspx 有个专门的函数取得相关的SPL文件名.
http://fxh7622.blog.51cto.com/63841/d-3 最先找到的网址,里面的例子部分是用DELPHI的,我的INF文件就是从这里拷的