WX辣乎JY 2017-02-13 13:15 采纳率: 0%
浏览 3389

aspose.pdf 怎么只能转4页PDF?求指点

 /// <summary>
        /// 将pdf文档转换为图片的方法(该方法基于第三方DLL),你可以像这样调用该方法:
        /// ConvertPDF2Image("F:\\PdfFile.doc", "F:\\", "ImageFile", 1, 20, ImageFormat.Png, 256);
        /// </summary>
        /// <param name="pdfInputPath">Word文件路径</param>
        /// <param name="imageOutputPath">图片输出路径,如果为空,默认值为Word所在路径</param>
        /// <param name="imageName">图片的名字,不需要带扩展名,如果为空,默认值为Word的名称</param>
        /// <param name="startPageNum">从PDF文档的第几页开始转换,如果为0,默认值为1</param>
        /// <param name="endPageNum">从PDF文档的第几页开始停止转换,如果为0,默认值为Word总页数</param>
        /// <param name="imageFormat">设置所需图片格式,如果为null,默认格式为PNG</param>
        /// <param name="resolution">设置图片的像素,数字越大越清晰,如果为0,默认值为128,建议最大值不要超过1024</param>
        public static void ConvertPdfToImage(string wordInputPath, string imageOutputPath,
            string imageName, int startPageNum, int endPageNum, ImageFormat imageFormat, int resolution)
        {
            try
            {
                // open word file

                Aspose.Pdf.Document doc = new Aspose.Pdf.Document(wordInputPath);

                // validate parameter
                if (doc == null) { throw new Exception("Pdf文件无效或者Pdf文件被加密!"); }
                if (imageOutputPath.Trim().Length == 0) { imageOutputPath = Path.GetDirectoryName(wordInputPath); }
                if (!Directory.Exists(imageOutputPath)) { Directory.CreateDirectory(imageOutputPath); }
                if (imageName.Trim().Length == 0) { imageName = Path.GetFileNameWithoutExtension(wordInputPath); }
                if (startPageNum <= 0) { startPageNum = 1; }
                if (endPageNum > doc.Pages.Count || endPageNum <= 0) { endPageNum = doc.Pages.Count; }
                if (startPageNum > endPageNum) { int tempPageNum = startPageNum; startPageNum = endPageNum; endPageNum = startPageNum; }
                if (imageFormat == null) { imageFormat = ImageFormat.Png; }
                if (resolution <= 0) { resolution = 128; }

                //PdfSaveOptions pdfSaveOptions = new PdfSaveOptions();
                //pdfSaveOptions.SaveFormat= GetSaveFormat(imageFormat);

                ImageSaveOptions imageSaveOptions = new ImageSaveOptions(GetSaveFormat(imageFormat));

                imageSaveOptions.Resolution = resolution;

                // start to convert each page
                for (int i = startPageNum; i <= endPageNum; i++)
                {
                    imageSaveOptions.PageIndex = i - 1;

                    MemoryStream stream = new MemoryStream();
                    Aspose.Pdf.SaveOptions pdfSaveOptions = new Aspose.Pdf.PdfSaveOptions();
                    //Aspose.Pdf.Devices.Resolution reso = new Aspose.Pdf.Devices.Resolution(resolution);
                    Aspose.Pdf.Devices.PngDevice pngDevice = new Aspose.Pdf.Devices.PngDevice(990, 1400);

                    string strNumber;
                    if (i < 10)
                    {
                        strNumber = "0" + i.ToString();
                    }
                    else
                    {
                        strNumber = i.ToString();
                    }
                    pngDevice.Process(doc.Pages[i], Path.Combine(imageOutputPath, imageName) + "_" + strNumber + "." + imageFormat.ToString());
                    stream.Dispose();
                    //doc.Save(Path.Combine(imageOutputPath, imageName) + "_" + strNumber + "." + imageFormat.ToString(), pdfSaveOptions);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

Aspose.Pdf.Document doc = new Aspose.Pdf.Document(wordInputPath);调试的时候,发现刚进来到这里,doc.page.count是pdf的页数没毛病,但是doc.pages就只有4页。想不通。。其他代码都还没执行,第一行就这样,这是因为我的aspose是免费版的缘故吗?如果不是那可能是什么原因呢?刚刚接触Aspose和.net,所以来问问,大神help~~~

  • 写回答

5条回答 默认 最新

  • WX辣乎JY 2017-02-14 00:41
    关注

    得到PDF的路径之后,根据PDF转换为图片时只能转换4页的内容

    评论

报告相同问题?

悬赏问题

  • ¥35 平滑拟合曲线该如何生成
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 自己瞎改改,结果现在又运行不了了
  • ¥15 链式存储应该如何解决
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站