當前位置: 首頁>>代碼示例>>C#>>正文


C# PdfReader.GetPageN方法代碼示例

本文整理匯總了C#中iTextSharp.text.pdf.PdfReader.GetPageN方法的典型用法代碼示例。如果您正苦於以下問題:C# PdfReader.GetPageN方法的具體用法?C# PdfReader.GetPageN怎麽用?C# PdfReader.GetPageN使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在iTextSharp.text.pdf.PdfReader的用法示例。


在下文中一共展示了PdfReader.GetPageN方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: collectDataforDay

        /**
         * Put all data from given day into given table
         */
        public static void collectDataforDay(DateTime dateTime, SQLiteConnection m_dbConnection)
        {
            string zeroMonth = dateTime.Month < 10 ? "0" : "";
              string zeroDay = dateTime.Day < 10 ? "0" : "";
              string date = zeroMonth + dateTime.Month + "/" + zeroDay + dateTime.Day + "/" + dateTime.Year;

              PdfReader reader;
              try
              {
            reader = new PdfReader("http://www.equibase.com/premium/eqbPDFChartPlus.cfm?RACE=A&BorP=P&TID=SAR&CTRY=USA&DT=" + date + "&DAY=D&STYLE=EQB");
              }
              catch (Exception e)
              {
            Console.WriteLine("CAPTCHA TIME");
            Console.ReadKey();
            Console.ReadKey();

            reader = new PdfReader("http://www.equibase.com/premium/eqbPDFChartPlus.cfm?RACE=A&BorP=P&TID=SAR&CTRY=USA&DT=" + date + "&DAY=D&STYLE=EQB");
              }
              StringBuilder builder = new StringBuilder();

              for (int x = 1; x <= reader.NumberOfPages; x++)
              {
            PdfDictionary page = reader.GetPageN(x);
            IRenderListener listener = new SBTextRenderer(builder);
            PdfContentStreamProcessor processor = new PdfContentStreamProcessor(listener);
            PdfDictionary pageDic = reader.GetPageN(x);
            PdfDictionary resourcesDic = pageDic.GetAsDict(PdfName.RESOURCES);
            processor.ProcessContent(ContentByteUtils.GetContentBytesForPage(reader, x), resourcesDic);
              }

              if (pages.Count != 0)
              {

            DataHandler handler = new DataHandler(dateTime, pages, m_dbConnection);
            Thread thread = new Thread(new ThreadStart(handler.extractPdfData));

            thread.Start();
            thread.Join();
            reader.Dispose();
            pages.Clear();
              }
              else
              {
            // If there were no races on this particular day, simply skip it! :D
            Console.WriteLine("Invalid Date: " + date);
              }
        }
開發者ID:ryanlough,項目名稱:Horse-Racing-Analytic-Betting,代碼行數:51,代碼來源:Program.cs

示例2: TestConstructionForType0WithoutToUnicodeMap

        virtual public void TestConstructionForType0WithoutToUnicodeMap()
        {
            int pageNum = 2;
            PdfName fontIdName = new PdfName("TT9");

            string testFile = TestResourceUtils.GetResourceAsTempFile(TEST_RESOURCES_PATH, "type0FontWithoutToUnicodeMap.pdf");
            RandomAccessFileOrArray f = new RandomAccessFileOrArray(testFile);
            PdfReader reader = new PdfReader(f, null);

            try
            {
                PdfDictionary fontsDic = reader.GetPageN(pageNum).GetAsDict(PdfName.RESOURCES).GetAsDict(PdfName.FONT);
                PdfDictionary fontDicDirect = fontsDic.GetAsDict(fontIdName);
                PRIndirectReference fontDicIndirect = (PRIndirectReference)fontsDic.Get(fontIdName);

                Assert.AreEqual(PdfName.TYPE0, fontDicDirect.GetAsName(PdfName.SUBTYPE));
                Assert.AreEqual("/Identity-H", fontDicDirect.GetAsName(PdfName.ENCODING).ToString());
                Assert.IsNull(fontDicDirect.Get(PdfName.TOUNICODE), "This font should not have a ToUnicode map");

                new DocumentFont(fontDicIndirect); // this used to throw an NPE
            }
            finally
            {
                reader.Close();
            }
        }
