Exemple #1
0
        public bool ConvertToImage(string outputFile, int pageNumber)
        {
            try
            {
                try
                {
                    ImageType bINARY = null;
                    switch (this.OutputImageColor)
                    {
                    case PDF2Image.PDF2ImageColor.BINARY:
                    {
                        bINARY = ImageType.BINARY;
                        break;
                    }

                    case PDF2Image.PDF2ImageColor.GRAY:
                    {
                        bINARY = ImageType.GRAY;
                        break;
                    }

                    case PDF2Image.PDF2ImageColor.RGB:
                    {
                        bINARY = ImageType.RGB;
                        break;
                    }

                    case PDF2Image.PDF2ImageColor.ARGB:
                    {
                        bINARY = ImageType.ARGB;
                        break;
                    }
                    }
                    PDFHelper.CheckOutputFolder(PDF2Image.TempPath);
                    bool flag = true;
                    this.startPage = Math.Max(this.startPage, 1);
                    if (this.endPage < 0)
                    {
                        this.endPage = this.pdfDocument.getNumberOfPages();
                    }
                    this.endPage = Math.Min(this.endPage, this.pdfDocument.getNumberOfPages());
                    PDFRenderer   pDFRenderer   = new PDFRenderer(this.pdfDocument);
                    BufferedImage bufferedImage = null;
                    bufferedImage = (bINARY != null ? pDFRenderer.renderImageWithDPI(pageNumber - 1, (float)this.dpi, bINARY) : pDFRenderer.renderImageWithDPI(pageNumber - 1, (float)this.dpi));
                    flag          = flag & ImageIOUtil.writeImage(bufferedImage, outputFile, this.dpi);
                }
                catch (Exception exception1)
                {
                    Exception exception = exception1;
                    throw new PDFToolkitException(exception.Message, exception);
                }
            }
            finally
            {
                PDFHelper.EmptyDirectory(PDF2Image.TempPath);
            }
            return(true);
        }
Exemple #2
0
        public bool ConvertToMultipageTiffImage(string outputFile)
        {
            try
            {
                try
                {
                    if (!Directory.Exists(PDF2Image.TempPath))
                    {
                        Directory.CreateDirectory(PDF2Image.TempPath);
                    }
                    ImageType bINARY = null;
                    switch (this.OutputImageColor)
                    {
                    case PDF2Image.PDF2ImageColor.BINARY:
                    {
                        bINARY = ImageType.BINARY;
                        break;
                    }

                    case PDF2Image.PDF2ImageColor.GRAY:
                    {
                        bINARY = ImageType.GRAY;
                        break;
                    }

                    case PDF2Image.PDF2ImageColor.RGB:
                    {
                        bINARY = ImageType.RGB;
                        break;
                    }

                    case PDF2Image.PDF2ImageColor.ARGB:
                    {
                        bINARY = ImageType.ARGB;
                        break;
                    }

                    default:
                    {
                        bINARY = null;
                        break;
                    }
                    }
                    string str  = ".bmp";
                    bool   flag = true;
                    this.startPage = Math.Max(this.startPage, 1);
                    if (this.endPage < 0)
                    {
                        this.endPage = this.pdfDocument.getNumberOfPages();
                    }
                    this.endPage = Math.Min(this.endPage, this.pdfDocument.getNumberOfPages());
                    PDFRenderer   pDFRenderer = new PDFRenderer(this.pdfDocument);
                    List <string> strs        = new List <string>();
                    for (int i = this.startPage - 1; i < this.endPage; i++)
                    {
                        BufferedImage bufferedImage = null;
                        bufferedImage = (bINARY != null ? pDFRenderer.renderImageWithDPI(i, (float)this.dpi, bINARY) : pDFRenderer.renderImageWithDPI(i, (float)this.dpi));
                        string str1 = string.Concat(new object[] { PDF2Image.TempPath, "\\", i + 1, str });
                        flag = flag & ImageIOUtil.writeImage(bufferedImage, str1, this.dpi);
                        strs.Add(str1);
                    }
                    this.ConvertJPGToTiff(strs, outputFile);
                }
                catch (Exception exception1)
                {
                    Exception exception = exception1;
                    throw new PDFToolkitException(exception.Message, exception);
                }
            }
            finally
            {
                PDFHelper.EmptyDirectory(PDF2Image.TempPath);
            }
            return(true);
        }