コード例 #1
0
        internal static void Run()
        {
            // Create a PdfRasterizer object
            PdfRasterizer rasterizer = new PdfRasterizer(Util.GetResourcePath("DocumentA.pdf"));


            // Create a color array using custom colors
            Color[] color = new Color[] { Color.FromArgb(255, 0, 0, 0),
                                          Color.FromArgb(255, 255, 255, 255),
                                          Color.FromArgb(255, 255, 0, 0),
                                          Color.FromArgb(255, 0, 255, 0),
                                          Color.FromArgb(255, 0, 0, 255),
                                          Color.FromArgb(255, 255, 255, 0),
                                          Color.FromArgb(255, 0, 255, 255),
                                          Color.FromArgb(255, 255, 0, 255) };

            // Create a UserPalette object using color array
            UserPalette userPalette = new UserPalette(color);

            // Create a PngIndexedColorFormat object using the palette
            PngIndexedColorFormat pngIndexedColorFormat = new PngIndexedColorFormat(userPalette, 100, DitheringAlgorithm.FloydSteinberg);

            // Create a PngImageFormat object using indexed color format object
            PngImageFormat pngImageFormat = new PngImageFormat(pngIndexedColorFormat);

            // Create a image size tha is a fixed size
            FixedImageSize fixedImageSize = new FixedImageSize(595, 841);

            // Save the image
            rasterizer.Draw("PngImageWithUserPalette.png", pngImageFormat, fixedImageSize);
        }
コード例 #2
0
        internal static void Run()
        {
            // Create a PdfRasterizer object
            PdfRasterizer rasterizer = new PdfRasterizer(Util.GetResourcePath("DocumentA.pdf"));

            // Create a GifImageFormat object
            GifImageFormat GifImageFormat = new GifImageFormat();

            // Set the dithering algorithm to FloydSteinberg
            GifImageFormat.DitheringAlgorithm = DitheringAlgorithm.FloydSteinberg;

            // Set the dithering percentage
            GifImageFormat.DitheringPercent = 100;

            // Set the palette type.
            GifImageFormat.ColorPalette = Palette.WebPalette;

            // Set the antialiasing to true
            GifImageFormat.AntiAliasing = true;

            // Create a image size tha is a fixed size
            FixedImageSize fixedImageSize = new FixedImageSize(595, 841);

            // Save the image
            rasterizer.Draw("GifWithWebPalette.Gif", GifImageFormat, fixedImageSize);
        }
コード例 #3
0
        // Convert a PDF document to 4 GIF files (one for each page).
        // Use the ceTe.DynamicPDF.Rasterizer namespace for the PdfRasterizer class.
        static void Main(string[] args)
        {
            // Create a PdfRasterizer object using the source PDF to be converted to GIF image
            PdfRasterizer rasterizer = new PdfRasterizer(GetResourcePath("doc-a.pdf"));

            // Call the Draw method with output image name, image format and the DPI
            rasterizer.Draw("output.gif", ImageFormat.Gif, ImageSize.Dpi600);
        }
コード例 #4
0
        // Convert a PDF document to BMP images (one for each page).
        // Use the ceTe.DynamicPDF.Rasterizer namespace for the PdfRasterizer class.
        private static void PdfToBmp()
        {
            // Create a PdfRasterizer object using the source PDF to be converted to BMP images
            PdfRasterizer rasterizer = new PdfRasterizer(GetResourcePath("doc-a.pdf"));

            // Call the Draw method with output image name, image format and the DPI
            rasterizer.Draw("output.bmp", ImageFormat.Bmp, ImageSize.Dpi96);
        }
コード例 #5
0
        // Convert a PDF document to a multipage TIFF image.
        // Use the ceTe.DynamicPDF.Rasterizer namespace for the PdfRasterizer class.
        private static void PdfToMultiPageTiff()
        {
            // Create a PdfRasterizer object using the source PDF to be converted to multipage TIFF image
            PdfRasterizer rasterizer = new PdfRasterizer(GetResourcePath("doc-a.pdf"));

            // Call the DrawToMultiPageTiff method with output image name, image format and the DPI
            rasterizer.DrawToMultiPageTiff("MultiPage.tiff", ImageFormat.TiffWithCcitGroup4, ImageSize.Dpi150);
        }
