title: QT html and CSS to pdf file
body: <p>I am using <code>QTextDocument</code> and using <code>setHtml</code> to add html. Then I used <code>QPrinter</code> to print in A4 pdf format <code>QPrinter::PdfFormat</code> but the printed pdf did not take the css style sheets. I also tried <code>QTextDocument::setDefaultHtml</code> and <code>setResource</code>.</p>
  
  <p>The code is as follows. How to get the CSS style in pdf format. 
  I use ubuntu and qmake for compiling.</p>
  
  <pre><code>const int highQualityDPI = 300;
  QDir::setCurrent(QCoreApplication::applicationDirPath());
  
  QFile  htmlFile ("myhtml.html");
  if (!htmlFile.open(QIODevice::ReadOnly | QIODevice::Text)){
      return -1;
  }
  
  QString htmlContent;
  QTextStream in(&amp;htmlFile);
  htmlContent=in.readAll();
  
  QFile  cssFile ("style.css");
  if (!cssFile.open(QIODevice::ReadOnly | QIODevice::Text)){
      return -1;
  }
  QString cssContent;
  QTextStream cssIn(&amp;cssFile);
  cssContent = cssIn.readAll();
  
  QTextDocument *document = new QTextDocument();
  document-&gt;addResource( QTextDocument::StyleSheetResource, QUrl( "style.css" ), cssContent );
  document-&gt;setHtml( htmlContent ); 
  
  QPrinter printer(QPrinter::HighResolution);
  printer.setPageSize(QPrinter::A4);
  printer.setOutputFormat(QPrinter::PdfFormat);
  
  printer.setOutputFileName("output.pdf");
  
  document-&gt;print(&amp;printer);
  delete document;
  return 0;
  </code></pre>