zoukankan      html  css  js  c++  java
  • C#将PDF转换为图片的方法

    1.需要添加引用  O2S.Components.PDFRender4NET

    链接: https://pan.baidu.com/s/1ZPTaLTnFkex6QrsndLjwxg 提取码: jdh2 复制这段内容后打开百度网盘手机App,操作更方便哦

    实例代码:

    /// <summary>
    /// 将PDF转换为图片的方法
    /// </summary>
    /// <param name="pdfInputPath">PDF文件路径</param>
    /// <param name="imageOutputPath">图片输出路径</param>
    /// <param name="imageName">生成图片的名字</param>
    /// <param name="startPageNum">从PDF文档的第几页开始转换</param>
    /// <param name="endPageNum">从PDF文档的第几页开始停止转换</param>
    /// <param name="imageFormat">设置所需图片格式</param>
    /// <param name="definition">设置图片的清晰度,数字越大越清晰</param>
    public static void PdfToPng(string pdfInputPath, string imageOutputPath,
    string imageName, int startPageNum, int endPageNum, ImageFormat imageFormat, Definition definition)
    {
    PDFFile pdfFile = PDFFile.Open(pdfInputPath);
    if (!Directory.Exists(imageOutputPath))
    {
    Directory.CreateDirectory(imageOutputPath);
    }
    // validate pageNum
    if (startPageNum <= 0)
    {
    startPageNum = 1;
    }
    if (endPageNum > pdfFile.PageCount)
    {
    endPageNum = pdfFile.PageCount;
    }
    if (startPageNum > endPageNum)
    {
    int tempPageNum = startPageNum;
    startPageNum = endPageNum;
    endPageNum = startPageNum;
    }
    // start to convert each page
    if(endPageNum == 1)
    {
    Bitmap pageImage = pdfFile.GetPageImage(1 - 1, 56 * (int)definition);
    pageImage.Save(imageOutputPath + imageName + "." + imageFormat.ToString(), imageFormat);
    pageImage.Dispose();
    }
    else
    {
    for (int i = startPageNum; i <= endPageNum; i++)
    {
    Bitmap pageImage = pdfFile.GetPageImage(i - 1, 56 * (int)definition);
    pageImage.Save(imageOutputPath + imageName + i.ToString() + "." + imageFormat.ToString(), imageFormat);
    pageImage.Dispose();
    }
    }
    pdfFile.Dispose();
    }

  • 相关阅读:
    update 更改字段
    查看 links
    oracle 统计字段空值数
    查看oracle 数据库编码个格式
    oracle 数据库DBA权限
    一文弄懂 Golang 排序
    Golang Linux、Windows、Mac 下交叉编译
    go 简单封装数学运算包
    [Vue warn]: Unknown custom element: did you register the component correctly?
    深度图怎么看行情走势
  • 原文地址:https://www.cnblogs.com/xiewei123/p/10902578.html
Copyright © 2011-2022 走看看