コード例 #6
0
        // Convert a PDF document to TIFF images (one for each page).
        // Use the ceTe.DynamicPDF.Rasterizer namespace for the PdfRasterizer class.
        private static void PdfToTiff()
        {
            // Create a PdfRasterizer object using the source PDF to be converted to TIFF image
            PdfRasterizer rasterizer = new PdfRasterizer(GetResourcePath("doc-a.pdf"));

            // Call the Draw method with output image name, image format and the DPI
            rasterizer.Draw("EachPage.tiff", ImageFormat.TiffWithLzw, ImageSize.Dpi150);
        }
コード例 #7
0
        // Convert a PDF document to PNG images (one for each page).
        // Use the ceTe.DynamicPDF.Rasterizer namespace for the PdfRasterizer class.
        private static void PdfToPng()
        {
            // Create a PdfRasterizer object using the source PDF to be converted to PNG image
            PdfRasterizer rasterizer = new PdfRasterizer(GetResourcePath("doc-a.pdf"));

            // Call the Draw method with output image name, image format and the DPI
            rasterizer.Draw("output.png", ImageFormat.Png, ImageSize.Dpi300);
        }
コード例 #8
0
        internal static void Run()
        {
            // Create a PdfRasterizer object
            PdfRasterizer rasterizer = new PdfRasterizer(Util.GetResourcePath("DocumentA.pdf"));

            // Create a image size tha is a fixed size
            FixedImageSize fixedImageSize = new FixedImageSize(595, 841);

            // Save the image
            rasterizer.DrawToMultiPageTiff("MultiPageTiff.tif", ImageFormat.TiffWithLzw, fixedImageSize);
        }
コード例 #9
0
        internal static void Run()
        {
            // Create a PdfRasterizer object
            PdfRasterizer rasterizer = new PdfRasterizer(Util.GetResourcePath("DocumentA.pdf"));

            // Create a image size tha is a fixed size
            FixedImageSize fixedImageSize = new FixedImageSize(595, 841);

            // Create a PngImageFormat object with RGB color
            PngImageFormat pngImageFormat = new PngImageFormat(PngColorFormat.Rgb);

            // Save the image
            rasterizer.Draw("PngImageWithRgbColor.png", pngImageFormat, fixedImageSize);
        }
コード例 #10
0
        /// <summary>
        /// From NuGet, named ceTe.DynamicPDF.Rasterizer.NET
        /// Online https://www.dynamicpdf.com/Rasterizer-PDF-.NET.aspx
        /// To note: https://www.dynamicpdf.com/docs/dotnet/rasterizer-limitations
        /// Example https://www.dynamicpdf.com/docs/dotnet/cete.dynamicpdf.rasterizer.pdfrasterizer
        /// </summary>
        /// <param name="pathToFile"></param>
        /// <param name="pathToSaveTo"></param>
        public void RasterisePdf(string pathToFile, string pathToSaveTo)
        {
            // Create a PdfRasterizer object.
            PdfRasterizer rasterizer = new PdfRasterizer(pathToFile);

            // Save the image.
            //TiffImageFormat.TiffWithLzw
            rasterizer.Draw(
                //FileHelper.PrepareOutputDirectoryAndFileName(pathToFile, pathToSaveTo),
                FileHelper.PrepareOutputDirectoryAndFileName(
                    FileHelper.FileNameForImage("DynamicPDF", pathToFile, null),
                    pathToSaveTo),
                PngImageFormat.Png, ImageSize.Dpi72);
        }
