printer++

printer++ 是什么

printer++ 是一个灵活的和强大的 windows 虚拟printer。允许用户从很多应用中打印,比如(excel,webpages,word…),然后将打印任务发送到一个printer++ SDK 解决方案,该方案是专门定制的,针对应用需求的。
通过printer++,用户,可以发送和处理一个很长的文档,报告,表格,表单,或者任何可打印的文字意义上的东西。printer++ 捕捉,打印数据,然后处理它。
通过printer++ ,用户可以轻易的发送有用的数据到数据存储区,邮件,短信,提交数据到另外一个系统,或者自定义的工作流程。设想一下,你可以从可打印的页面,获取数据。

想法来源

难题:我使用系统A,有时,我需要系统A的一些数据,实时的从系统A拷贝得到系统B,
解决方法:

1.使用用户手动输入,通过打字把数据从系统A输入到系统B

2.在系统A和系统B中定制一个后台程序,这样,在特定的事件发生的时候,将会从系统A到系统B,触发拷贝数据。
这个方法2 比方法1好,没有手动介入
缺点是,如果系统A或者系统B是一个商业系统,不让别随便动的系统。需要经过生产商的允许。也许会很贵,也许会很占用时间。

printer++的解决方法

在所有的应用中,都有打印页面的功能。
在系统A中,如果你能打印数据,同时这个数据,需要拷贝到系统B中。这样,我们可以“捕捉打印数据”,解析,然后使用它。
步骤为:
1.安装一个printer++ 虚拟打印机到用户的电脑中。可以命名为”系统A到系统B 打印机”,
2.我们创建一个(dll)解决方案,使用printer++SDK 来和上面的printer一起工作。
解决方案,将会从解析的页面中寻找数据元素,并提交到系统B。
这种方法,可以通过多种方式实现。比如,系统B APIs,windows宏。最难的部分,已经完成了,从系统A中,得到取出数据,变为可用的状态。

3.从用户的角度,任何时间,从系统A必须拷贝到系统的B的数据,可以简单的点击“PRINT”按钮,然后,选择“系统A到系统B 打印机”。

实际客户场景

我们的一个客户,是一个乡村经销商,该经销商,有一个畅销的产品是家庭货架。
客户将会登录官网,使用货架设计程序,然后打印出程序输出的列表,包括设计出的货架用用到的所有部件,元部件。
用户,然后会使用打印的数据,手动的输入到Excel中,并且在客户的数据库中,寻找价格,打上标记,然后为用户创建一个Excel的报价文档。在用户等待报价的时候,这些所有的工作,需要都完成。

步骤是:
1,在网站上设计货架
2,打印出货架部件列表
3,手动输入到Excel,然后寻找价格。
4,打印Excel中的报价。

使用printer++ SDK,我们创建一个应用程序解决方案,解析可打印的配件列表,在数据库中寻找价格,然后打印最终的报价文档,不用任何的手动输入。

1,在网站上设计货架
选择printer++ icon 用来做报价产生。

printer++ SDK的解决方案,解析打印页面,寻找配件列表,并找到价格,然后产生报价文档。

有时候,

有时候,你使用一些软件,发现它缺少特定的功能,但是所有的数据需要,你想为这个功能添加一个按钮,但是不能,因为那是一个第三方的软件。printer++允许你,添加 一个新的按钮,到第三方的应用中。这是一个快速,简单的方式,来扩展功能到你的系统。你可以添加多个printer++解决方案来作为不同的按钮。

使用方法:
win7 64位 PC
安装:printer++的64位版本
setup_x64.zip
https://www.printerplusplus.com/
https://www.printerplusplus.com/Content/setup_x64.zip

安装步骤参考:https://www.printerplusplus.com/Tutorial
Install printer++ with printer name: “EmailWeatherInCelcius”.

会出现如下目录:C:\PrinterPlusPlus
安装的过程,会出现如下安装文档:

C:\PrinterPlusPlus_Installer.txt

下载:Source:
https://www.printerplusplus.com/Content/source.zip

进入:source\Processors\Tutorial\EmailWeatherInCelcius\EmailWeatherInCelcius.csproj
编译出:
source\Processors\Tutorial\EmailWeatherInCelcius\bin\Debug\EmailWeatherInCelcius.dll

将EmailWeatherInCelcius.dll 拷贝到C:\PrinterPlusPlus

编译的时候用到了vs2010 和vs2013 。

查看一下配置文件:C:\PrinterPlusPlus\PrinterPlusPlus.exe.config:
内容如下:

