QT HTML to pdf width error
-
I am working on converting HTML to .pdf via QT.
The code I created is as follows.
However, when I look at the generated pdf result, the table is shifted to one side (left picture).
How can I make it appear as width: 100% like the Viewer supported by the web (W3Schools) (right picture)?QString strHtml = R"( <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Test Hospital DR Report</title> <style> table { width: 100%; } </style> </head> <body> <table style="width:100%"> <tr> <td>A: </td> <td>B: </td> </tr> <tr> <td>C: </td> <td>D: </td> <td>E: </td> </tr> <tr> <td>F: </td> <td>G: </td> <td>H: </td> </tr> <tr> <td>I: </td> <td></td> <td></td> </tr> </table> </body> </html> )"; QTextDocument doc; doc.setHtml(strHtml); // Print HTML content QPrinter printer; printer.setPrinterName(QPrinterInfo::defaultPrinter().printerName()); if (printer.isValid()) { doc.print(&printer); qDebug() << "[" << __FUNCTION__ << "] Printed successfully..."; } else { qDebug() << "[" << __FUNCTION__ << "] Failed to print..."; }
-
I am working on converting HTML to .pdf via QT.
The code I created is as follows.
However, when I look at the generated pdf result, the table is shifted to one side (left picture).
How can I make it appear as width: 100% like the Viewer supported by the web (W3Schools) (right picture)?QString strHtml = R"( <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Test Hospital DR Report</title> <style> table { width: 100%; } </style> </head> <body> <table style="width:100%"> <tr> <td>A: </td> <td>B: </td> </tr> <tr> <td>C: </td> <td>D: </td> <td>E: </td> </tr> <tr> <td>F: </td> <td>G: </td> <td>H: </td> </tr> <tr> <td>I: </td> <td></td> <td></td> </tr> </table> </body> </html> )"; QTextDocument doc; doc.setHtml(strHtml); // Print HTML content QPrinter printer; printer.setPrinterName(QPrinterInfo::defaultPrinter().printerName()); if (printer.isValid()) { doc.print(&printer); qDebug() << "[" << __FUNCTION__ << "] Printed successfully..."; } else { qDebug() << "[" << __FUNCTION__ << "] Failed to print..."; }