View Full Version : Please help with Arabic text printing and PDF creation

7th November 2013, 19:38
I'm trying to print an Arabic text to PDF file and to a normal printer using QPrinter. I face two different problems.

First, when printing to PDF, text appears as if cracked; with spaces between characters (letters) that should be there.

Second, when printing to a normal printer the text appears correct, but with wrong text alignment !

printing code:

void Widget::printDocument(QPainter &painter, QPrinter &printer)
qint32 margin = 40 ;

QRect rct = printer.paperRect().adjusted(margin, margin, -margin, -margin) ;
painter.drawRect(rct) ;

QTextOption toption ;
toption.setTextDirection(Qt::RightToLeft) ;

QFont fontTitle("Arial", 36) ;
QString title = ui->leTitle->text().trimmed() ;
toption.setAlignment(Qt::AlignTop|Qt::AlignHCenter );
painter.drawText(rct.adjusted(0, 10, 0, 0), title, toption);

QFont fontText("Arial", 28) ;
painter.setFont(fontText) ;
QString text = ui->teText->toPlainText() ;
toption.setAlignment(Qt::AlignLeft|Qt::AlignHCente r);
painter.drawText(rct.adjusted(0, 10+painter.fontMetrics().height()*4, 0, 0), text, toption);


void Widget::on_pbPDF_clicked()
QString fileName = QFileDialog::getSaveFileName(this, QString(), QString(), QString("*.pdf(*.pdf)")) ;
return ;

QPrinter printer ;

QPainter painter(&printer) ;

printDocument(painter, printer) ;

painter.end() ;

QDesktopServices::openUrl(QUrl(fileName)) ;


system information:

- tried both Windows 7 64bit, and Windows XP (with Qt 4.8)
- the printer: tried both HP 1018, and HP Laserjet P1005
- Qt version: tried 4.8, and 5.1 both has the same problem.

Note: attached a sample qt project that shows the problem. and the resulting pdf .

8th November 2013, 01:16
It worked fine for me.
The pdf file was created without any * cracking of text *.
For the printing part, i didnt test it.

Good Luck.

8th November 2013, 18:58
send the result pdf if you please :)

8th November 2013, 19:34
Sure here is the result.
i would have tested the print function too but i dont have my printer installed right now.


Good Luck.

10th November 2013, 13:32
first, thanks for your help :)

- I tried several fonts on different OSs but in all cases the font character positioning is wrong ( additional spaces appear between characters)

- after the result you give to me, I tried to compile the same application with Qt version 4.7.4 on windows 7, and I got a very good result pretty like the one you sent to me. looks like the problem is in the printing support of the latest Qt !

thanks again.

10th November 2013, 13:49
I used Qt 5.1.1 on Windows 7 64 bit.
How about the printing issue that you were facing ? ( the flipped parenthesis )
Did you fix it ?

Good Luck.

11th November 2013, 12:39
the flipped parenthesis problem when printed to a hw printer still exists even when compiled with 4.7.4

I've submitted a bug report, anyway: https://bugreports.qt-project.org/browse/QTBUG-34678

11th November 2013, 15:10

I've just notices the bugfix ( as I think ) in the changes log of Qt 5.1.1:

- REG: Fix character size when exporting PDF on Windows


11th November 2013, 22:10
I will test it on windows 7 64 bit using Qt 5.1.1 in a couple of days and get back to the post.

Good Luck.