開發者ID:newlysoft,項目名稱:itextsharp,代碼行數:26,代碼來源:DocumentFontTest.cs

示例3: RemoveLayers

 /// <summary>
 /// Removes layers from a PDF document </summary>
 /// <param name="reader">	a PdfReader containing a PDF document </param>
 /// <param name="layers">	a sequence of names of OCG layers </param>
 /// <exception cref="IOException"> </exception>
 public virtual void RemoveLayers(PdfReader reader, params string[] layers)
 {
     int n = reader.NumberOfPages;
     ICollection<string> ocgs = new HashSet2<string>();
     for (int i = 0; i < layers.Length; i++)
     {
         ocgs.Add(layers[i]);
     }
     OCGParser parser = new OCGParser(ocgs);
     for (int i = 1; i <= n; i++)
     {
         PdfDictionary page = reader.GetPageN(i);
         Parse(parser, page);
         page.Remove(new PdfName("PieceInfo"));
         RemoveAnnots(page, ocgs);
         RemoveProperties(page, ocgs);
     }
     PdfDictionary root = reader.Catalog;
     PdfDictionary ocproperties = root.GetAsDict(PdfName.OCPROPERTIES);
     RemoveOCGsFromArray(ocproperties, PdfName.OCGS, ocgs);
     PdfDictionary d = ocproperties.GetAsDict(PdfName.D);
     if (d != null)
     {
         RemoveOCGsFromArray(d, PdfName.ON, ocgs);
         RemoveOCGsFromArray(d, PdfName.OFF, ocgs);
         RemoveOCGsFromArray(d, PdfName.LOCKED, ocgs);
         RemoveOCGsFromArray(d, PdfName.RBGROUPS, ocgs);
         RemoveOCGsFromArray(d, PdfName.ORDER, ocgs);
         RemoveOCGsFromArray(d, PdfName.AS, ocgs);
     }
     reader.RemoveUnusedObjects();
 }
開發者ID:,項目名稱:,代碼行數:37,代碼來源:

示例4: IsScannedPdf

        public static bool IsScannedPdf(string pdfFilePath)
        {
            // Start analyzing the PDF
            PdfReader reader = new PdfReader(pdfFilePath);
            PdfDictionary resources;

            try
            {
                // Go through all the pages
                for (int p = 1; p <= reader.NumberOfPages; p++)
                {
                    // Find the embedded resources
                    PdfDictionary dic = reader.GetPageN(p);
                    resources = dic.GetAsDict(PdfName.RESOURCES);
                    if (resources != null)
                    {
                        // If we have any embedded font, it's not scanned
                        if (resources.GetAsDict(PdfName.FONT) != null)
                            return false;
                    }
                }
                return true;
            }
            finally
            {
                reader.Close();
            }
        }
開發者ID:sbxlmdsl,項目名稱:MateCat-Win-Converter,代碼行數:28,代碼來源:PdfAnalyzer.cs

