本文整理匯總了C#中iTextSharp.text.pdf.PdfReader.RemoveUnusedObjects方法的典型用法代碼示例。如果您正苦於以下問題:C# PdfReader.RemoveUnusedObjects方法的具體用法?C# PdfReader.RemoveUnusedObjects怎麽用?C# PdfReader.RemoveUnusedObjects使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類iTextSharp.text.pdf.PdfReader
的用法示例。
在下文中一共展示了PdfReader.RemoveUnusedObjects方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: CreatePdf
void CreatePdf(string input_path, IList<int> pages, string output_path)
{
// open a reader for the source file
PdfReader reader = new PdfReader(input_path);
try
{
reader.RemoveUnusedObjects();
// get output file
using (var fs = new FileStream(output_path, FileMode.Create, FileAccess.Write))
{
// create input document
var input_doc = new iTextSharp.text.Document(reader.GetPageSizeWithRotation(pages[0]));
// create the writer
PdfWriter writer = PdfWriter.GetInstance(input_doc, fs);
try
{
writer.SetFullCompression();
input_doc.Open();
try
{
// for each page copy the page directly from the reader into the writer
PdfContentByte cb = writer.DirectContent;
foreach (int page_number in pages)
{
input_doc.SetPageSize(reader.GetPageSizeWithRotation(page_number));
input_doc.NewPage();
PdfImportedPage page = writer.GetImportedPage(reader, page_number);
int rotation = reader.GetPageRotation(page_number);
if (rotation == 90 || rotation == 270)
cb.AddTemplate(page, 0, -1f, 1f, 0, 0, reader.GetPageSizeWithRotation(page_number).Height);
else
cb.AddTemplate(page, 1f, 0, 0, 1f, 0, 0);
}
}
finally
{
input_doc.Close();
}
}
finally
{
writer.Close();
}
}
}
finally
{
reader.Close();
}
}
示例2: ManipulatePdf
/**
* Removes the embedded font
*/
public void ManipulatePdf(String src, String dest)
{
CreatePdf(src);
// we create a reader instance
PdfReader reader = new PdfReader(src);
// we loop over all objects
PdfObject obj;
for (int i = 1; i < reader.XrefSize; i++)
{
obj = reader.GetPdfObject(i);
// we skip all objects that aren't a dictionary
if (obj == null || !obj.IsDictionary())
continue;
// we process all dictionaries
UnembedTTF((PdfDictionary) obj);
}
// removing unused objects will remove unused font file streams
reader.RemoveUnusedObjects();
// we persist the altered document
Stream os = new FileStream(dest, FileMode.Create);
PdfStamper stamper = new PdfStamper(reader, os);
stamper.Close();
}
示例3: SetPageContentTest02
public void SetPageContentTest02() {
String outPdf = DestFolder + "out2.pdf";
PdfReader reader = new PdfReader(TestResourceUtils.GetResourceAsStream(TestResourcesPath, "in.pdf"));
PdfStamper stamper = new PdfStamper(reader, new FileStream(outPdf, FileMode.Create));
int total = reader.NumberOfPages + 1;
for (int i = 1; i < total; i++) {
byte[] bb = reader.GetPageContent(i);
reader.SetPageContent(i, bb);
}
reader.RemoveUnusedObjects();
stamper.Close();
String s = new CompareTool().CompareByContent(outPdf, TestResourceUtils.GetResourceAsTempFile(TestResourcesPath, "cmp_out2.pdf"), DestFolder, "diff_");
Assert.Null(s);
}
示例4: 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();
}