using Spire.Pdf; using Spire.Pdf.Graphics; using Spire.Pdf.Grid;
PdfDocument doc = new PdfDocument(); PdfPageBase page = doc.Pages.Add();
PdfGrid grid = new PdfGrid(); PdfGridRow row = grid.Rows.Add(); grid.Columns.Add(2);
grid.Style.CellPadding = new PdfPaddings(1, 1, 1, 1);
float width = page.Canvas.ClientSize.Width - (grid.Columns.Count + 1); grid.Columns[0].Width = width * 0.1f; grid.Columns[1].Width = width * 0.1f;
PdfGridCellTextAndStyleList lst = new PdfGridCellTextAndStyleList(); PdfGridCellTextAndStyle textAndStyle = new PdfGridCellTextAndStyle(); textAndStyle.Image=PdfImage.FromFile(@"C:\Users\Administrator\Pictures\448a5ba8f8851709a1f53e.jpg");
textAndStyle.ImageSize = new SizeF(50, 50); lst.List.Add(textAndStyle); row.Cells[0].Value = lst;
PdfLayoutResult result = grid.Draw(page, new PointF(10, 30));
doc.SaveToFile(outputFile, FileFormat.PDF); System.Diagnostics.Process.Start(outputFile);
using System;
using System.Drawing;
using System.Windows.Forms;
using Spire.Pdf;
using Spire.Pdf.Graphics;
using Spire.Pdf.Grid;
namespace Insert_an_Image_to_PDF_Grid_Cell
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
string outputFile ="output.pdf";
//新建一个PDF文档
PdfDocument doc = new PdfDocument();
//添加页面
PdfPageBase page = doc.Pages.Add();
//创建PDF网格
PdfGrid grid = new PdfGrid();
//设置单元格边框与填充内容的间距
grid.Style.CellPadding = new PdfPaddings(1, 1, 1, 1);
//添加行
PdfGridRow row = grid.Rows.Add();
//添加列
grid.Columns.Add(2);
float width = page.Canvas.ClientSize.Width - (grid.Columns.Count + 1);
//设置列宽
grid.Columns[0].Width = width * 0.1f;
grid.Columns[1].Width = width * 0.1f;
//加载图片
PdfGridCellTextAndStyleList lst = new PdfGridCellTextAndStyleList();
PdfGridCellTextAndStyle textAndStyle = new PdfGridCellTextAndStyle();
textAndStyle.Image=PdfImage.FromFile (@"C:\Users\Administrator\Pictures\448a5ba8f8851709a1f53e.jpg");
//设置图片大小
textAndStyle.ImageSize = new SizeF(50, 50);
lst.List.Add(textAndStyle);
//在第一个单元格添加图片
row.Cells[0].Value = lst;
//在页面特定位置绘制PDF网格
PdfLayoutResult result = grid.Draw(page, new PointF(10, 30));
//保存并运行PDF文件
doc.SaveToFile(outputFile, FileFormat.PDF);
System.Diagnostics.Process.Start(outputFile);
}
}
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有