示例5: ExtractImagesFromPDF

        public static void ExtractImagesFromPDF(string password, string key, string docPath, string pagePath, PageCollection pages)
        {
            Page page = null;
            // NOTE:  This will only get the first image it finds per page.
            PdfReader pdf = new PdfReader(Utility.Security.AES.DecryptFile(key, docPath));
            //RandomAccessFileOrArray raf = new iTextSharp.text.pdf.RandomAccessFileOrArray(p);

            try
            {
                for (int pageNumber = 1; pageNumber <= pdf.NumberOfPages; pageNumber++)
                {
                    PdfDictionary pg = pdf.GetPageN(pageNumber);

                    // recursively search pages, forms and groups for images.
                    PdfObject obj = FindImageInPDFDictionary(pg);
                    if (obj != null)
                    {

                        int XrefIndex = Convert.ToInt32(((PRIndirectReference)obj).Number.ToString(System.Globalization.CultureInfo.InvariantCulture));
                        PdfObject pdfObj = pdf.GetPdfObject(XrefIndex);
                        PdfStream pdfStrem = (PdfStream)pdfObj;
                        byte[] bytes = PdfReader.GetStreamBytesRaw((PRStream)pdfStrem);
                        if ((bytes != null))
                        {
                            using (System.IO.MemoryStream memStream = new System.IO.MemoryStream(bytes))
                            {
                                memStream.Position = 0;
                                System.Drawing.Image img = System.Drawing.Image.FromStream(memStream);
                                // must save the file while stream is open.

                                page = new Page();
                                page.Order = pages.Count;
                                page.Save();
                                page.Token = Utility.Security.AES.GetToken(page.Id, password);
                                //string path = System.IO.Path.Combine(page.Filename, String.Format(@"{0}.jpg", pageNumber));
                                System.Drawing.Imaging.EncoderParameters parms = new System.Drawing.Imaging.EncoderParameters(1);
                                parms.Param[0] = new System.Drawing.Imaging.EncoderParameter(System.Drawing.Imaging.Encoder.Compression, 0);
                                System.Drawing.Imaging.ImageCodecInfo jpegEncoder = System.Drawing.Imaging.ImageCodecInfo.GetImageEncoders().FirstOrDefault(e => e.FormatDescription == "JPEG");
                                System.IO.MemoryStream ms = new System.IO.MemoryStream();
                                img.Save(ms, jpegEncoder, parms);
                                System.IO.File.WriteAllBytes(System.IO.Path.Combine(pagePath, page.Filename), SoftFluent.Samples.GED.Utility.Security.AES.EncryptStream(page.Token, ms.ToArray()).ToArray());
                                ms.Close();
                                pages.Add(page);
                            }
                        }
                    }
                }
            }
            catch
            {
                throw;
            }
            finally
            {
                pdf.Close();
                //raf.Close();
            }
        }
開發者ID:modulexcite,項目名稱:CodeFluent-Entities,代碼行數:58,代碼來源:PDFManager.cs

示例6: GetContentBytesForPage

        /**
         * Gets the content bytes of a page from a reader
         * @param reader  the reader to get content bytes from
         * @param pageNum   the page number of page you want get the content stream from
         * @return  a byte array with the effective content stream of a page
         * @throws IOException
         * @since 5.0.1
         */
        public static byte[] GetContentBytesForPage(PdfReader reader, int pageNum)
        {
            PdfDictionary pageDictionary = reader.GetPageN(pageNum);
            PdfObject contentObject = pageDictionary.Get(PdfName.CONTENTS);
            if (contentObject == null)
                return new byte[0];

            byte[] contentBytes = ContentByteUtils.GetContentBytesFromContentObject(contentObject);
            return contentBytes;
        }
開發者ID:karino2,項目名稱:wikipediaconv,代碼行數:18,代碼來源:ContentByteUtils.cs

示例7: ListFonts

// ---------------------------------------------------------------------------    
    /**
     * Creates a HashSet containing information about the fonts in the src PDF file.
     * @param src the PDF file
     * 
     * HashSet only available in .NET >= 3.5
     */
    public HashSet<String> ListFonts(byte[] src) {
      HashSet<String> set = new HashSet<String>();
      PdfReader reader = new PdfReader(src);
      PdfDictionary resources;
      for (int k = 1; k <= reader.NumberOfPages; ++k) {
        resources = reader.GetPageN(k).GetAsDict(PdfName.RESOURCES);
        ProcessResource(set, resources);
      }
      return set;
    }
開發者ID:,項目名稱:,代碼行數:17,代碼來源:

示例8: ProcessContentPage

        public static void ProcessContentPage(PdfReader reader, int page, Test_iTextSharp.ITextExtractionStrategy strategy)
        {
            PdfReaderContentParser parser = new PdfReaderContentParser(reader);

            PdfDictionary pageDic = reader.GetPageN(page);
            PdfDictionary resourcesDic = pageDic.GetAsDict(PdfName.RESOURCES);

            Test_iTextSharp.PdfContentStreamProcessor processor = new Test_iTextSharp.PdfContentStreamProcessor(strategy);
            byte[] bytes = ContentByteUtils.GetContentBytesForPage(reader, page);
            processor.ProcessContent(bytes, resourcesDic);
        }
