Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt Creator and other tools
  4. QTextDocument is faster do show big html file as Chrome Browser
QtWS25 Last Chance

QTextDocument is faster do show big html file as Chrome Browser

Scheduled Pinned Locked Moved Unsolved Qt Creator and other tools
pdfpdfiumqabstractscroll
1 Posts 1 Posters 828 Views
  • 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.
  • P Offline
    P Offline
    patrik08
    wrote on last edited by
    #1

    I am excited by the new qt5, I remember that 9 years ago QTextDocument had other behaviors ..
    Maybe the pictures I do not know

    A pdf of 1MB (libre office use) converted into html to a readable quality reaches 60MB as html in the attached code ...
    QTextDocument draws all 20 pages in 35sec.
    Chrome Browser after 2 minutes says it does not respond ...

    If I show images from QPdfium, the time are much longer ... can anyone explain it?
    here waht i run ...

    
    
    
    /// same game to odt format image if load faster
    static inline QByteArray html_image(QImage x, const QSize area) {
      if (x.isNull()) {
        return QByteArray();
      }
      QByteArray ba;
      QBuffer bu(&ba);
      //bu.open(QBuffer::ReadWrite);
      bu.open(QIODevice::WriteOnly);
      x.save(&bu,"JPG",5);
      bu.close();
      QString head0 =  QString("<img style='max-width:90vw' src='data:image/png;base64,");
      QString head1 = QString("\'  width=\'");
      head1 += QString::number(area.width());
      head1 += QString("\' height=\'");
      head1 += QString::number(area.height());
      head1 += QString("' />");
      head0.replace(QChar(39), QChar(34));
      head1.replace(QChar(39), QChar(34));
      QByteArray endchunk = ba.toBase64(); ///  tra_chunk.toBase64();
      x.~QImage();
      //// qDebug() << __FUNCTION__ << "- size-> " << endchunk.size();
      endchunk.prepend(head0.toLatin1());
      endchunk.append(head1.toLatin1());
       //// qDebug() << __FUNCTION__ << "- " << endchunk;
      return endchunk;
    }
    
    /* MM_TO_POINT  A4  210 mm × 297 mm some work to QTextDocument */
    static inline QByteArray html_pdf_file(const QString file) {  //// pdf file ...
      const qreal pixelscreenscale = 2;
       QSize _A4( MM_TO_POINT(210) / pixelscreenscale , MM_TO_POINT(297) / pixelscreenscale  ); /// screen .. to print get full...
       QByteArray body,tmp,line;
       body += QByteArray("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\"> ");
       body += QByteArray("<html><head><meta name=\"qrichtext\" content=\"1\" /><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />" );
       body += QByteArray("</head><body>" );
    
    #ifdef LOADPDFIUMYES
      qreal scale = MM_TO_POINT(210) / _A4.width(); /// must give pixelscreenscale!!!
      QPdfium *m_pdf = new QPdfium();
      m_pdf->loadFile(file);
      if (!m_pdf->isValid()) {
          return QByteArray();
      }
      const int pagex = m_pdf->pageCount();
      if (pagex > 0) {
          int dd=-1;
          do {
             dd++;
             //// qDebug() << __FUNCTION__ << " - " << scale << "- page  " << dd;
             QPdfiumPage page = m_pdf->page(dd);
             QImage image = page.image(scale);
             if (image.isNull()) {
               return QByteArray();
             }
             QByteArray img64 = html_image(image,_A4);  /// .toLatin1();
             image.~QImage();
             line += QByteArray("<p align=\"center\" style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">  ");
             line += img64;
             line += QByteArray("</p>");
             body.append(line);
          } while( dd < (pagex -1) );
      }
    #endif
      QByteArray footer = QByteArray("</body></html>");
      body.append(footer);
      return body;
    }
    
    
    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