本文整理匯總了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);
}
}
示例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();
}
}