コード例 #11
0
        internal static void Run()
        {
            // Create a PdfRasterizer object
            PdfRasterizer rasterizer = new PdfRasterizer(Util.GetResourcePath("DocumentA.pdf"));

            // Create a JpegImageFormat object
            JpegImageFormat jpegImageFormat = new JpegImageFormat(100);

            // Create a image size tha is a fixed size
            FixedImageSize fixedImageSize = new FixedImageSize(595, 841);

            // Save the image
            rasterizer.Draw("JpegImage.jpg", jpegImageFormat, fixedImageSize);
        }
コード例 #12
0
		public static void ExportPdf(string sourceFilePath, string destinationPngPath, string destinationThumbsPath)
		{
			var rasterizer = new PdfRasterizer(sourceFilePath);
			// Save the image.
			var pngImageFormat = new PngImageFormat(PngColorFormat.Rgb);
			var imageSizeFormat = new PercentageImageSize(100);
			var thumbsSizeFormat = new PercentageImageSize(10);
			for (var i = 0; i < rasterizer.Pages.Count; i++)
			{
				rasterizer.Pages[i].Draw(Path.Combine(destinationPngPath, "Page" + (i + 1) + ".png"), pngImageFormat, imageSizeFormat);
				rasterizer.Pages[i].Draw(Path.Combine(destinationThumbsPath, "Page" + (i + 1) + ".png"), pngImageFormat, thumbsSizeFormat);
			}
			rasterizer.Dispose();
		}
コード例 #13
0
        internal static void Run()
        {
            // Create a PdfRasterizer object
            PdfRasterizer rasterizer = new PdfRasterizer(Util.GetResourcePath("DocumentA.pdf"));

            // Create a image size tha is a fixed size
            FixedImageSize fixedImageSize = new FixedImageSize(595, 841);

            // Create a TiffMonochromeColorFormat object with CCIT Group 3 compression.
            TiffMonochromeColorFormat tiffColorFormat = new TiffMonochromeColorFormat(TiffMonochromeCompressionType.CcitGroup3);

            // Create a TiffImageFormat object with monocrome color
            TiffImageFormat tiffImageFormat = new TiffImageFormat(tiffColorFormat);

            // Save the image
            rasterizer.Draw("TiffImageColorFormat.tif", tiffImageFormat, fixedImageSize);
        }
コード例 #14
0
        internal static void Run()
        {
            // Create a PdfRasterizer object
            PdfRasterizer rasterizer = new PdfRasterizer(Util.GetResourcePath("DocumentA.pdf"));

            // Create a BmpMonochromeColorFormat object
            BmpMonochromeColorFormat bmpMonochromeColorFormat = new BmpMonochromeColorFormat(DitheringAlgorithm.FloydSteinberg, 100);

            // Create a BmpImageFormat object with the bmpMonochromeColorFormat
            BmpImageFormat bmpImageFormat = new BmpImageFormat(bmpMonochromeColorFormat);

            // Create a image size tha is a fixed size
            FixedImageSize fixedImageSize = new FixedImageSize(595, 841);

            // Save the image
            rasterizer.Draw("MonochromeImage.bmp", bmpImageFormat, fixedImageSize);
        }
コード例 #15
0
        internal static void Run()
        {
            // Get a byte array containing the source PDF
            byte[] pdfArray = System.IO.File.ReadAllBytes(Util.GetResourcePath("PortFolio.pdf"));

            // Create an input PDF from the byte array
            InputPdf inputPdf = new InputPdf(pdfArray);

            // Get an array of the attachments in the input PDF
            Attachment[] files = inputPdf.Attachments;

            // Gets the first attachment as a PDF if it is a PDF file
            InputPdf inputPdfFile = files[0].TryGetPdf();

            // Create a PdfRasterizer object
            PdfRasterizer rasterizer = new PdfRasterizer(inputPdfFile);

            // Save the image
            rasterizer.Draw("PdfPortfolio.png", ImageFormat.Png, ImageSize.Dpi96);
        }
