예제 #1
0
        /// <summary>
        /// Converte immagine da stream in pdf su stream
        /// </summary>
        /// <param name="srcImageStream"></param>
        /// <param name="outPdfStream"></param>
        public void ImageBufferToPdfStream(byte[] image, Stream outPdfStream)
        {
            var wp = new WriterProperties().AddXmpMetadata().SetFullCompressionMode(true).SetPdfVersion(PdfVersion.PDF_1_4);
            var w  = new PdfWriter(outPdfStream, wp);

            w.SetCloseStream(false);
            var doc = new PdfDocument(w);

            var info = doc.GetDocumentInfo();

            //Dati PDF
            if (!string.IsNullOrEmpty(this.Author))
            {
                info.SetAuthor(this.Author);
            }

            if (!string.IsNullOrEmpty(this.Title))
            {
                info.SetTitle(this.Title);
            }

            if (!string.IsNullOrEmpty(this.Subject))
            {
                info.SetSubject(this.Subject);
            }

            var hlDoc = new Document(doc);

            var img = ImageDataFactory.Create(image, true);

            if (img is TiffImageData)
            {
                var numFrames = TiffImageData.GetNumberOfPages(image);

                for (int iPage = 1; iPage <= numFrames; iPage++)
                {
                    img = ImageDataFactory.CreateTiff(image, false, iPage, false);

                    using (var ms = new MemoryStream())
                    {
                        var imgPdf = new Image(img);
                        imgPdf.SetFixedPosition(0, 0);

                        doc.AddNewPage(new PageSize(imgPdf.GetImageWidth(), imgPdf.GetImageHeight()));

                        hlDoc.Add(imgPdf);
                    }
                }
            }
            else
            {
                doc.AddNewPage(new PageSize(img.GetWidth(), img.GetHeight()));
                var imgPdf = new Image(img);
                imgPdf.SetFixedPosition(0, 0);
                hlDoc.Add(imgPdf);
            }


            doc.Close();
        }
예제 #2
0
        /// <summary>Counts number of pages in the provided tiff image.</summary>
        /// <param name="inputImage">
        /// input image
        /// <see cref="System.IO.FileInfo"/>
        /// </param>
        /// <returns>number of pages in the provided TIFF image</returns>
        private static int GetNumberOfPageTiff(FileInfo inputImage)
        {
            RandomAccessFileOrArray raf = new RandomAccessFileOrArray(new RandomAccessSourceFactory().CreateBestSource
                                                                          (inputImage.FullName));
            int numOfPages = TiffImageData.GetNumberOfPages(raf);

            raf.Close();
            return(numOfPages);
        }
예제 #3
0
        static void Main(string[] args)
        {
            PdfWriter   writer   = new PdfWriter("C:\\Users\\Bill\\Desktop\\out.pdf");
            PdfDocument pdf      = new PdfDocument(writer);
            Document    document = new Document(pdf);

            Uri tiffFqn = UrlUtil.ToURL("C:\\Users\\Bill\\Desktop\\Multipage Test Image.tif");
            IRandomAccessSource     iRandomAccessSource     = new RandomAccessSourceFactory().CreateSource(tiffFqn);
            RandomAccessFileOrArray randomAccessFileOrArray = new RandomAccessFileOrArray(iRandomAccessSource);

            int tiffPageCount = TiffImageData.GetNumberOfPages(randomAccessFileOrArray);

            for (int i = 1; i <= tiffPageCount; i++)
            {
                Image tiffPage = new Image(ImageDataFactory.CreateTiff(tiffFqn, true, i, true));
                document.Add(tiffPage);
            }

            document.Close();
        }
예제 #4
0
        public virtual void CreatePdf(String dest)
        {
            PdfDocument pdf      = new PdfDocument(new PdfWriter(dest));
            Document    document = new Document(pdf);
            Image       img;
            // Animated GIF
            Uri url1 = UrlUtil.ToURL(TEST1);
            IList <ImageData> list = ImageDataFactory.CreateGifFrames(url1);

            foreach (ImageData data in list)
            {
                img = new iText.Layout.Element.Image(data);
                document.Add(img);
            }
            // JBIG2
            Uri url2 = UrlUtil.ToURL(TEST2);
            IRandomAccessSource     ras2 = new RandomAccessSourceFactory().CreateSource(url2);
            RandomAccessFileOrArray raf2 = new RandomAccessFileOrArray(ras2);
            int pages2 = Jbig2ImageData.GetNumberOfPages(raf2);

            for (int i = 1; i <= pages2; i++)
            {
                img = new iText.Layout.Element.Image(ImageDataFactory.CreateJbig2(url2, i));
                document.Add(img);
            }
            // TIFF
            Uri url3 = UrlUtil.ToURL(TEST3);
            IRandomAccessSource     ras3 = new RandomAccessSourceFactory().CreateSource(url3);
            RandomAccessFileOrArray raf3 = new RandomAccessFileOrArray(ras3);
            int pages3 = TiffImageData.GetNumberOfPages(raf3);

            for (int i_1 = 1; i_1 <= pages3; i_1++)
            {
                img = new iText.Layout.Element.Image(ImageDataFactory.CreateTiff(url3, true, i_1, true));
                document.Add(img);
            }
            document.Close();
        }