static void Main()
        {
            // Create new document
            Document pdfDocument = new Document();

            pdfDocument.RegistrationName = "demo";
            pdfDocument.RegistrationKey  = "demo";

            // If you wish to load an existing document uncomment the line below and comment the Add page section instead
            // pdfDocument.Load(@".\existing_document.pdf");

            // Get Tiff file in Bitmap
            Bitmap multipageTiffImage = (Bitmap)System.Drawing.Image.FromFile("MultipageTiffFile.tiff");

            // Tiff images can contain multiple images named as frame
            int count = multipageTiffImage.GetFrameCount(FrameDimension.Page);

            for (int idx = 0; idx < count; idx++)
            {
                // save each frame to a bytestream
                multipageTiffImage.SelectActiveFrame(FrameDimension.Page, idx);
                MemoryStream byteStream = new MemoryStream();
                multipageTiffImage.Save(byteStream, ImageFormat.Tiff);

                // Fix Image Orientation
                var sysImage = FixImageOrientation(byteStream);

                using (sysImage)
                {
                    var   image = new Image(sysImage, ImageCompression.DCT, 75);
                    float w     = sysImage.Width / sysImage.HorizontalResolution * 72f;
                    float h     = sysImage.Height / sysImage.VerticalResolution * 72f;

                    // Create PDF page
                    var page = new Page(w, h);

                    var canvas = page.Canvas;
                    canvas.DrawImage(image, 0, 0, w, h);

                    // Add PDF document
                    pdfDocument.Pages.Add(page);
                }
            }

            // Save document to file
            pdfDocument.Save("result.pdf");

            // Cleanup
            pdfDocument.Dispose();

            // Open result document in default associated application (for demo purpose)
            ProcessStartInfo processStartInfo = new ProcessStartInfo("result.pdf");

            processStartInfo.UseShellExecute = true;
            Process.Start(processStartInfo);
        }
Esempio n. 2
0
        private static void TestGetImages()
        {
            string input = @"c:\5\inbox-technical74\Big Yellow Group 2017 FS.pdf";

            using (Document doc = new Document(input))
            {
                var   images = doc.Pages[0].Images;
                Image image  = images[0];
            }
        }
Esempio n. 3
0
        static void Main(string[] args)
        {
            string inputPdfDocument  = @".\sample.pdf";
            string maskingImage      = @".\mask.png";
            string resultPdfDocument = @".\result.pdf";


            // Create Bytescout.PDFExtractor.ImageExtractor instance
            using (ImageExtractor imageExtractor = new ImageExtractor())
            {
                imageExtractor.RegistrationName = "demo";
                imageExtractor.RegistrationKey  = "demo";

                // Load document
                imageExtractor.LoadDocumentFromFile(inputPdfDocument);

                // Create Bytescout.PDF.Document instance
                using (Document pdfDocument = new Document())
                {
                    pdfDocument.RegistrationName = "demo";
                    pdfDocument.RegistrationKey  = "demo";

                    // Load document
                    pdfDocument.Load(inputPdfDocument);

                    // Load masking image
                    var maskImage = new Image(maskingImage);

                    // Process pages
                    for (int i = 0; i < pdfDocument.Pages.Count; i++)
                    {
                        Page page = pdfDocument.Pages[i];

                        // Find images on the page
                        if (imageExtractor.GetFirstPageImage(i))
                        {
                            do
                            {
                                // Get image rectangle
                                var imageRect = imageExtractor.GetCurrentImageRectangle();

                                // Draw new image other the found image
                                page.Canvas.DrawImage(maskImage, imageRect.Left, imageRect.Top, imageRect.Width, imageRect.Height);
                            } while (imageExtractor.GetNextImage());
                        }
                    }

                    // Save modified document
                    pdfDocument.Save(resultPdfDocument);
                }
            }

            // Open document in default PDF viewer application (for demonstration).
            Process.Start(resultPdfDocument);
        }
        static void Main()
        {
            // Create new document
            Document pdfDocument = new Document();

            pdfDocument.RegistrationName = "demo";
            pdfDocument.RegistrationKey  = "demo";

            // If you wish to load an existing document uncomment the line below and comment the Add page section instead
            // pdfDocument.Load(@".\existing_document.pdf");

            // Add page
            Page page = new Page(PaperFormat.A4);

            pdfDocument.Pages.Add(page);

            Canvas canvas = page.Canvas;

            // Add JPEG image and draw unscaled
            Image image1 = new Image("Image1.jpg");

            canvas.DrawImage(image1, 20, 20);

            // Add PNG image and draw reduced twice
            Image image2 = new Image("Image2.png");

            canvas.DrawImage(image2, 20, 520, image2.Width / 2, image2.Height / 2);

            // Add TIFF image and draw scaled disproportionately
            Image image3 = new Image("Image3.tif");

            canvas.DrawImage(image3, 270, 520, image3.Width / 2, image3.Height / 4);

            // Add GIF image and draw rotated 90 degrees and scaled
            Image image4 = new Image("Image4.gif");

            canvas.TranslateTransform(390, 650);
            canvas.RotateTransform(90);
            canvas.DrawImage(image4, 0, 0, image4.Width / 4, image4.Height / 4);

            // Save document to file
            pdfDocument.Save("result.pdf");

            // Cleanup
            pdfDocument.Dispose();

            // Open result document in default associated application (for demo purpose)
            ProcessStartInfo processStartInfo = new ProcessStartInfo("result.pdf");

            processStartInfo.UseShellExecute = true;
            Process.Start(processStartInfo);
        }