コード例 #16
0
        public Task <Stream> GenerateCover(Stream file)
        {
            if (file is null)
            {
                throw new ArgumentNullException(nameof(file));
            }
            Stream imageStream = null;
            var    task        = Task.Factory.StartNew(() =>
            {
                InputPdf input    = new InputPdf(file);
                PdfRasterizer pdf = new PdfRasterizer(input);
                byte[] image      = pdf.Pages[0].Draw(ImageFormat.Jpeg, ImageSize.Dpi72);
                imageStream       = new MemoryStream(image);
            });

            return(Task.WhenAll(task).ContinueWith(t =>
            {
                return imageStream;
            }));
        }
コード例 #17
0
        internal static void Run()
        {
            // Create a PdfRasterizer object
            PdfRasterizer rasterizer = new PdfRasterizer(Util.GetResourcePath("DocumentA.pdf"));

            // Create the GifImageFormat object.
            GifImageFormat gifImageFormat = new GifImageFormat();

            // Set the dithering algorithm to FloydSteinberg
            gifImageFormat.DitheringAlgorithm = DitheringAlgorithm.FloydSteinberg;

            // Set the dithering percentage
            gifImageFormat.DitheringPercent = 100;

            // Create a image size tha is a fixed size
            FixedImageSize fixedImageSize = new FixedImageSize(595, 841);

            // Save the image
            rasterizer.Draw("IndexedImage.Gif", gifImageFormat, fixedImageSize);
        }
        public void LoadPdfFromBase(byte[] base64BinaryStr, string printerName, string printerTray, string paperSize)
        {
            string tempDirectory = Environment.GetEnvironmentVariable("LocalAppData") + "/001/";

            Stream streamer = new MemoryStream();

            streamer.Write(base64BinaryStr);

            PdfRasterizer pdfRasterizer = new PdfRasterizer(920, 920, paperSize);
            var           tiffs         = pdfRasterizer.Rasterize(streamer);

            convertedBmp = tiffs;

            if (!Directory.Exists(tempDirectory))
            {
                Directory.CreateDirectory(tempDirectory);
            }

            convertedBmp.Save(tempDirectory + "test1.tiff");

            PrintPdf("printJobName", printerName, GetPrinterTrayIdByTrayName(printerName, printerTray), paperSize);
        }
        public ActionResult RasterizeToImages(IFormCollection collection)
        {
            m_formCollection = collection;

            // get the PDF file
            string pdfFile = m_hostingEnvironment.ContentRootPath + @"\wwwroot" + @"\DemoFiles\Pdf\InputPdf.pdf";

            // create the PDF rasterizer
            PdfRasterizer pdfRasterizer = new PdfRasterizer();

            // set a demo serial number
            pdfRasterizer.SerialNumber = "YCgJMTAE-BiwJAhIB-EhlWTlBA-UEBRQFBA-U1FOUVJO-WVlZWQ==";

            // set the output images color space
            pdfRasterizer.ColorSpace = GetColorSpace();

            // set the rasterization resolution in DPI
            pdfRasterizer.DPI = int.Parse(collection["textBoxDPI"]);

            int fromPdfPageNumber = int.Parse(collection["textBoxFromPage"]);
            int toPdfPageNumber   = collection["textBoxToPage"][0].Length > 0 ? int.Parse(collection["textBoxToPage"]) : 0;

            byte[] imageBuffer = null;

            if (collection["checkBoxToTiff"].Count > 0)
            {
                // convert the PDF document to a multipage TIFF image in a memory buffer
                // the TIFF images can also be produced in a file using the RasterizeToTiffFile method
                imageBuffer = pdfRasterizer.RasterizeToTiff(pdfFile, fromPdfPageNumber, toPdfPageNumber);
            }
            else
            {
                // rasterize a range of pages of the PDF document to memory in .NET Image objects
                // the images can also be produced to a folder using the RasterizeToImageFiles method
                // or they can be produced one by one using the RaisePageRasterizedEvent method
                PdfPageRasterImage[] pageImages = pdfRasterizer.RasterizeToImageObjects(pdfFile, fromPdfPageNumber, toPdfPageNumber);

                // return if no page was rasterized
                if (pageImages.Length == 0)
                {
                    return(Redirect("/RasterizePdfPagesToImages"));
                }

                // get the first page image bytes in a buffer
                try
                {
                    // get the .NET Image object
                    System.Drawing.Image imageObject = pageImages[0].ImageObject;

                    // get the image data in a buffer
                    imageBuffer = GetImageBuffer(imageObject);
                }
                finally
                {
                    // dispose the page images
                    for (int i = 0; i < pageImages.Length; i++)
                    {
                        pageImages[i].Dispose();
                    }
                }
            }

            if (collection["checkBoxToTiff"].Count > 0)
            {
                FileResult fileResult = new FileContentResult(imageBuffer, "image/tiff");
                fileResult.FileDownloadName = "PageImage.tiff";

                return(fileResult);
            }
            else
            {
                FileResult fileResult = new FileContentResult(imageBuffer, "image/png");
                fileResult.FileDownloadName = "PageImage.png";

                return(fileResult);
            }
        }
