Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. PDF output from QPrinter cuts last letter of words if the html characters are generated with cyrillic support

PDF output from QPrinter cuts last letter of words if the html characters are generated with cyrillic support

Scheduled Pinned Locked Moved Solved General and Desktop
19 Posts 2 Posters 5.1k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mardzo
    wrote on last edited by
    #1

    I am creating a software for Windows 10 with QT 5.7. So, basically I generate a QString named htmltable that i fill with html. I use the function for PDF printing:

        QPrinter printer;
    
        printer.setResolution(QPrinter::HighResolution);
    
        printer.setOutputFormat(QPrinter::PdfFormat);
    
        printer.setOutputFileName(fileName);
    
       // printer.setFullPage(true);
    
        printer.setOrientation(QPrinter::Portrait);
    
        printer.setPaperSize(QPrinter::A4);
    
        QSizeF size = printer.paperSize(QPrinter::Point);
    
        QTextDocument doc;
    
        doc.setHtml(htmltable);
    
        doc.setPageSize(size);
    
        doc.print(&printer);`
    

    The pages print fine if the characters in the words are latin. But if they are written with cyrillic support, the last character of some of the words is cut-off as seen on the picture bellow. This only happens if the font-size attribute is smaller for example 4pt. As you can see when the font is bigger there are no cut offs even on cyrillic characters.

    alt text

    Any suggestions?

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      How does it look on screen using a QTextDocument + QTextEdit ?

      M 1 Reply Last reply
      0
      • mrjjM mrjj

        How does it look on screen using a QTextDocument + QTextEdit ?

        M Offline
        M Offline
        mardzo
        wrote on last edited by
        #3

        @mrjj Do you mean like this?

           QTextEdit *edit = new QTextEdit(this);
        
            edit->setText(doc.toHtml());
            edit->resize(1500,1748);
        
            edit->show();
            edit->raise();
        

        In the QTextEdit the letters are fine in cyrillic. So the problem is in the printer ? :((

        1 Reply Last reply
        0
        • mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Hi
          Not sure yet. It could be the font when converted to "printer".
          Could you now print it via QTextEdit ?
          http://doc.qt.io/qt-5/qtextedit.html#print
          Just to see if it then blows or what happening.

          1 Reply Last reply
          0
          • M Offline
            M Offline
            mardzo
            wrote on last edited by mardzo
            #5

            @mrjj i try to print it like this:

            
                    QSizeF size = printer.paperSize(QPrinter::Point);
            
                    QTextDocument doc;
            
                    doc.setHtml(htmltable);
            
                    doc.setPageSize(size);
            
                    QTextEdit *edit = new QTextEdit(this);
            
                    edit->setText(doc.toHtml());
                    edit->resize(size.toSize());
            
                    edit->show();
                    edit->raise();
            
                   // doc.print(&printer);
            
            
                   edit->print(&printer);
            

            but i get like 200 blank pdf pages and i know i should only get one. I think i am not setting the size correctly for the qtextedit

            1 Reply Last reply
            0
            • mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by mrjj
              #6

              Ok, That's surprising as

              QSizeF size = printer.paperSize(QPrinter::Point);
              edit->resize(size);

              I thought it would get really huge ?
              Did u check the value for size?

              Maybe try
              QSizeF size = printer.paperSize(QPrinter::DevicePixel);
              edit->resize(size);
              And see what happens as it sounds like it TExtEdit got really small :)

              M 1 Reply Last reply
              0
              • mrjjM mrjj

                Ok, That's surprising as

                QSizeF size = printer.paperSize(QPrinter::Point);
                edit->resize(size);

                I thought it would get really huge ?
                Did u check the value for size?

                Maybe try
                QSizeF size = printer.paperSize(QPrinter::DevicePixel);
                edit->resize(size);
                And see what happens as it sounds like it TExtEdit got really small :)

                M Offline
                M Offline
                mardzo
                wrote on last edited by
                #7

                @mrjj I tried your code i got the same result. I remember experiencing this behaviour when i was using qtextdocument without setting the page size().

                mrjjM 1 Reply Last reply
                0
                • M mardzo

                  @mrjj I tried your code i got the same result. I remember experiencing this behaviour when i was using qtextdocument without setting the page size().

                  mrjjM Offline
                  mrjjM Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  @mardzo
                  Ah, that sounds like thats the issue and it then will "page break" in other places as
                  expected.
                  Im wondering if the HTML code contains anything
                  "fixed size"-ish that dont scale so well between screen and printer DPI.

                  M 1 Reply Last reply
                  0
                  • mrjjM mrjj

                    @mardzo
                    Ah, that sounds like thats the issue and it then will "page break" in other places as
                    expected.
                    Im wondering if the HTML code contains anything
                    "fixed size"-ish that dont scale so well between screen and printer DPI.

                    M Offline
                    M Offline
                    mardzo
                    wrote on last edited by mardzo
                    #9

                    @mrjj well the html table has a fixed width=440 and style = "margin-top:50px; margin-right:20px; " Im a bit new at QT and i dont understand how the latin letters are displayed correctly and cyrillic at the end of a word are the only one that are cut off

                    mrjjM 1 Reply Last reply
                    0
                    • M mardzo

                      @mrjj well the html table has a fixed width=440 and style = "margin-top:50px; margin-right:20px; " Im a bit new at QT and i dont understand how the latin letters are displayed correctly and cyrillic at the end of a word are the only one that are cut off

                      mrjjM Offline
                      mrjjM Offline
                      mrjj
                      Lifetime Qt Champion
                      wrote on last edited by
                      #10

                      @mardzo
                      Yes that is a bit odd. But cyrillic is another font, i assume?
                      So it could react differently being upscaled/created for the printer context.
                      A printer has many more DPI than the screen so some scaling is involved as else
                      it would just be ultra tiny. ( when printed)
                      Could also be a bug in the font handling so the actual size of the cyrillic is reported incorrectly.

                      Is it possivble to get the actual HTML that you print?
                      ( so I can try it)

                      M 1 Reply Last reply
                      0
                      • mrjjM mrjj

                        @mardzo
                        Yes that is a bit odd. But cyrillic is another font, i assume?
                        So it could react differently being upscaled/created for the printer context.
                        A printer has many more DPI than the screen so some scaling is involved as else
                        it would just be ultra tiny. ( when printed)
                        Could also be a bug in the font handling so the actual size of the cyrillic is reported incorrectly.

                        Is it possivble to get the actual HTML that you print?
                        ( so I can try it)

                        M Offline
                        M Offline
                        mardzo
                        wrote on last edited by mardzo
                        #11

                        @mrjj I create it dynamically so i cant send it all. I tried so save it all in a txt file, but the cyrilic characters are replaced with ??????. here is a small snippet with cyrilic characters in it. Im sorry for the bad formatting

                        <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">
                        <html>
                        <head>
                          <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
                          <meta name="qrichtext" content="1">
                           <title>QTextEdit Example</title>
                                <style type="text/css">p, li { white-space: pre-wrap; } </style>
                        </head>
                        <body style=" font-family:Tahoma; font-size:9pt; font-weight:300; font-style:normal;">
                        	<table align=center style = "margin-top:50px;  margin-right:20px; ">
                          		<tr><th><h2>Извештај за настани од контрола на пристап</h2></th>	    </tr> 
                             </table>
                        	<table align=center style='margin-top:10px;  margin-right:20px; '>
                           		<tr>
                                	<td>Филтер:</td>
                                    <td>Сите логови</td>
                                    <td>Од:</td>
                                    <td>28.11.2016</td>                          
                                    <td>До:</td> 				
                                    <td>28.11.2016</td>
                                </tr>
                           </table>"
                           <table style = 'text-align: left; padding: 1px; background-color: #fff; font-size:6pt;'
                                              border=2  align=center cellspacing=1 width=440 > 
                           		<tr> 
                                	<th>Бр.</th> 
                                	<th>Уред</th> 
                               		 <th>Лог</th> 
                                	 <th>Врата</th> 
                                	 <th>Корисник</th> 
                                     <th>Датум и Време</th> 
                                </tr>
                            </table>
                        </body>
                        </html>
                        1 Reply Last reply
                        0
                        • mrjjM Offline
                          mrjjM Offline
                          mrjj
                          Lifetime Qt Champion
                          wrote on last edited by
                          #12

                          Hi
                          Super.
                          I get this
                          alt text

                          Is that ok test case?

                          M 1 Reply Last reply
                          0
                          • mrjjM mrjj

                            Hi
                            Super.
                            I get this
                            alt text

                            Is that ok test case?

                            M Offline
                            M Offline
                            mardzo
                            wrote on last edited by mardzo
                            #13

                            @mrjj yes, this is okay but what happens when you try to set style="font-size : 6pt;" on the table and export it as pdf? Does it cut the last letter of the cyrillic words? I edited the previously posted html

                            1 Reply Last reply
                            0
                            • mrjjM Offline
                              mrjjM Offline
                              mrjj
                              Lifetime Qt Champion
                              wrote on last edited by
                              #14

                              Hi
                              Super.
                              style="font-size : 6pt;"
                              As set stylesheet on it or?

                              I will retry with the new html.

                              M 1 Reply Last reply
                              0
                              • mrjjM mrjj

                                Hi
                                Super.
                                style="font-size : 6pt;"
                                As set stylesheet on it or?

                                I will retry with the new html.

                                M Offline
                                M Offline
                                mardzo
                                wrote on last edited by
                                #15

                                @mrjj yes, try with the exact new html i posted

                                mrjjM 1 Reply Last reply
                                0
                                • M mardzo

                                  @mrjj yes, try with the exact new html i posted

                                  mrjjM Offline
                                  mrjjM Offline
                                  mrjj
                                  Lifetime Qt Champion
                                  wrote on last edited by
                                  #16

                                  @mardzo
                                  Hmm seems to be 1-1 one
                                  alt text

                                  Can we try reverse and see if u get same?
                                  https://www.dropbox.com/s/kxu7drheoulah3p/myTextEdit.zip?dl=0

                                  M 1 Reply Last reply
                                  1
                                  • mrjjM mrjj

                                    @mardzo
                                    Hmm seems to be 1-1 one
                                    alt text

                                    Can we try reverse and see if u get same?
                                    https://www.dropbox.com/s/kxu7drheoulah3p/myTextEdit.zip?dl=0

                                    M Offline
                                    M Offline
                                    mardzo
                                    wrote on last edited by
                                    #17

                                    @mrjj yes your project works fine i have tried it and got a good pdf :). But did u notice that when u input the html in the qtextedit in the ui it alters the html adding spans. paragrarphs etc.? Do u suggest for me to change my html table based on the changes the QT Designer made to it?

                                    1 Reply Last reply
                                    0
                                    • M Offline
                                      M Offline
                                      mardzo
                                      wrote on last edited by
                                      #18

                                      Bloody hell! I figured it out. The only thing i needed to do was to put <span></span> inside the table cells. Thanks @mrjj for your help.

                                      mrjjM 1 Reply Last reply
                                      2
                                      • M mardzo

                                        Bloody hell! I figured it out. The only thing i needed to do was to put <span></span> inside the table cells. Thanks @mrjj for your help.

                                        mrjjM Offline
                                        mrjjM Offline
                                        mrjj
                                        Lifetime Qt Champion
                                        wrote on last edited by
                                        #19

                                        @mardzo
                                        Super. Good work. Well i was wondering what the difference was between screen
                                        and pdf and you found it :)

                                        1 Reply Last reply
                                        0

                                        • Login

                                        • Login or register to search.
                                        • First post
                                          Last post
                                        0
                                        • Categories
                                        • Recent
                                        • Tags
                                        • Popular
                                        • Users
                                        • Groups
                                        • Search
                                        • Get Qt Extensions
                                        • Unsolved