Results 1 to 9 of 9

Thread: Please help with Arabic text printing and PDF creation

  1. #1
    Join Date
    Dec 2008
    Posts
    15
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Question 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:

    Qt Code:
    1. void Widget::printDocument(QPainter &painter, QPrinter &printer)
    2. {
    3. qint32 margin = 40 ;
    4.  
    5. QRect rct = printer.paperRect().adjusted(margin, margin, -margin, -margin) ;
    6. painter.drawRect(rct) ;
    7.  
    8. QTextOption toption ;
    9. toption.setTextDirection(Qt::RightToLeft) ;
    10.  
    11. QFont fontTitle("Arial", 36) ;
    12. fontTitle.setBold(true);
    13. painter.setFont(fontTitle);
    14. QString title = ui->leTitle->text().trimmed() ;
    15. toption.setAlignment(Qt::AlignTop|Qt::AlignHCenter);
    16. painter.drawText(rct.adjusted(0, 10, 0, 0), title, toption);
    17.  
    18. QFont fontText("Arial", 28) ;
    19. painter.setFont(fontText) ;
    20. QString text = ui->teText->toPlainText() ;
    21. toption.setAlignment(Qt::AlignLeft|Qt::AlignHCenter);
    22. painter.drawText(rct.adjusted(0, 10+painter.fontMetrics().height()*4, 0, 0), text, toption);
    23.  
    24. }
    25.  
    26. void Widget::on_pbPDF_clicked()
    27. {
    28. QString fileName = QFileDialog::getSaveFileName(this, QString(), QString(), QString("*.pdf(*.pdf)")) ;
    29. if(fileName.isEmpty())
    30. return ;
    31.  
    32. QPrinter printer ;
    33. printer.setOutputFormat(QPrinter::PdfFormat);
    34. printer.setOutputFileName(fileName);
    35.  
    36. QPainter painter(&printer) ;
    37.  
    38. printDocument(painter, printer) ;
    39.  
    40. painter.end() ;
    41.  
    42. QDesktopServices::openUrl(QUrl(fileName)) ;
    43.  
    44. }
    To copy to clipboard, switch view to plain text mode 

    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 .
    Attached Files Attached Files

  2. #2
    Join Date
    Dec 2012
    Posts
    197
    Thanks
    25
    Thanked 41 Times in 33 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default 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.

  3. #3
    Join Date
    Dec 2008
    Posts
    15
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Please help with Arabic text printing and PDF creation

    send the result pdf if you please

  4. #4
    Join Date
    Dec 2012
    Posts
    197
    Thanks
    25
    Thanked 41 Times in 33 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default 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.

    pdf-Result.jpg

    Good Luck.

  5. #5
    Join Date
    Dec 2008
    Posts
    15
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default 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.

  6. #6
    Join Date
    Dec 2012
    Posts
    197
    Thanks
    25
    Thanked 41 Times in 33 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default 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.

  7. #7
    Join Date
    Dec 2008
    Posts
    15
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default 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

  8. #8
    Join Date
    Dec 2008
    Posts
    15
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default 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

  9. #9
    Join Date
    Dec 2012
    Posts
    197
    Thanks
    25
    Thanked 41 Times in 33 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default 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.

Similar Threads

  1. Arabic text rendering; issues with parentheses
    By TropicalPenguin in forum Qt Programming
    Replies: 4
    Last Post: 10th September 2013, 10:53
  2. Printing to a plain text (txt) file from a report
    By luizofoca in forum Qt Programming
    Replies: 0
    Last Post: 10th June 2010, 20:02
  3. Replies: 1
    Last Post: 3rd September 2008, 15:16
  4. Text too big while printing after using SetWindow()
    By ibergmark in forum Qt Programming
    Replies: 2
    Last Post: 6th March 2008, 06:51
  5. Pixel Position and Printing text
    By nErnie in forum Qt Programming
    Replies: 1
    Last Post: 7th November 2006, 13:35

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.