Esempio n. 5
0
        static void Main()
        {
            // Create new document
            Document pdfDocument = new Document();

            pdfDocument.RegistrationName = "demo";
            pdfDocument.RegistrationKey  = "demo";

            // If you wish to load an existing document uncomment the line below and comment the Add page section instead
            // pdfDocument.Load(@".\existing_document.pdf");

            //Create instance and load file
            Xps2Image xps2Image = new Xps2Image("Sample.xps");

            // Set parameter
            Parameters oParam = new Parameters();

            oParam.Dpi       = 300;           // Set Dpi
            oParam.ImageType = ImageType.Png; // Output image type

            // Get Bitmap from input file
            var outBitmapList = xps2Image.ToBitmap(oParam);

            foreach (var itmBitmap in outBitmapList)
            {
                // Create new pdf page
                Page page = new Page(PaperFormat.A4);

                // Save image to a bytestream
                MemoryStream byteStream = new MemoryStream();
                itmBitmap.Save(byteStream, ImageFormat.Png);

                // Fill page with image
                Image pageImage = new Image(byteStream);
                page.Canvas.DrawImage(pageImage, 5, 5, pageImage.Width / 2, pageImage.Height / 3);

                // Add pdf page to pdf document
                pdfDocument.Pages.Add(page);
            }

            // Save document to file
            pdfDocument.Save("result.pdf");

            // Cleanup
            pdfDocument.Dispose();

            // Open result document in default associated application (for demo purpose)
            ProcessStartInfo processStartInfo = new ProcessStartInfo("result.pdf");

            processStartInfo.UseShellExecute = true;
            Process.Start(processStartInfo);
        }
        static void Main()
        {
            // Create new document
            Document pdfDocument = new Document();

            pdfDocument.RegistrationName = "demo";
            pdfDocument.RegistrationKey  = "demo";

            // If you wish to load an existing document uncomment the line below and comment the Add page section instead
            // pdfDocument.Load(@".\existing_document.pdf");

            // Input image array
            var arrImages = new string[] { "Image1.jpg", "Image2.jpg" };

            // Process each image
            foreach (var itmImage in arrImages)
            {
                var sysImage = FixImageOrientation(itmImage);

                using (sysImage)
                {
                    var   image = new Image(sysImage, ImageCompression.DCT, 75);
                    float w     = sysImage.Width / sysImage.HorizontalResolution * 72f;
                    float h     = sysImage.Height / sysImage.VerticalResolution * 72f;

                    // Create PDF page
                    var page = new Page(w, h);

                    var canvas = page.Canvas;
                    canvas.DrawImage(image, 0, 0, w, h);

                    // Add PDF document
                    pdfDocument.Pages.Add(page);
                }
            }

            // Save PDF document
            pdfDocument.Save("result.pdf");

            // Cleanup
            pdfDocument.Dispose();

            // Open result document in default associated application (for demo purpose)
            ProcessStartInfo processStartInfo = new ProcessStartInfo("result.pdf");

            processStartInfo.UseShellExecute = true;
            Process.Start(processStartInfo);
        }
        static void Main()
        {
            // Create new document
            Document pdfDocument = new Document();

            pdfDocument.RegistrationName = "demo";
            pdfDocument.RegistrationKey  = "demo";
            // Add page
            Page page = new Page(PaperFormat.A4);

            pdfDocument.Pages.Add(page);

            Canvas canvas = page.Canvas;

            // Add JPEG image and draw unscaled
            Image image1 = new Image("Image1.jpg");

            canvas.DrawImage(image1, 20, 20);

            // Add PNG image and draw reduced twice
            Image image2 = new Image("Image2.png");

            canvas.DrawImage(image2, 20, 520, image2.Width / 2, image2.Height / 2);

            // Add TIFF image and draw scaled disproportionately
            Image image3 = new Image("Image3.tif");

            canvas.DrawImage(image3, 270, 520, image3.Width / 2, image3.Height / 4);

            // Add GIF image and draw rotated 90 degrees and scaled
            Image image4 = new Image("Image4.gif");

            canvas.TranslateTransform(390, 650);
            canvas.RotateTransform(90);
            canvas.DrawImage(image4, 0, 0, image4.Width / 4, image4.Height / 4);

            // Save document to file
            pdfDocument.Save("result.pdf");

            // Cleanup
            pdfDocument.Dispose();

            // Open document in default PDF viewer app
            Process.Start("result.pdf");
        }