0
votes

How to print html with cyrillic symbols? I tried to do this:

QTextDocument *document = new QTextDocument();
document->setHtml(htmlContent);
document->print(printer);

But document printed in wrong encoding. Html encoding is utf-8.

2
How is your printer set up? Are you using CUPS? With which driver? On which operating system, with which printer ?Basile Starynkevitch
printer set up (if you mean this): printer->setPaperSize(QSizeF(114,162), QPrinter::Millimeter); printer->setOrientation(QPrinter::Portrait); printer->setPageMargins(0,0,0,0, QPrinter::Millimeter); printer->setOutputFormat(QPrinter::NativeFormat); Yes, cups is running on debian. Printer's model CUSTOM Engineering VKP80.axon
Have you tried displaying that QTextDocument in a QTextEdit? Does it display correctly there?hyde
No, because it's console app running under xvfb, but when i put htmlContent into console charset incorrect too.axon
You could make a GUI app (or just add gui module to project, and launch a window in this spot), and see if it displays correctly there. If it does not, then your question changes, it no longer has nothing to do with printing, which is kind of important detail... :)hyde

2 Answers

1
votes

Assuming htmlContent is QString, you probably created it with wrong encoding. For example, if original HTML data (which is bytes) is UTF-8, then you should maybe use something like

htmlContent = QString::fromUtf8(myHtmlDataCharPtr);

If htmlContent is char pointer to UTF-8 data, then you should use

document->setHtml(QString::fromUtf8(htmlContent));

0
votes

QTextDocument needs very correct HTML to function correctly - WebKit / Firefox / QWebBrowser usually accepts less wellformed input and still displays it correctly. Thus write the output into a file and send it to some HTML-checking program, fix all issues and then try again.