<?xml version="1.0"?>
<configuration>
  <configSections>
    <section name="processors" type="System.Configuration.NameValueSectionHandler"/>
  </configSections>
  <processors>
    <add key="EmailWeatherInCelcius" value="EmailWeatherInCelcius.Processor, EmailWeatherInCelcius, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
  </processors>
  <appSettings>
    <add key="DefaultProcessor" value=""/>
    <add key="DebugMode" value="1"/>
  </appSettings>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
  </startup>
</configuration>

修改完毕之后,重启电脑
注意,不知道是否是没有重启电脑的原因,之前安装的32位的安装包,在打印机列表中,没有找到EmailWeatherInCelcius

重启电脑之后,运行printer++

这里写图片描述

然后打开一个文本文件,如下:
这里写图片描述

其中的EmailWeatherInCelcius 是 printer++ 的虚拟打印机。
执行打印:会自动调用如下函数:

using System;
using System.Net.Mail;
using PrinterPlusPlusSDK;
using System.IO; 

namespace EmailWeatherInCelcius
{
    public class Processor : PrinterPlusPlusSDK.IProcessor
    {
        public PrinterPlusPlusSDK.ProcessResult Process(string key, string psFilename)
        {

            StreamWriter log = new StreamWriter("E:\\printer++\\ceshi.txt", true);
            log.WriteLine("hello world time:" + System.DateTime.Now.ToLongTimeString() + "," + psFilename);


            //Convert PS to Text
            var txtFilename = System.IO.Path.GetTempFileName();
            ConvertPsToTxt(psFilename, txtFilename);

            log.WriteLine("hello world time:" + System.DateTime.Now.ToLongTimeString() + "," + psFilename + ',' + txtFilename);


            //Process the converted Text File
            var extractedValue = ProcessTextFileABC(txtFilename);

            //Ask user for recipeint's email
            var recipients = Microsoft.VisualBasic.Interaction.InputBox("Enter email address of recipient.");

            //Send email if user entered an email address
            if (!string.IsNullOrWhiteSpace(recipients))
            {
                log.WriteLine("Send Email " + recipients + "\r\n");

                SendEmail(extractedValue, recipients);
            }

            log.Close(); 


            return new ProcessResult();
        }

        ...  ...

%!PS-Adobe-3.0
%%Title: C:\Users\ABC\Desktop\a.txt
%%Creator: PScript5.dll Version 5.2.2
%%CreationDate: 4/23/2018 15:57:30
%%For: ABC
%%BoundingBox: (atend)
%%Pages: (atend)
%%Orientation: Portrait
%%PageOrder: Special
%%DocumentNeededResources: (atend)
%%DocumentSuppliedResources: (atend)
%%DocumentData: Clean7Bit
%%TargetDevice: (PrinterPlusPlus) (3010) 815
%%LanguageLevel: 3
%%EndComments

%%BeginDefaults
%%PageBoundingBox: 0 0 595 842
%%ViewingOrientation: 1 0 0 1
%%EndDefaults

%%BeginProlog
%%BeginResource: file Pscript_WinNT_ErrorHandler 5.0 0
/currentpacking where{pop/oldpack currentpacking def/setpacking where{pop false
setpacking}if}if/ brkpage64dictdef b r k p a g e 64 d i c t d e f brkpage begin/prnt{dup type/stringtype
ne{=string cvs}if dup length 6 mul/tx exch def/ty 10 def currentpoint/toy exch
def/tox exch def 1 setgray newpath tox toy 2 sub moveto 0 ty rlineto tx 0
rlineto 0 ty neg rlineto closepath fill tox toy moveto 0 setgray show}bind def
/nl{currentpoint exch pop lmargin exch moveto 0 -10 rmoveto}def/=={/cp 0 def
typeprint nl}def/typeprint{dup type exec}readonly def/lmargin 72 def/rmargin 72
def/tprint{dup length cp add rmargin gt{nl/cp 0 def}if dup length cp add/cp
exch def prnt}readonly def/cvsprint{=string cvs tprint( )tprint}readonly def
/integertype{cvsprint}readonly def/realtype{cvsprint}readonly def/booleantype
{cvsprint}readonly def/operatortype{(–)tprint =string cvs tprint(– )tprint}
readonly def/marktype{pop(-mark- )tprint}readonly def/dicttype{pop
(-dictionary- )tprint}readonly def/nulltype{pop(-null- )tprint}readonly def
/filetype{pop(-filestream- )tprint}readonly def/savetype{pop(-savelevel- )
tprint}readonly def/fonttype{pop(-fontid- )tprint}readonly def/nametype{dup
xcheck not{(/)tprint}if cvsprint}readonly def/stringtype{dup rcheck{(()tprint
tprint())tprint}{pop(-string- )tprint}ifelse}readonly def/arraytype{dup rcheck
{dup xcheck{({)tprint{typeprint}forall(})tprint}{([)tprint{typeprint}forall(])
tprint}ifelse}{pop(-array- )tprint}ifelse}readonly def/packedarraytype{dup
rcheck{dup xcheck{({)tprint{typeprint}forall(})tprint}{([)tprint{typeprint}
forall(])tprint}ifelse}{pop(-packedarray- )tprint}ifelse}readonly def/courier
/Courier findfont 10 scalefont def end errordict/handleerror{systemdict begin
errorbegin e r r o r b e g i n brkpage begin newerror{/newerror false store vmstatus pop pop 0
ne{grestoreall}if errorname(VMerror)ne{showpage}if initgraphics courier setfont
lmargin 720 moveto errorname(VMerror)eq{userdict/ehsave known{clear userdict
/ehsave get restore 2 vmreclaim}if vmstatus exch pop exch pop PrtVMMsg}{
(ERROR: )prnt errorname prnt nl(OFFENDING COMMAND: )prnt/command load prnt
error/ostack known{nl nl(STACK:)prnt nl nl $error/ostack get aload length{==}  
repeat}if}ifelse systemdict/showpage get exec(%%[ Error: )print errorname  
=print(; OffendingCommand: )print/command load =print( ]%%)= flush}if end end  
end}dup 0 systemdict put dup 4
error/ostack known{nl nl(STACK:)prnt nl nl $error/ostack get aload length{==}  repeat}if}ifelse systemdict/showpage get exec(%%[ Error: )print errorname  =print(; OffendingCommand: )print/command load =print( ]%%)= flush}if end end  end}dup 0 systemdict put dup 4
brkpage put bind readonly put/currentpacking
where{pop/setpacking where{pop oldpack setpacking}if}if
%%EndResource
userdict /Pscript_WinNT_Incr 230 dict dup begin put
%%BeginResource: file Pscript_FatalError 5.0 0
userdict begin/FatalErrorIf{{initgraphics findfont 1 index 0 eq{exch pop}{dup
length dict begin{1 index/FID ne{def}{pop pop}ifelse}forall/Encoding
{ISOLatin1Encoding}stopped{StandardEncoding}if def currentdict end
/ErrFont-Latin1 exch definefont}ifelse exch scalefont setfont counttomark 3 div
cvi{moveto show}repeat showpage quit}{cleartomark}ifelse}bind def end
%%EndResource
userdict begin/PrtVMMsg{vmstatus exch sub exch pop gt{[
(This job requires more memory than is available in this printer.)100 500
(Try one or more of the following, and then print again:)100 485
(For the output format, choose Optimize For Portability.)115 470
(In the Device Settings page, make sure the Available PostScript Memory is accurate.)
115 455(Reduce the number of fonts in the document.)115 440
(Print the document in parts.)115 425 12/Times-Roman[/STSong-Light–GBK-EUC-H
dup{findfont}stopped{cleartomark}{/FontName get eq{pop cleartomark[

 public GenericResult AddVPrinter(string printerName, string key)
        {
            GenericResult retVal = new GenericResult("AddVPrinter");
            try
            {
                string monitorName = "PrinterPlusPlus";
                string portName = string.Format("{0}:", printerName);
                string driverName = "PrinterPlusPlus";

                string driverFileName = "PSCRIPT5.DLL";
                string dataFileName = "PRINTERPLUSPLUS.PPD";
                string configFileName = "PS5UI.DLL";
                string helpFileName = "PSCRIPT.HLP";

                string driverPath = @"C:\WINDOWS\system32\spool\drivers\w32x86\PSCRIPT5.DLL";
                string dataPath = @"C:\WINDOWS\system32\spool\drivers\w32x86\VPRINTER.PPD";
                string configPath = @"C:\WINDOWS\system32\spool\drivers\w32x86\PS5UI.DLL";
                string helpPath = @"C:\WINDOWS\system32\spool\drivers\w32x86\PSCRIPT.HLP";

通过菜单 文件 打印的方式:
log:

2018/4/23 17:41:57 - Locked...Sleeping...
2018/4/23 17:41:57 - Created: C:\PrinterPlusPlus\Temp\EmailWeatherInCelcius_XXX-PC_XXX_20180423_174157_11.ps
2018/4/23 17:41:57 - Process: EmailWeatherInCelcius, C:\PrinterPlusPlus\Temp\EmailWeatherInCelcius_XXX-PC_XXX_20180423_174157_11.ps
2018/4/23 17:41:57 - Initializing Processor
2018/4/23 17:41:57 - Executing Process

PrinterPlusPlus_Installer.txt 内容如下:

2018/4/23 10:03:49 - Install Started.
2018/4/23 10:03:49 - PrinterName: MyPrinterTest
2018/4/23 10:03:49 - Setting Driver Path and Files.
2018/4/23 10:03:49 - Adding Printer Monitor.
2018/4/23 10:03:49 - Exception: 找不到指定的模块。
2018/4/23 10:03:49 - Source: AddVPrinter
Message: 找不到指定的模块。
InnerException: System.ComponentModel.Win32Exception (0x80004005): 找不到指定的模块。
   在 PrinterPlusPlusSetupCustomAction.SpoolerHelper.AddVPrinter(String printerName, String key)
2018/4/23 10:03:49 - Source: AddVPrinter
Message: Source: AddVPrinter
Message: 找不到指定的模块。
InnerException: System.Configuration.Install.InstallException: Source: AddVPrinter
Message: 找不到指定的模块。 ---> System.ComponentModel.Win32Exception: 找不到指定的模块。
   在 PrinterPlusPlusSetupCustomAction.SpoolerHelper.AddVPrinter(String printerName, String key)
   --- 内部异常堆栈跟踪的结尾 ---
   在 PrinterPlusPlusSetupCustomAction.Installer.Install(IDictionary stateSaver)
2018/4/23 10:03:49 - Install Finished.
2018/4/23 11:59:54 - Install Started.
2018/4/23 11:59:54 - PrinterName: EmailWeatherInCelcius
2018/4/23 11:59:54 - Setting Driver Path and Files.
2018/4/23 11:59:54 - Adding Printer Monitor.
2018/4/23 11:59:54 - Exception: 找不到指定的模块。
2018/4/23 11:59:54 - Source: AddVPrinter
Message: 找不到指定的模块。
InnerException: System.ComponentModel.Win32Exception (0x80004005): 找不到指定的模块。
   在 PrinterPlusPlusSetupCustomAction.SpoolerHelper.AddVPrinter(String printerName, String key)
2018/4/23 11:59:54 - Source: AddVPrinter
Message: Source: AddVPrinter
Message: 找不到指定的模块。
InnerException: System.Configuration.Install.InstallException: Source: AddVPrinter
Message: 找不到指定的模块。 ---> System.ComponentModel.Win32Exception: 找不到指定的模块。
   在 PrinterPlusPlusSetupCustomAction.SpoolerHelper.AddVPrinter(String printerName, String key)
   --- 内部异常堆栈跟踪的结尾 ---
   在 PrinterPlusPlusSetupCustomAction.Installer.Install(IDictionary stateSaver)
2018/4/23 11:59:54 - Install Finished.
2018/4/23 13:37:02 - Install Started.
2018/4/23 13:37:02 - PrinterName: EmailWeatherInCelcius
2018/4/23 13:37:02 - Setting Driver Path and Files.
2018/4/23 13:37:02 - Adding Printer Monitor.
2018/4/23 13:37:02 - Adding Printer Port.
2018/4/23 13:37:02 - Adding Printer Driver.
2018/4/23 13:37:03 - Adding Printer
2018/4/23 13:37:04 - Configuring Virtual Port
2018/4/23 13:37:04 - Restarting Spool Service
2018/4/23 13:37:05 - AddVPrinter Success
2018/4/23 13:37:05 - Adding Printer++ to Startup
2018/4/23 13:37:08 - Install Finished.
2018/4/23 13:45:06 - Install Started.
2018/4/23 13:45:06 - PrinterName: EmailWeatherInCelcius
2018/4/23 13:45:06 - Setting Driver Path and Files.
2018/4/23 13:45:06 - Adding Printer Monitor.
2018/4/23 13:45:06 - Adding Printer Port.
2018/4/23 13:45:06 - Adding Printer Driver.
2018/4/23 13:45:06 - Adding Printer
2018/4/23 13:45:06 - Exception: 打印机已存在。
2018/4/23 13:45:06 - Source: AddVPrinter
Message: 打印机已存在。
InnerException: System.ComponentModel.Win32Exception (0x80004005): 打印机已存在。
   在 PrinterPlusPlusSetupCustomAction.SpoolerHelper.AddVPrinter(String printerName, String key)
2018/4/23 13:45:06 - Source: AddVPrinter
Message: Source: AddVPrinter
Message: 打印机已存在。
InnerException: System.Configuration.Install.InstallException: Source: AddVPrinter
Message: 打印机已存在。 ---> System.ComponentModel.Win32Exception: 打印机已存在。
   在 PrinterPlusPlusSetupCustomAction.SpoolerHelper.AddVPrinter(String printerName, String key)
   --- 内部异常堆栈跟踪的结尾 ---
   在 PrinterPlusPlusSetupCustomAction.Installer.Install(IDictionary stateSaver)
2018/4/23 13:45:06 - Install Finished.

在word文档中点击 打印按钮,之后,都发生的了什么事情?

PScript5.dll

C:\PrinterPlusPlus\Temp\EmailWeatherInCelcius_ABC-PC_ABC_20180423_152219_7.ps
是啥时候生成的呢?

应该是在 驱动中 生成的。

证据是 ,如果不打开printer++ 应用程序,会在目录C:\PrinterPlusPlus\Temp\下面生成一个
类似下面名字的文件:
EmailWeatherInCelcius_ABC-PC_ABC_20180423_183010_13.ps

文件格式解析:

Building the Processor function
The Process function has two parameters: string key and string psFilename. Key is the name of the printer that initiated the process, while psFilename is the filename of the generated PostScript file.
From this method, we can do almost anything we want to the PostScript file. For this demo, we will be doing the following:
Convert the Postscript file to Text
Read the Text file to extract the values we want and convert the extracted values from Fahrenheit to Celcius.
Prompt user to email recipient.
Send email to recipients.
Click here to download the sample PostScript file generated by printer++.

Now, let’s start building the Processor function.
Convert the Postscript file to Text
For this conversion, we will be using Postscript to Text Converter from verydoc.
Download and unzip the converter to “C:\ps2txt”

Note that you can also use other conversion tools like Ghostscript and Xpdf.

We can now add a new method that will call the converter to convert the ps file:

public static string ConvertPsToTxt(string psFilename, string txtFilename)
{
    var retVal = string.Empty;
    var errorMessage = string.Empty;
    var command = "C:\\ps2txt\\ps2txt.exe";
    var args = string.Format("-nolayout \"{0}\" \"{1}\"", psFilename, txtFilename);
    retVal = Shell.ExecuteShellCommand(command, args, ref errorMessage);
    return retVal;
}

Then, we'll call the new function in our Process method:
//Convert PS to Text
var txtFilename = System.IO.Path.GetTempFileName();
ConvertPsToTxt(psFilename, txtFilename);

Click here to download the converted Text file.

Read the Text file to extract the values we want and convert the extracted values from Fahrenheit to Celcius
Now let’s analyze the converted text file, based from this conversion, we can create a logic on how to extract the values that we need.

New York Weather
Right Now
Updated: Aug 29, 2012, 3:25am EDT

73°F
Clear

We can use the line 47 with “Farming” value as a marker before we begin extracting the values.
To extract the following, let’s create a new function:

Postscript

http://www.verydoc.com/ps-to-text.html

Postscript to Text Converter is a utility for extracting text from PostScript and EPS files. It reads in postscript and EPS files and outputs an ASCII rendering. This is useful when trying to search or read the text contained in postscript and EPS files.

Postscript to Text Converter is a standalone application. No Ghostscript and Acrobat Distiller needed.
Postscript to Text Converter does maintain original physical layout in text files, the layout in converted text files are not difference compare to original PS and EPS files.

The ability to save any file as PostScript makes this a universal solution to convert forms (e.g. invoices, records) and database reports into pure, formatted ASCII text documents.

The software can be run using the handy interface or in batch mode to convert large volumes of graphics in real-time. This converter is available via an easily integrated COM object (or DLL Library, or Command Line), enabling developers to access the converter via any programming or scripting languages, such as Visual Basic, C/C++, Delphi, ASP, PHP, C#, .NET, etc. Using the COM object (or DLL Library, or Command Line), file conversions can be done consecutively or simultaneously.

改造 之后的应用源码 C#工程 ,使用 vs2013 或者 vs2010 都可以。
https://download.csdn.net/download/wowocpp/10372609

评论 8
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值