コード例 #20
0
        protected void buttonRasterizeToImages_Click(object sender, EventArgs e)
        {
            // get the PDF file
            string pdfFile = Server.MapPath("~") + @"\DemoFiles\Pdf\InputPdf.pdf";

            // create the PDF rasterizer
            PdfRasterizer pdfRasterizer = new PdfRasterizer();

            // set a demo serial number
            pdfRasterizer.SerialNumber = "YCgJMTAE-BiwJAhIB-EhlWTlBA-UEBRQFBA-U1FOUVJO-WVlZWQ==";

            // set the output images color space
            pdfRasterizer.ColorSpace = GetColorSpace();

            // set the rasterization resolution in DPI
            pdfRasterizer.DPI = int.Parse(textBoxDPI.Text);

            int fromPdfPageNumber = int.Parse(textBoxFromPage.Text);
            int toPdfPageNumber   = textBoxToPage.Text.Length > 0 ? int.Parse(textBoxToPage.Text) : 0;

            // rasterize a range of pages of the PDF document to memory in .NET Image objects
            // the images can also be produced to a folder using the RasterizeToImageFiles method
            // or they can be produced one by one using the RaisePageRasterizedEvent method
            PdfPageRasterImage[] pageImages = pdfRasterizer.RasterizeToImageObjects(pdfFile, fromPdfPageNumber, toPdfPageNumber);

            // return if no page was rasterized
            if (pageImages.Length == 0)
            {
                return;
            }

            // get the first page image bytes in a buffer
            byte[] imageBuffer = null;
            try
            {
                // get the .NET Image object
                System.Drawing.Image imageObject = pageImages[0].ImageObject;

                // get the image data in a buffer
                imageBuffer = GetImageBuffer(imageObject);
            }
            finally
            {
                // dispose the page images
                for (int i = 0; i < pageImages.Length; i++)
                {
                    pageImages[i].Dispose();
                }
            }

            // inform the browser about the binary data format
            HttpContext.Current.Response.AddHeader("Content-Type", "image/png");

            // let the browser know how to open the image and the image name
            HttpContext.Current.Response.AddHeader("Content-Disposition",
                                                   String.Format("attachment; filename={0}; size={1}", "PageImage.png", imageBuffer.Length.ToString()));

            // write the image buffer to HTTP response
            HttpContext.Current.Response.BinaryWrite(imageBuffer);

            // call End() method of HTTP response to stop ASP.NET page processing
            HttpContext.Current.Response.End();
        }
コード例 #21
0
 public RasterizerPDF(string pFilePath, string pDestinationPath,int intStartPage)
 {
     this._filePath = pFilePath;
     this._destinationPath = pDestinationPath;
     rasterizer = new PdfRasterizer(_filePath,intStartPage,1);
 }
コード例 #22
0
 public RasterizerPDF(string pFilePath, string pDestinationPath)
 {
     this._filePath = pFilePath;
     this._destinationPath = pDestinationPath;
     rasterizer = new PdfRasterizer(_filePath);
 }