開發者ID:labeuze,項目名稱:source,代碼行數:11,代碼來源:PdfTools.cs

示例9: ExtractImagesFromPDF

        public static void ExtractImagesFromPDF(string sourcePdf, string outputPath)
        {
            // NOTE:  This will only get the first image it finds per page.
            PdfReader pdf = new PdfReader(sourcePdf);
            RandomAccessFileOrArray raf = new iTextSharp.text.pdf.RandomAccessFileOrArray(sourcePdf);

            try
            {
                for (int pageNumber = 1; pageNumber <= pdf.NumberOfPages; pageNumber++)
                {
                    PdfDictionary pg = pdf.GetPageN(pageNumber);

                    // recursively search pages, forms and groups for images.
                    PdfObject obj = FindImageInPDFDictionary(pg);
                    if (obj != null)
                    {

                        int XrefIndex = Convert.ToInt32(((PRIndirectReference)obj).Number.ToString(System.Globalization.CultureInfo.InvariantCulture));
                        PdfObject pdfObj = pdf.GetPdfObject(XrefIndex);
                        PdfStream pdfStrem = (PdfStream)pdfObj;
                        byte[] bytes = PdfReader.GetStreamBytesRaw((PRStream)pdfStrem);
                        if ((bytes != null))
                        {
                            using (System.IO.MemoryStream memStream = new System.IO.MemoryStream(bytes))
                            {
                                memStream.Position = 0;
                                System.Drawing.Image img = System.Drawing.Image.FromStream(memStream);
                                // must save the file while stream is open.
                                if (!Directory.Exists(outputPath))
                                    Directory.CreateDirectory(outputPath);

                                string path = Path.Combine(outputPath, String.Format(@"{0}.jpg", pageNumber));
                                System.Drawing.Imaging.EncoderParameters parms = new System.Drawing.Imaging.EncoderParameters(1);
                                parms.Param[0] = new System.Drawing.Imaging.EncoderParameter(System.Drawing.Imaging.Encoder.Compression, 0);
                                System.Drawing.Imaging.ImageCodecInfo jpegEncoder = GetImageEncoder("JPEG");
                                img.Save(path, jpegEncoder, parms);
                            }
                        }
                    }
                }
            }
            catch
            {
                throw;
            }
            finally
            {
                pdf.Close();
                raf.Close();
            }


        }
開發者ID:alqadasifathi,項目名稱:OfficeTools.Pdf2Image.Word2Image,代碼行數:53,代碼來源:Program.cs

示例10: testPageResources

        public void testPageResources()
        {
            string testFile = TestResourceUtils.GetResourceAsTempFile(TEST_RESOURCES_PATH, "getLinkTest2.pdf");
            String filename = testFile;
            PdfReader rdr = new PdfReader(new RandomAccessFileOrArray(filename), new byte[0]);

            PdfDictionary pageResFromNum = rdr.GetPageResources(1);
            PdfDictionary pageResFromDict = rdr.GetPageResources(rdr.GetPageN(1));
            // same size & keys
            Assert.IsTrue(pageResFromNum.Keys.Equals(pageResFromDict.Keys));

            rdr.Close();
        }
開發者ID:smartleos,項目名稱:itextsharp,代碼行數:13,代碼來源:PdfReaderTest.cs

示例11: extractSnippets

 public void extractSnippets(String src, String dest)
 {
     TextWriter output = new StreamWriter(new FileStream(dest, FileMode.Create));
     PdfReader reader = new PdfReader(src);
     IRenderListener listener = new MyTextRenderListener(output);
     PdfContentStreamProcessor processor =
         new PdfContentStreamProcessor(listener);
     PdfDictionary pageDic = reader.GetPageN(1);
     PdfDictionary resourcesDic = pageDic.GetAsDict(PdfName.RESOURCES);
     processor.ProcessContent(ContentByteUtils.GetContentBytesForPage(reader, 1), resourcesDic);
     output.Flush();
     output.Close();
     reader.Close();
 }
