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

}

相关推荐
格林威5 小时前
常规线扫描镜头有哪些类型?能做什么?
人工智能·深度学习·数码相机·算法·计算机视觉·视觉检测·工业镜头
B站计算机毕业设计之家6 小时前
智慧交通项目:Python+YOLOv8 实时交通标志系统 深度学习实战(TT100K+PySide6 源码+文档)✅
人工智能·python·深度学习·yolo·计算机视觉·智慧交通·交通标志
txwtech6 小时前
第6篇 OpenCV RotatedRect如何判断矩形的角度
人工智能·opencv·计算机视觉
a1111111111ss9 小时前
添加最新的LSKNet遥感目标检测网络主干
人工智能·目标检测·计算机视觉
edward111014 小时前
[C++]探索现代C++中的移动语义与完美转发从底层原理到高级应用
计算机视觉
CoovallyAIHub18 小时前
告别等待!十条高效PyTorch数据增强流水线,让你的GPU不再"饥饿"
深度学习·算法·计算机视觉
CoovallyAIHub19 小时前
量子计算迎来诺奖时刻!谷歌赢麻了
深度学习·算法·计算机视觉
AI视觉网奇20 小时前
开源3d数字人学习笔记2025
人工智能·计算机视觉
深瞳智检1 天前
YOLO算法原理详解系列 第002期-YOLOv2 算法原理详解
人工智能·算法·yolo·目标检测·计算机视觉·目标跟踪