终端服务 (Win32) 下的打印问题
对于我们的应用程序,我们需要能够在页面上的特定位置打印输出。 例如,我们需要能够在相对于页面左上角的精确 (1.00", 1.00") 处打印一些文本。 问题在于,各种 GDI 调用中的所有坐标都不是相对于显示器的左上角,而是相对于设备相关的偏移量,可以通过以下代码获得该偏移量:
int cx = ::GetDeviceCaps(hDC, PHYSICALOFFSETX);
int cy = ::GetDeviceCaps(hDC, PHYSICALOFFSETY);
当然,这些坐标位于设备单位,因此您可以根据需要将它们转换为逻辑单位。 然后,您可以在其他 API 调用中调整坐标,以准确获得您需要的输出。
当直接在 Windows 下运行时,这就像一个魅力。 但是,当使用终端服务打印到 Windows Server 2008 上的重定向打印机时,DeviceCaps 函数不再报告正确的信息,至少对于大量不同的打印机而言是如此。 设备偏移量报告为 0,并且在查询页面上的可打印区域时,会返回不正确的信息(API 夸大了可用空间的数量)。 更糟糕的是,微软或打印机驱动程序供应商似乎都意识到了这个问题,因为当打印作业后台打印到本地计算机时(这样它就可以后台打印到本地打印机),所有输出都会通过一些补偿来转移。数量; 这个数字似乎是黑客行为,因为它与本地查询打印机功能时 GetDeviceCaps 报告的正确值相差甚远。
因此,结果是打印输出从页面上移出......
还有其他人看到过此类问题吗? 我是否疯狂地想要精确控制打印输出? 当然,为了正确分页,需要一个准确的可用可打印空间量值,不是吗? 任何帮助或指示将不胜感激。
For our application, we need to be able to print output at a specific location on a page. For example, we need to be able to print some text at exactly (1.00", 1.00") relative to the top left corner of the page. The problem lies in the fact that all coordinates in the various GDI calls are not relative to the upper left corner of the display, but are rather relative to a device dependent offset, which one obtains with code like:
int cx = ::GetDeviceCaps(hDC, PHYSICALOFFSETX);
int cy = ::GetDeviceCaps(hDC, PHYSICALOFFSETY);
These, of course, are in device units, so you convert them to logical units as desired. And then, you may adjust your coordinates in other API calls to get the output exactly where you need it.
This works like a charm when running under Windows directly. However, when using Terminal Services to print to a redirected printer on Windows Server 2008, the DeviceCaps functions no longer report correct information, at least for a large number of different printers. Device offsets are reported as 0, and when querying the printable region on a page, incorrect information is returned (the APIs overstate the amount of available real estate). Worse, it appears that either MS or the printer driver vendor is aware of the issue, because when the print job spools to your local machine (so that it can then spool to your local printer), all of the output is shifted by some compensating amount; an amount that appears to be a hack as it is nowhere close to the correct value reported by GetDeviceCaps when querying printer capabilities locally.
So, the result is that printed output gets shifted off the page ...
Has anyone else seen issues of this sort? Am I crazy to want precise control over printed output? Certainly, in order to paginate correctly, one needs an accurate value for the amount of available printable space, no? Any help or pointers would be appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Microsoft 知识库问题 959442 和随附的修补程序应该可以解决该问题:
"当您尝试从运行 Windows XP SP3 的客户端计算机使用终端服务轻松打印来打印文档时,文档的边缘被截断, Windows Vista SP1 或 Windows Server 2008”
The Microsoft Knowledgebase issue 959442 and the included hotfix should resolve the problem:
"The edges of a document are truncated when you try to print the document by using Terminal Services Easy Print from a client computer that is running Windows XP SP3, Windows Vista SP1, or Windows Server 2008"