简体   繁体   English

使用订书钉在MS-Word中进行Delphi打印

[英]Delphi Print in MS-Word using Staples

I'm trying to print documents in MS-Word. 我正在尝试在MS-Word中打印文档。 Either by TWordApplication or OleVariant is ok with me. TWordApplication或OleVariant都可以。 Our printer has the option to print. 我们的打印机可以选择打印。 We use a Xerox printer with staple cababilities. 我们使用具有钉书钉功能的Xerox打印机。 When i do everything manually, it works fine of course. 当我手动执行所有操作时,它当然可以正常工作。 When i do it from code, i can't seem to make it work. 当我通过代码执行此操作时,我似乎无法使其正常工作。

Delphi itself has as far as i know, no connection to set up staples directly. 据我所知,Delphi本身没有直接建立订书钉的联系。 Not from code, not from MS-Word. 不是来自代码,不是来自MS-Word。 I set up 2 types of print jobs on my printer (advanced settings). 我在打印机上设置了两种类型的打印作业(高级设置)。 One for normal printing and one for printing with 1 staple. 一种用于普通打印,一种用于使用1个订书钉打印。 For both settings i made an export. 对于这两种设置,我都进行了导出。 Then i tried to import the setting where i needed them. 然后,我尝试将设置导入需要的位置。 Unfortunately, the printer driver does not seem to like what i'm doing. 不幸的是,打印机驱动程序似乎不喜欢我在做什么。 Every time i try to import the setting for the staples, the driver seems to delete the import from the registry and uses its default. 每次我尝试导入装订钉的设置时,驱动程序似乎都会从注册表中删除导入并使用其默认设置。 After i try to overwrite the entry 'DevMode' in any way, the entry in the registry is deleted and the printer goes to default mode. 在我尝试以任何方式覆盖条目“ DevMode”之后,注册表中的条目将被删除,打印机将进入默认模式。

I tried to import a registry file, but that fails. 我试图导入注册表文件,但是失败了。 I tried to import the value from the registry file and write it with WriteBinaryData, but that deletes the DevMode entry. 我试图从注册表文件中导入值,并使用WriteBinaryData写入它,但这会删除DevMode条目。 I tried to copy the registry value from another registry value somewhere in the Registry that holds the information of profiles that i created. 我试图从另一个注册表值中复制另一个注册表值,该注册表值保存了我创建的配置文件的信息。 Nothing seems to happen when i try that though. 我尝试尝试时似乎什么也没发生。

can anyone help me with this, as far as i know, i tried everything, but i can't seem to make it work. 据我所知,有人能帮助我吗,据我所知,我尝试了一切,但似乎无法使其正常工作。 It could also be that i did something wrong with the WriteBinaryData and the ReadBinaryData. 也可能是我对WriteBinaryData和ReadBinaryData做错了。 If someone could give me a working example for that, i would be very greatful. 如果有人可以给我一个可行的例子,我将非常感激。

I work with Delphi XE2. 我使用Delphi XE2。

TIA TIA

The DEVMODE structure is used internally by the printer driver, it includes internal data (even driver heap ) and must not be modified unless you have a detailed HOWTO sheet from the manufacturer. DEVMODE结构由打印机驱动程序在内部使用,它包含内部数据(甚至驱动程序堆 ),除非您有制造商的详细HOWTO表,否则不得修改。 What you are trying to achieve requires a more hardware-close viewpoint than reaching your printer trough OLE, and - poorly - there are no guarantees that it can even be done if the manufacturer did not provide an API directly for this purpose. 您要达到的目标需要比进入OLE打印机更接近硬件的观点,而且-很糟糕 -如果制造商没有为此目的直接提供API, 无法保证甚至可以完成 (And normally they don't.) (通常他们不这样做。)

Create a macro within Word which does what you want, then copy this macro into your program. 在Word中创建所需功能的宏,然后将此宏复制到程序中。 Obviously, you will have to change the syntax a certain amount. 显然,您将必须对语法进行一定的更改。 Also, macros in Word (and Excel) use constants which are defined within those programs but not within Delphi, so you will have to discover what their values are, then use those values in your program. 另外,Word(和Excel)中的宏使用在那些程序中定义的常量,而不是在Delphi中定义的常量,因此,您必须发现它们的值是什么,然后在程序中使用这些值。

Can you enable staples using you printer driver config? 您可以使用打印机驱动程序配置启用装订钉吗? If so, circumvent the problem by installing te printer twice on windows, one with and one without staples, and select te printer you want upon printing. 如果是这样,请在Windows上安装两次打印机(一个装订和装订不带钉书钉),然后选择要在打印时选择的打印机,以解决该问题。 Word has an property in the COM API for that. Word在COM API中具有该属性。 I used this method myself for selection different papertrays. 我自己使用此方法选择了不同的纸盘。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM