public virtual void TestFreeReference() { PdfWriter writer = new PdfWriter(destinationFolder + "freeReference.pdf", new WriterProperties().SetFullCompressionMode (false)); PdfDocument pdfDocument = new PdfDocument(new PdfReader(sourceFolder + "baseFreeReference.pdf"), writer); pdfDocument.GetPage(1).GetResources().GetPdfObject().GetAsArray(new PdfName("d")).Get(0).GetIndirectReference ().SetFree(); PdfStream pdfStream = new PdfStream(); pdfStream.SetData(new byte[] { 24, 23, 67 }); pdfStream.MakeIndirect(pdfDocument); pdfDocument.GetPage(1).GetResources().GetPdfObject().GetAsArray(new PdfName("d")).Add(pdfStream); pdfDocument.Close(); NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(destinationFolder + "freeReference.pdf", sourceFolder + "cmp_freeReference.pdf", destinationFolder, "diff_")); }
public virtual void FullCompressionAppendMode() { PdfWriter writer = new PdfWriter(destinationFolder + "fullCompressionAppendMode.pdf", new WriterProperties ().SetFullCompressionMode(true).SetCompressionLevel(CompressionConstants.NO_COMPRESSION)); PdfDocument pdfDocument = new PdfDocument(new PdfReader(sourceFolder + "fullCompressionDoc.pdf"), writer, new StampingProperties().UseAppendMode()); PdfPage page = pdfDocument.GetPage(1); PdfStream contentStream = new PdfStream(); String contentStr = iText.IO.Util.JavaUtil.GetStringForBytes(pdfDocument.GetPage(1).GetFirstContentStream( ).GetBytes(), Encoding.ASCII); contentStream.SetData(contentStr.Replace("/F1 16", "/F1 24").GetBytes(Encoding.ASCII)); page.GetPdfObject().Put(PdfName.Contents, contentStream); page.SetModified(); pdfDocument.Close(); NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(destinationFolder + "fullCompressionAppendMode.pdf" , sourceFolder + "cmp_fullCompressionAppendMode.pdf", destinationFolder, "diff_")); PdfDocument assertDoc = new PdfDocument(new PdfReader(destinationFolder + "fullCompressionAppendMode.pdf") ); NUnit.Framework.Assert.IsTrue(assertDoc.GetPdfObject(9).IsStream()); NUnit.Framework.Assert.AreEqual(1, ((PdfDictionary)assertDoc.GetPdfObject(9)).GetAsNumber(PdfName.N).IntValue ()); }