開發者ID:Niladri24dutta,項目名稱:itextsharp,代碼行數:14,代碼來源:S05_ExtractSnippets.cs

示例12: TrimPDFFile

 public void TrimPDFFile(Stream outputStream, Stream inputStream, PageLayout pageLayout)
 {
     using (var reader = new PdfReader(inputStream))
     {
         var inputPageSize = reader.GetPageSize(1);
         var inputPage = reader.GetPageN(1);
         inputPage.Put(PdfName.MEDIABOX, new PdfRectangle(PageLayoutA4.GetLabelRect(0)));
         using (var stamper = new PdfStamper(reader, outputStream))
         {
             stamper.Writer.CloseStream = false;
             stamper.MarkUsed(inputPage);
         }
     }
 }
開發者ID:markdevel,項目名稱:clicklabel,代碼行數:14,代碼來源:PdfManip.cs

示例13: ManipulatePdf

// --------------------------------------------------------------------------- 
    /**
     * Manipulates a PDF file src with the file dest as result
     * @param src the original PDF
     */
    public byte[] ManipulatePdf(byte[] src) {
      PdfReader reader = new PdfReader(src);
      int n = reader.NumberOfPages;
      PdfDictionary pageDict;
      PdfRectangle rect = new PdfRectangle(55, 76, 560, 816);
      for (int i = 1; i <= n; i++) {
        pageDict = reader.GetPageN(i);
        pageDict.Put(PdfName.CROPBOX, rect);
      }
      using (MemoryStream ms = new MemoryStream()) {
        using (PdfStamper stamper = new PdfStamper(reader, ms)) {
        }
        return ms.ToArray();
      }
    }
開發者ID:kuujinbo,項目名稱:iTextInAction2Ed,代碼行數:20,代碼來源:CropPages.cs

示例14: ManipulatePdf

// --------------------------------------------------------------------------- 
    /**
     * Manipulates a PDF file src
     * @param src the original PDF
     */
    public byte[] ManipulatePdf(byte[] src) {
      PdfReader reader = new PdfReader(src);
      int n = reader.NumberOfPages;
      int rot;
      PdfDictionary pageDict;
      for (int i = 1; i <= n; i++) {
        rot = reader.GetPageRotation(i);
        pageDict = reader.GetPageN(i);
        pageDict.Put(PdfName.ROTATE, new PdfNumber(rot + 90));        
      }        
      using (MemoryStream ms = new MemoryStream()) {
        using (PdfStamper stamper = new PdfStamper(reader, ms)) {
        }
        return ms.ToArray();
      }
    }
開發者ID:,項目名稱:,代碼行數:21,代碼來源:

示例15: ManipulatePdf

 public void ManipulatePdf(string src, string dest)
 {
     PdfReader reader = new PdfReader(src);
     // We assume that there's a single large picture on the first page
     PdfDictionary page = reader.GetPageN(1);
     PdfDictionary resources = page.GetAsDict(PdfName.RESOURCES);
     PdfDictionary xobjects = resources.GetAsDict(PdfName.XOBJECT);
     Dictionary<PdfName, PdfObject>.KeyCollection.Enumerator enumerator = xobjects.Keys.GetEnumerator();
     enumerator.MoveNext();
     PdfName imgName = enumerator.Current;
     Image img = Image.GetInstance((PRIndirectReference) xobjects.GetAsIndirectObject(imgName));
     img.SetAbsolutePosition(0, 0);
     img.ScaleAbsolute(reader.GetPageSize(1));
     PdfStamper stamper = new PdfStamper(reader, new FileStream(dest,FileMode.Create));
     stamper.GetOverContent(1).AddImage(img);
     stamper.Close();
     reader.Close();
 }
開發者ID:newlysoft,項目名稱:itextsharp,代碼行數:18,代碼來源:RepeatImage.cs


注:本文中的iTextSharp.text.pdf.PdfReader.GetPageN方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。