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);
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);
pdfPainter.setPen(Qt::black);
pdfPainter.scale(10,10);
QString html
= "<table border = 1><tr><td>name</td><td>surname</td><td>age</td></tr></table>";
doc.setDefaultStyleSheet("table {border: 1px solid black}");
doc.setHtml(html);
doc.drawContents(&pdfPainter);
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);
pdfPainter.setPen(Qt::black);
pdfPainter.scale(10,10);
QString html = "<table border = 1><tr><td>name</td><td>surname</td><td>age</td></tr></table>";
doc.setDefaultStyleSheet("table {border: 1px solid black}");
doc.setHtml(html);
doc.drawContents(&pdfPainter);
To copy to clipboard, switch view to plain text mode
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.
Bookmarks