{
public:
~pdfReport();
void MakePDFReport(QString filePath);
private:
#define DPI_RESOLUTION 300 //DPI中的PDF分辨率
#define TOTAL_WIDTH 2481 //A4纸
#define TOTAL_HEIGHT 3507 //A4纸
#define PAGE_MARGIN 20 //页边距值
#define PAGE_MARGIN_PIXELS (int)((float)PAGE_MARGIN/72*DPI_RESOLUTION)
#define PAGE_WIDTH (TOTAL_WIDTH-PAGE_MARGIN_PIXELS*2)
#define PAGE_HEIGHT (TOTAL_HEIGHT-PAGE_MARGIN_PIXELS*2)
QPdfWriter *pdfWriter;
QTextOption option;
QPainter *pdfPainter;
QFont font;
QFile pdfFile;
TestResult_t testResult;
QString picturePath = “…/picture/”;
private:
#define realWidthPixels(Value) (int)((float)Value/72*DPI_RESOLUTION)
#define realHeightPixels(Value) (int)((float)Value/72*TOTAL_HEIGHT)
void PDFReportInit(QString filePath,int currentPage, int totalPage);
void InitNewPage(int currentPage, int totalPage);
};
2.report.cpp文件
void pdfReport::PDFReportInit(QString filePath,int currentPage, int totalPage)
{
//创建要写入的pdf文件
QDateTime currentTime = QDateTime::currentDateTime();
QString timeString = currentTime.toString(“yyyy_MM_dd-hh_mm_ss”);
QString fileName = filePath + “\” + timeString + “Report.pdf”;
pdfFile.setFileName(fileName);
pdfFile.open(QIODevice::ReadWrite);
pdfWriter = new QPdfWriter(&pdfFile);
//设置pdf文件属性
pdfWriter->setPageSize