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

}

相关推荐
sali-tec10 小时前
C# 基于OpenCv的视觉工作流-章66-直线夹角
图像处理·人工智能·opencv·算法·计算机视觉
AGV算法笔记13 小时前
目标检测论文精读:Deformable DETR 为什么被认为是 DETR 真正走向实用的关键一步?
人工智能·深度学习·目标检测·机器学习·计算机视觉·目标跟踪
sali-tec20 小时前
C# 基于OpenCv的视觉工作流-章67-线线间距
图像处理·人工智能·opencv·算法·计算机视觉
__Wedream__20 小时前
NTIRE 2026遥感红外超分第五名方案解读:不训复杂模型,只调少量参数——Mona适配器如何高效迁移HAT?
深度学习·计算机视觉·超分辨率重建·basicsr·nitre
hixiong1231 天前
C# TensorRT部署RF-DETR目标检测&分割模型
人工智能·目标检测·计算机视觉·ai·c#
sali-tec1 天前
C# 基于OpenCv的视觉工作流-章63-点廓距离
图像处理·人工智能·opencv·计算机视觉
sali-tec2 天前
C# 基于OpenCv的视觉工作流-章61-点线距离
图像处理·人工智能·opencv·计算机视觉
AI棒棒牛2 天前
YOLOv13最新创新改进系列:YOLOv13特征可视化,特征提取图,科技感满满,丰富实验神器!!!
人工智能·科技·yolo·目标检测·计算机视觉