View Full Version : How to get a solid border line when using QTextDocument's setHtml for a PDF file?

22nd May 2019, 21:33
QTextDocument allows one to create a page using HTML and output the results to a PDF file. The HTML that is allowed is listed at https://doc.qt.io/qt-5/richtext-html-subset.html. This web page states in the CSS Properties section that "border-style" is allowed, but I cannot get it to work. I want to have a solid line, but keep getting the default of ridge. Below is my code:

QString pdfFilePath = pdfFile; // Get the file path from the user
QPdfWriter pdf_file(pdfFilePath);
QTextDocument doc;

pdf_file.setPageSize(QPageSize(QPageSize::Letter)) ;
pdf_file.setPageMargins(QMarginsF(0.75, 0.25, 0.75, 0.25),QPageLayout::Inch);
pdf_file.setPageOrientation(QPageLayout::Portrait) ;

QPainter pdfPainter(&pdf_file);

QString html = "<table border = 1><tr><td>name</td><td>surname</td><td>age</td></tr></table>";
doc.setDefaultStyleSheet("table {border: 1px solid black}");

If one plugs in a value for pdfFile (first line), you should be able to run the code.
Thank you for looking at this problem. I look forward to hearing from you.