1 Attachment(s)
Please help with Arabic text printing and PDF creation
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:
Code:
{
qint32 margin = 40 ;
QRect rct
= printer.
paperRect().
adjusted(margin, margin,
-margin,
-margin
) ;
painter.drawRect(rct) ;
toption.setTextDirection(Qt::RightToLeft) ;
QFont fontTitle
("Arial",
36) ;
fontTitle.setBold(true);
painter.setFont(fontTitle);
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::AlignHCenter);
painter.drawText(rct.adjusted(0, 10+painter.fontMetrics().height()*4, 0, 0), text, toption);
}
void Widget::on_pbPDF_clicked()
{
if(fileName.isEmpty())
return ;
printer.
setOutputFormat(QPrinter::PdfFormat);
printer.setOutputFileName(fileName);
printDocument(painter, printer) ;
painter.end() ;
}
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 .
Re: Please help with Arabic text printing and PDF creation
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.
Re: Please help with Arabic text printing and PDF creation
send the result pdf if you please :)
1 Attachment(s)
Re: Please help with Arabic text printing and PDF creation
Sure here is the result.
i would have tested the print function too but i dont have my printer installed right now.
Attachment 9765
Good Luck.
Re: Please help with Arabic text printing and PDF creation
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.
Re: Please help with Arabic text printing and PDF creation
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.
Re: Please help with Arabic text printing and PDF creation
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
Re: Please help with Arabic text printing and PDF creation
@toufic.dbouk
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
https://qt.gitorious.org/qt/qtbase/s.../changes-5.1.1
Re: Please help with Arabic text printing and PDF creation
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.