如何使用Qt Q打印机发送剪切纸命令
How to use Qt QPrinter to send cut paper command
我正在编写一个Qt桌面程序,该程序需要在交易后打印收据。为此,我需要在每张收据的末尾开具一张"剪纸"。我知道以下ascii字符(ascii 27+ascii 105)需要在打印文本的末尾发送才能剪纸。
我找不到任何关于如何使用QPrinter发送此邮件的文档。我使用QPrinter&QPainter实现打印。
如果有人尝试过,请建议如何在Qt中处理切纸打印机命令。
尽管我没有你的问题的确切答案,但我的收据打印机正在运行。"剪切"命令由打印命令中的TmxPaperSource=DocFeedCut
参数给定。
我制作了一个PDF,然后将其发送到打印机(我并不是在打印普通收据…)。
void printSomething(QGraphicsScene* scene)
{
/* Make a PDF-Printer */
QPrinter pdfPrinter(QPrinter::ScreenResolution);
pdfPrinter.setOutputFormat( QPrinter::PdfFormat );
pdfPrinter.setPaperSize( QSize(100, 80), QPrinter::Millimeter );
pdfPrinter.setPageMargins( QMarginsF(2, 0, 5.8, 0) ); //dont set top and bottom margins
pdfPrinter.setColorMode(QPrinter::GrayScale);
pdfPrinter.setResolution(203); //dpi of my printer
pdfPrinter.setFullPage(true);
pdfPrinter.setOutputFileName( "hello.pdf" );
/* Render the Scene using the PDF-Printer */
QPainter pdfPainter;
pdfPainter.begin( &pdfPrinter );
scene->render( &pdfPainter );
pdfPainter.end();
/* Print */
system( std::string("lp -o PageSize=RP80x297 -o TmxPaperReduction=Bottom -o Resolution=203x203dpi -o TmxPaperSource=DocFeedCut -o TmxMaxBandWidth=640 -o TmxPrintingSpeed=auto hello.pdf").c_str() );
}
我找到了这个问题的答案,并发布了这个问题,以便对其他人有用。
我使用append(ascii字符)命令将打印机命令附加到打印机。
这是我使用的示例代码:
QString printer_name = "PrinterOne";
qDebug() << "Test printing started...";
QByteArray print_content_ba("Test Print text ");
print_content_ba.append("n");
//add end of the receipt buffer & cut command
print_content_ba.append(27);
print_content_ba.append(105);
HANDLE p_hPrinter;
DOC_INFO_1 DocInfo;
DWORD dwJob = 0L;
DWORD dwBytesWritten = 0L;
BOOL bStatus = FALSE;
//code to convert QString to wchar_t
wchar_t szPrinterName[255];
int length = printer_name.toWCharArray(szPrinterName);
szPrinterName[length]=0;
if (OpenPrinter(szPrinterName,&p_hPrinter,NULL)){
qDebug() << "Printer opening success " << QString::fromWCharArray(szPrinterName);
DocInfo.pDocName = L"Loyalty Receipt";
DocInfo.pOutputFile = NULL;
DocInfo.pDatatype = L"RAW";
dwJob = StartDocPrinter( p_hPrinter, 1, (LPBYTE)&DocInfo );
if (dwJob > 0) {
qDebug() << "Job is set.";
bStatus = StartPagePrinter(p_hPrinter);
if (bStatus) {
qDebug() << "Writing text to printer" << print_content_ba ;
bStatus = WritePrinter(p_hPrinter,print_content_ba.data(),print_content_ba.length(),&dwBytesWritten);
if(bStatus > 0){
qDebug() << "printer write success" << bStatus;
}
EndPagePrinter(p_hPrinter);
} else {
qDebug() << "could not start printer";
}
EndDocPrinter(p_hPrinter);
qDebug() << "closing doc";
} else {
qDebug() << "Couldn't create job";
}
ClosePrinter(p_hPrinter);
qDebug() << "closing printer";
}
else{
qDebug() << "Printer opening Failed";
}
相关文章:
- 如何从命令行使用 cmake 为有根的安卓设备制作可执行文件?
- 命令模式 - 使用"weight"执行任务的命令
- 在一个命令中使用 2 个重载运算符会导致错误
- 从命令提示符使用 MSBuild 调试简单的C++可执行文件
- 如何通过命令行使用MSBUILD VS2015构建所有配置
- 如何在Xdotool命令中使用变量
- 如何从命令行使用 Visual Studio 2017 Codegen ClangC2?
- 错误:“命令” /重复使用ASM挥发性之前的预期字符串字母
- 如何将所选行的第一列值绑定到变量并在 QT 的 SQL 命令中使用它?
- 在预处理器命令中使用 qmake 变量 #include
- 如果使用命令在使用保留标识符时发出警告
- C++ microshell,输入一个命令并使用fork(),dup(),pipe()将其通过管道传输到进程。只是我没有得到我想要的结果
- SQLEXECTIRECT命令无法使用相同的查询
- GNUMake:使用不同命令同时使用C/C++目标的更好方法
- 发送cURL PUT命令,使用libcurl在c++中用程序在webhdfs中创建文件
- 如何从Windows上的命令行使用MinGW编译器
- 在C++中使用 Dos 命令时使用 GetLastError
- 在同一命令中使用变量时移动到 lambda
- 我试图打开一个gnuplot通过命令行使用c++和编译图形
- 通过命令行使用R时出错