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


C# PdfStamper.SetFullCompression方法代碼示例

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


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

示例1: Post

        /// <summary>
        /// Compress a pdf
        /// </summary>
        /// <param name="base64Pdf">A small model to hold a base64 encoded pdf object { "content" : "somebase64" }</param>
        /// <returns>{ "content" : "smallerBase64" }</returns>
        public IHttpActionResult Post(Base64Pdf base64Pdf)
        {
            try
            {
                if (base64Pdf.data == null)
                    return BadRequest("Check supplied pdf model");

                byte[] data = Convert.FromBase64String(base64Pdf.data);

                //Compress
                byte[] compressedData;
                using (var memStream = new MemoryStream())
                {
                    var reader = new PdfReader(data);
                    var stamper = new PdfStamper(reader, memStream, PdfWriter.VERSION_1_4);
                    var pageNum = reader.NumberOfPages;

                    for (var i = 1; i <= pageNum; i++)
                        reader.SetPageContent(i, reader.GetPageContent(i));

                    stamper.SetFullCompression();
                    stamper.Close();
                    reader.Close();

                    compressedData = memStream.ToArray();
                }
                var compressedBase64 = Convert.ToBase64String(compressedData);

                return Json(new Base64Pdf { data = compressedBase64 });
            }
            catch (Exception ex)
            {
                return InternalServerError(ex);
            }
        }
開發者ID:penance316,項目名稱:CompressPdfWebApi,代碼行數:40,代碼來源:PdfController.cs

示例2: CompressPdf

// ---------------------------------------------------------------------------
    /**
     * Manipulates a PDF file src with the file dest as result
     * @param src the original PDF
     */
    public byte[] CompressPdf(byte[] src) {
      PdfReader reader = new PdfReader(src);
      using (MemoryStream ms = new MemoryStream()) {
        using (PdfStamper stamper = 
            new PdfStamper(reader, ms, PdfWriter.VERSION_1_5))
        {
          stamper.Writer.CompressionLevel = 9;
          int total = reader.NumberOfPages + 1;
          for (int i = 1; i < total; i++) {
            reader.SetPageContent(i, reader.GetPageContent(i));
          }
          stamper.SetFullCompression();
        }
        return ms.ToArray();
      }
    }
開發者ID:,項目名稱:,代碼行數:21,代碼來源:


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