为什么打印机会改变分辨率?用户,背景,什么?
我正在 Windwos php 服务器上使用 exec 从 php 运行 .bat 文件,其中 php 使用 fast-cgi (和 nginx)运行。运行此脚本的命令行是
pclose(popen("start / ". $cmd, "r"));
$cmd 类似于“mybatfile.bat 45 1”
当我手动运行批处理文件时,它会运行一个 python 程序来读取数据库,获取一些数据并打印一些小报告。而且一切都 100% 正确。
当它从网页运行时,报告就会出来,所以我知道程序已经运行了。该代码记录传递的参数。我知道这个电话是正确的。
从服务器/网页运行时,同一打印机上显示的报告比从并行线路运行时大大约 20%。
python 脚本使用 PyQt 并以本机模式打开打印机。
代码是
self.printer = QPrinter()
self.printer.setPrinterName(printer)
self.printer.setPageSize(QPrinter.A5)
self.printer.setOrientation(QPrinter.Portrait)
self.painter = QPainter(self.printer)
有谁知道为什么会发生这种情况 - 我能做些什么来纠正它?
操作系统是用于开发的 Windows 7(64 位)和用于生产的服务器版本。 Python 2.7 32 位。 QT 版本 4。
谢谢 伊恩
I am runing a .bat file from a php using exec on a Windwos php server, where php is run using fast-cgi (and nginx). The command line to run this script is
pclose(popen("start / ". $cmd, "r"));
Where $cmd is somethign like "mybatfile.bat 45 1"
When I run the batch file manually it runs a python program to read a database, get hold of some data, and print a little report. And it all works 100% correctly.
When it is run from the web page, the report comes out, so I know the program is run. The code logs the parameters passed. I know that the call is correct.
When run from the server/web page the report appears on the same printer approx 20% larger that when run from the coammnd line.
The python script uses PyQt and opens the printer in native mode.
The code is
self.printer = QPrinter()
self.printer.setPrinterName(printer)
self.printer.setPageSize(QPrinter.A5)
self.printer.setOrientation(QPrinter.Portrait)
self.painter = QPainter(self.printer)
Does anyone know why this happens - and what can I do to correct it?
O/S is windows 7 (64 bit) for developement and a Server version for production.
Python 2.7 32 bit.
QT version 4.
Thanks
Ian
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
破解了!
运行服务器的用户从未(自然)登录过,因此他们从未将屏幕分辨率从 90 dpi 更改过。
另一方面,我改变了屏幕分辨率,因为我使用大字体。
所以当我运行打印时,它以 120 dpi 打印。当服务器运行它时,它以 90 dpi 打印。
解决方案。
打开打印机后,读回实际分辨率,并计算比例因子。
对所有布局和定位使用比例因子 - 除了以磅为单位的字体大小,无论如何它都是正确的。
Cracked it!
The user who is running the server has never logged in (naturally) so they have never changed their screen resolution from 90 dpi.
I on the other hand, have changed by screen resolution because I use large fonts.
So when I ran the print it printed in 120 dpi. When the server ran it, it printed in 90 dpi.
Solution.
After opening the printer, read the actual resolution back, and compute a scale factor.
Use the scale factor for all layout and positioning - except font sizes in points which will be correct anyway.