Results 1 to 9 of 9

Thread: Please help with Arabic text printing and PDF creation

Threaded View

Previous Post Previous Post   Next Post Next Post
  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

Similar Threads

  1. Arabic text rendering; issues with parentheses
    By TropicalPenguin in forum Qt Programming
    Replies: 4
    Last Post: 10th September 2013, 09: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, 19:02
  3. Replies: 1
    Last Post: 3rd September 2008, 14:16
  4. Text too big while printing after using SetWindow()
    By ibergmark in forum Qt Programming
    Replies: 2
    Last Post: 6th March 2008, 05:51
  5. Pixel Position and Printing text
    By nErnie in forum Qt Programming
    Replies: 1
    Last Post: 7th November 2006, 12: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.