添加表格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."));

}

相关推荐
叶子爱分享3 小时前
计算机视觉与图像处理的关系
图像处理·人工智能·计算机视觉
cver1233 小时前
野生动物检测数据集介绍-5,138张图片 野生动物保护监测 智能狩猎相机系统 生态研究与调查
人工智能·pytorch·深度学习·目标检测·计算机视觉·目标跟踪
kyle~5 小时前
目标检测在国防和政府的应用实例
人工智能·目标检测·计算机视觉
Akttt6 小时前
【T2I】R&B: REGION AND BOUNDARY AWARE ZERO-SHOT GROUNDED TEXT-TO-IMAGE GENERATION
人工智能·深度学习·计算机视觉·text2img
jndingxin7 小时前
OpenCV CUDA模块设备层-----反向二值化阈值处理函数thresh_binary_inv_func()
人工智能·opencv·计算机视觉
jndingxin8 小时前
OpenCV CUDA模块设备层-----在 GPU 上执行类似于 std::copy 的操作函数warpCopy()
人工智能·opencv·计算机视觉
jndingxin8 小时前
OpenCV CUDA模块设备层-----在GPU 上高效地执行两个 uint 类型值的最大值比较函数vmax2()
人工智能·opencv·计算机视觉
顾道长生'10 小时前
(Arxiv-2024)自回归模型优于扩散:Llama用于可扩展的图像生成
计算机视觉·数据挖掘·llama·自回归模型·多模态生成与理解
千宇宙航10 小时前
闲庭信步使用SV搭建图像测试平台:第二十七课——图像的腐蚀
图像处理·计算机视觉·fpga开发
CoovallyAIHub11 小时前
YOLOv13都来了,目标检测还卷得动吗?别急,还有这些新方向!
深度学习·算法·计算机视觉