通过命令行更改打印机设置

通过命令行更改打印机设置

我有一台 Brother PT-9800PCN 标签打印机,使用 6mm 至 36mm 的胶带。有没有办法通过命令行更改默认纸张尺寸(宽度、长度、方向)?我使用 fpdf 在 pdf 中生成 18x113mm 和 24x50mm 标签,当通过 php 将 pdf 发送到打印机时,它只会在默认设置的纸张尺寸上打印。我尝试过使用 Adob​​e、Foxit 和 Sumatra 的命令。我还尝试过 Verypdf pdfprint 命令行,它有设置纸张尺寸的选项,结果相同。我想如果我通过命令行更改默认纸张尺寸,然后发送打印作业,它应该可以工作。

答案1

经过长时间的思考,我终于让它工作了。我所做的是

->对于所需的每种纸张尺寸,进入打印机首选项并设置页面尺寸、宽度、长度和任何其他所需设置

->在完成每个页面大小的所有设置后,在 cmd 中运行

rundll32 printui.dll PrintUIEntry /Ss /n "\\network\printer" /a "C:\prefered_location\temp_settings.dat" u

->对于我需要的每种页面大小,我将设置保存18x113m.dat24x45mm.dat

这是我在 php 中用来将 pdf 发送到打印机的代码

<?php
//save current printer settings to a temp file
echo system("rundll32 printui.dll PrintUIEntry /Ss /n \"\\\\network\\printer\" /a \"C:\\location\\temp_settings.dat\" u");
//load the required page settings
echo system("rundll32 printui.dll PrintUIEntry /Sr /n \"\\\\network\\printer\" /a \"C:\\location\\24x45mm.dat\" u");
//send pdf to printer. I've used in this case pdfprint.exe. Foxit can be used as well. Adobe didn't work. Sumatra still sends the pdf only to a 36mm tape
echo system("C:\\location\\pdfprint_cmd\\pdfprint.exe -printer \"\\\\network\\printer\" C:\\location\\mypdf.pdf");
//restore temp settings
echo system("rundll32 printui.dll PrintUIEntry /Sr /n \"\\\\network\\printer\" /a \"C:\\location\\temp_settings.dat\" u");
//delete temp settings file
echo system("del C:\\location\\temp_settings.dat");
?>

相关内容