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

}

相关推荐
只有左边一个小酒窝1 小时前
(六)卷积神经网络:深度学习在计算机视觉中的应用
深度学习·计算机视觉·cnn
carpell2 小时前
【语义分割专栏】3:Segnet实战篇(附上完整可运行的代码pytorch)
人工智能·python·深度学习·计算机视觉·语义分割
栗克4 小时前
Halcon 图像预处理②
人工智能·计算机视觉·halcon
小Q小Q7 小时前
cmake编译LASzip和LAStools
人工智能·计算机视觉
不爱写代码的玉子14 小时前
HALCON透视矩阵
人工智能·深度学习·线性代数·算法·计算机视觉·矩阵·c#
sbc-study14 小时前
PCDF (Progressive Continuous Discrimination Filter)模块构建
人工智能·深度学习·计算机视觉
EasonZzzzzzz14 小时前
计算机视觉——相机标定
人工智能·数码相机·计算机视觉
春末的南方城市14 小时前
港科大&快手提出统一上下文视频编辑 UNIC,各种视频编辑任务一网打尽,还可进行多项任务组合!
人工智能·计算机视觉·stable diffusion·aigc·transformer
且慢.58917 小时前
Python_day47
python·深度学习·计算机视觉
Unpredictable22217 小时前
【VINS-Mono算法深度解析:边缘化策略、初始化与关键技术】
c++·笔记·算法·ubuntu·计算机视觉