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


C# PdfReader.ReleasePage方法代碼示例

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


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

示例1: Extract

        public static String Extract(String url, String saveTo = null)
        {
            try
            {
                WebClient wc = new WebClient();
                byte[] data = wc.DownloadData(url);

                // 如果設置了保存到文件,則寫入文件
                if (!String.IsNullOrWhiteSpace(saveTo) && data != null && data.Length > 0)
                {
                    if (!Directory.Exists(saveTo))
                    {
                        Directory.CreateDirectory(saveTo);
                    }
                    String file = GeneratePath(saveTo, url);
                    try
                    {
                        using (FileStream fs = new FileStream(file, FileMode.CreateNew))
                        {
                            fs.Write(data, 0, data.Length);
                        }
                    }
                    catch (IOException ioe)
                    {
                    }
                }

                using (PdfReader reader = new PdfReader(data))
                {
                    try
                    {
                        StringBuilder sb = new StringBuilder();
                        ITextExtractionStrategy extract = new SimpleTextExtractionStrategy();
                        for (int i = 1; i <= reader.NumberOfPages; i++)
                        {
                            sb.Append(PdfTextExtractor.GetTextFromPage(reader, i, extract));
                            reader.ReleasePage(i);
                        }                                            
                        return sb.ToString();
                    }
                    finally
                    {
                        if (reader != null)
                        {
                            reader.Close();
                        }
                    }
                }
            }
            catch (Exception e)
            {
                return String.Empty;
            }
        }
開發者ID:TaikorInc,項目名稱:FalcoA,代碼行數:54,代碼來源:PdfParser.cs

示例2: GetBookmark

 /**
 * Gets a <CODE>List</CODE> with the bookmarks that are children of <CODE>outline</CODE>. It returns <CODE>null</CODE> if
 * the document doesn't have any bookmarks.
 * @param reader the document
 * @param outline the outline dictionary to get bookmarks from
 * @param includeRoot indicates if to include <CODE>outline</CODE> parameter itself into returned list of bookmarks
 * @return a <CODE>List</CODE> with the bookmarks or <CODE>null</CODE> if the
 * document doesn't have any
 */
 public static IList<Dictionary<String, Object>> GetBookmark(PdfReader reader, PdfDictionary outline, bool includeRoot) {
     if (outline == null)
         return null;
     IntHashtable pages = new IntHashtable();
     int numPages = reader.NumberOfPages;
     for (int k = 1; k <= numPages; ++k) {
         pages[reader.GetPageOrigRef(k).Number] = k;
         reader.ReleasePage(k);
     }
     if (includeRoot)
         return BookmarkDepth(reader, outline, pages, true);
     else
         return BookmarkDepth(reader, (PdfDictionary)PdfReader.GetPdfObjectRelease(outline.Get(PdfName.FIRST)), pages, false);
 }
開發者ID:joshaxey,項目名稱:Simple-PDFMerge,代碼行數:23,代碼來源:SimpleBookmark.cs

示例3: GetBookmark

 /**
 * Gets a <CODE>List</CODE> with the bookmarks. It returns <CODE>null</CODE> if
 * the document doesn't have any bookmarks.
 * @param reader the document
 * @return a <CODE>List</CODE> with the bookmarks or <CODE>null</CODE> if the
 * document doesn't have any
 */    
 public static IList<Dictionary<String, Object>> GetBookmark(PdfReader reader) {
     PdfDictionary catalog = reader.Catalog;
     PdfObject obj = PdfReader.GetPdfObjectRelease(catalog.Get(PdfName.OUTLINES));
     if (obj == null || !obj.IsDictionary())
         return null;
     PdfDictionary outlines = (PdfDictionary)obj;
     IntHashtable pages = new IntHashtable();
     int numPages = reader.NumberOfPages;
     for (int k = 1; k <= numPages; ++k) {
         pages[reader.GetPageOrigRef(k).Number] = k;
         reader.ReleasePage(k);
     }
     return BookmarkDepth(reader, (PdfDictionary)PdfReader.GetPdfObjectRelease(outlines.Get(PdfName.FIRST)), pages);
 }
開發者ID:,項目名稱:,代碼行數:21,代碼來源:


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