博客园  :: 首页  :: 联系 :: 管理

Spire.Doc 生成长图

Posted on 2020-10-21 13:22  天戈朱  阅读(285)  评论(0编辑  收藏  举报

按模板生成内容,转换成长图保存:

 

Document doc = new Document("A_BizRpt.docx");

.......

Image[] imgs = doc.SaveToImages(ImageType.Metafile);

var finalHeight = imgs.Sum(img => img.Height);
var finalWidth = imgs.Max(img => img.Width);
var finalImg = new Bitmap(finalWidth, finalHeight);
Graphics g = Graphics.FromImage(finalImg);
g.Clear(SystemColors.AppWorkspace);

var height = 0;
foreach (Image img in imgs)
{
     g.DrawImage(img, new Point(0, height));
     height += img.Height;

     img.Dispose();
}
g.Dispose();
finalImg.Save("1.png", System.Drawing.Imaging.ImageFormat.Png);
finalImg.Dispose();