Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            PdfDocument       document       = new PdfDocument("pdf's/CS 369 REGISTRATION.pdf");
            PdfPageCollection pageCollection = document.Pages;
            PdfPage           page           = pageCollection[0];
            PDFiumBitmap      bitmap         = new PDFiumBitmap(300, 300, true);

            //From my understanding, this renders the PdfPage to the bitmap. The bitmap is simply the target.
            page.Render(bitmap);


            Stream stream = new MemoryStream();

            document.Save(stream);



            /*try{
             *  PdfDocument document = PdfDocument.Load("pdf's/CS 369 REGISTRATION.pdf");
             *  var bitMapImg = document.Render(1, 300, 300, true);
             *  bitMapImg.Save("pdf's", ImageFormat.Png);
             * }catch(FileNotFoundException ex){
             *  Console.WriteLine("File Not Found");
             *
             * }catch(System.BadImageFormatException ex1){
             *  Console.WriteLine("Incorrect Image Format");
             * }*/
        }
Ejemplo n.º 2
0
 private void AddPdfDocument(PdfPageCollection pages)
 {
     foreach (PdfPage page in pages)
     {
         Doc.AddPage(page);
         PageNumbering(Doc.Pages.Count - 1);
     }
 }
Ejemplo n.º 3
0
        public double GetTotalPageHeight(PdfDocument document)
        {
            PdfPageCollection pages  = document.Pages;
            double            height = 0;

            for (int i = 0; i < pages.Count; i++)
            {
                height += pages[i].Height;
            }
            System.Diagnostics.Debug.WriteLine(height.ToString());
            return(height);
        }
Ejemplo n.º 4
0
        public void SaveAllText()
        {
            PdfDocument       document = GetDocument();
            PdfPageCollection pages    = document.Pages;

            pageCount = pages.Count;

            for (int i = 0; i < pageCount; i++)
            {
                File.Create(HostingEnvironment.MapPath("~/TestImages/" + i + ".txt"));
                //File.Write
            }
        }
Ejemplo n.º 5
0
        public HtmlGenericControl DisplayAllPages()
        {
            HtmlGenericControl div      = new HtmlGenericControl("div");
            PdfDocument        document = GetDocument();
            PdfPageCollection  pages    = document.Pages;

            pageCount = pages.Count;

            for (int pageNum = 0; pageNum < pageCount; pageNum++)
            {
                div.Controls.Add(DisplayPage(pageNum));
            }

            return(div);
        }
Ejemplo n.º 6
0
        public void SaveAllImages()
        {
            PdfDocument       document = GetDocument();
            PdfPageCollection pages    = document.Pages;

            pageCount = pages.Count;
            if (pageCount < 2)
            {
                return;
            }
            else
            {
                for (int pageNum = 2; pageNum < pageCount; pageNum++)
                {
                    SaveImage(pageNum);
                }
            }
        }
Ejemplo n.º 7
0
        public void SaveFirstImages()
        {
            PdfDocument       document = GetDocument();
            PdfPageCollection pages    = document.Pages;

            pageCount = pages.Count;

            try
            {
                for (int pageNum = 0; pageNum < 2; pageNum++)
                {
                    if (pageNum < pages.Count)
                    {
                        SaveImage(pageNum);
                    }
                }
            }catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine(e.ToString());
            }
        }
Ejemplo n.º 8
0
        private static void DrawPageNumber(PdfPageCollection pages, PdfMargins margin, int startNumber, int pageCount)
        {
            var brush  = PdfBrushes.Black;
            var pen    = new PdfPen(brush, 2f);
            var font   = new PdfTrueTypeFont(new Font("Arial", 9f, System.Drawing.FontStyle.Italic), true);
            var format = new PdfStringFormat(PdfTextAlignment.Right)
            {
                MeasureTrailingSpaces = true
            };
            var space = font.Height * 0.75f;
            var x     = margin.Left;

            foreach (PdfPageBase page in pages)
            {
                page.Canvas.SetTransparency(1f);
                var width = page.Canvas.ClientSize.Width - margin.Left - margin.Right;
                var y     = page.Canvas.ClientSize.Height - margin.Bottom + space;
                page.Canvas.DrawLine(pen, x, y, x + width, y);
                var numberLabel = $"{startNumber++} of {pageCount}";
                page.Canvas.DrawString(numberLabel, font, brush, x + width, y, format);
            }
        }