添加表格MFC PDF

void AddTable(HPDF_Doc pdf, HPDF_Page page)

{

HPDF_Font font = HPDF_GetFont(pdf, "Helvetica", NULL);

if (!font)

{

AfxMessageBox(_T("Error: Cannot get Font."));

return;

}

HPDF_Page_SetFontAndSize(page, font, 12);

HPDF_REAL rowHeight = 20;

HPDF_REAL colWidth = 100;

HPDF_REAL x = 50;

HPDF_REAL y = 500;

int numRows = 5;

int numCols = 3;

for (int i = 0; i <= numRows; i++)

{

HPDF_Page_MoveTo(page, x, y - i * rowHeight);

HPDF_Page_LineTo(page, x + numCols * colWidth, y - i * rowHeight);

HPDF_Page_Stroke(page);

}

for (int i = 0; i <= numCols; i++)

{

HPDF_Page_MoveTo(page, x + i * colWidth, y);

HPDF_Page_LineTo(page, x + i * colWidth, y - numRows * rowHeight);

HPDF_Page_Stroke(page);

}

for (int i = 0; i < numRows; i++)

{

for (int j = 0; j < numCols; j++)

{

CString text;

text.Format(_T("Cell %d,%d"), i + 1, j + 1);

HPDF_Page_BeginText(page);

HPDF_Page_MoveTextPos(page, x + j * colWidth + 5, y - (i + 1) * rowHeight + 5);

HPDF_Page_ShowText(page, CStringA(text));

HPDF_Page_EndText(page);

}

}

}

void CMainViewWnd::ExportToPDF(const CString& filePath)

{

HPDF_Doc pdf = HPDF_New(NULL, NULL);

if (!pdf)

{

AfxMessageBox(_T("Error: Cannot create PdfDoc object."));

return;

}

if (HPDF_SetCompressionMode(pdf, HPDF_COMP_ALL) != HPDF_OK)

{

AfxMessageBox(_T("Error: Cannot set compression mode."));

HPDF_Free(pdf);

return;

}

HPDF_Page page = HPDF_AddPage(pdf);

if (!page)

{

AfxMessageBox(_T("Error: Cannot create PdfPage object."));

HPDF_Free(pdf);

return;

}

AddTable(pdf, page);

if (HPDF_SaveToFile(pdf, CStringA(filePath)) != HPDF_OK)

{

AfxMessageBox(_T("Error: Cannot save to file."));

HPDF_Free(pdf);

return;

}

HPDF_Free(pdf);

AfxMessageBox(_T("Exported to PDF successfully."));

}

相关推荐
ComputerInBook6 小时前
数字图像处理(4版)——第 3 章——(图像的)强度变换和空间滤波(Rafael C.Gonzalez&Richard E. Woods)
图像处理·人工智能·计算机视觉·强度变换和空间滤波
泰恒10 小时前
国内外大模型的区别与差距
人工智能·深度学习·yolo·机器学习·计算机视觉
加勒比海带6611 小时前
目标检测算法——低空智能实验室开放数据集汇总附下载链接【点赞+收藏】
大数据·图像处理·人工智能·python·深度学习·目标检测·计算机视觉
犽戾武13 小时前
YOLOv8 目标检测模型训练与 RK3588 NPU 部署全记录
人工智能·计算机视觉·目标跟踪
挂科边缘17 小时前
【PASCAL VOC 数据集介绍篇】目标检测与分割常用的数据集:PASCAL VOC 数据集全版本详解与避坑指南
人工智能·目标检测·计算机视觉
Coovally AI模型快速验证17 小时前
清华+上交+国网团队:数据-模型-推理三层协同设计做高分辨率UAV绝缘子缺陷检测,mAP达92.9%
人工智能·计算机视觉·无人机巡检·电力巡检
quetalangtaosha18 小时前
Anomaly Detection系列(CVPR2025 EG-MPC论文解读)
人工智能·深度学习·计算机视觉
深度学习lover18 小时前
<数据集>yolo 船舶识别<目标检测>
人工智能·python·yolo·目标检测·计算机视觉·船舶分类识别
深圳市快瞳科技有限公司19 小时前
端侧喂鸟器上的轻量化鸟类识别:从模型选型到低功耗部署实战
计算机视觉·neo4j
m0_7431064620 小时前
【3D硬核】四元数(Quaternions)与旋转矩阵(Rotation)——三维空间中的旋转
人工智能·计算机视觉·3d·矩阵·几何学