Qt: printing on printer dot matrix

折月煮酒 提交于 2019-12-13 06:08:15

问题


I'm trying to print some string to a printer dot matrix LX-300+ using Qt but it seems that the font is skewed. Some users also have this problem http://www.qtcentre.org/threads/11814-printing-program-in-LX-300-(dot-matrix-printer)-problem but i can't find the solutions until now. Please help me to address this problem. Do i need to create a dll or application using other framework maybe .net if this is Qt bug? Here is my code

QTextDocument document;
QTextCursor cursor = QTextCursor(&document);
QFont font = QFont("Courier");
QTextCharFormat format = QTextCharFormat();
format.setFont(font);
cursor.setCharFormat(format);
cursor.insertText("lorem ipsum dolor sit amit amit ");

QPrinter printer(QPrinter::ScreenResolution);
printer.setPrinterName(ui->ddlPrinter->currentData().toString());
printer.setColorMode(QPrinter::GrayScale);
printer.setPageSize(QPrinter::A4);
printer.setFullPage(false);
QPrintDialog dialog(&printer, this);
document.print(&printer);

i'm using Qt5.4.0 mingw491 32 OS win 7 64bit


回答1:


I can solve this problem using Windows API directly like this pseudo code

OpenPrinter(name,&hPrinter, NULL);
dwJob = StartDocPrinter( hPrinter, 1, (LPBYTE)&DocInfo );
bStatus = StartPagePrinter(hPrinter);
BOOL bStatus = WritePrinter(hPrinter,(LPVOID)buffer,text.length(),&dwBytesWritten);

hope this help someone



来源:https://stackoverflow.com/questions/32310797/qt-printing-on-printer-dot-matrix

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!