public virtual void CopyObject5() { PdfDocument pdfDoc1 = new PdfDocument(new PdfWriter(destinationFolder + "copyObject5_1.pdf")); PdfPage page1 = pdfDoc1.AddNewPage(); page1.GetContentStream(0).GetOutputStream().Write(ByteUtils.GetIsoBytes("%Page_1")); page1.Flush(); pdfDoc1.Close(); PdfDocument pdfDoc1R = new PdfDocument(new PdfReader(destinationFolder + "copyObject5_1.pdf")); page1 = pdfDoc1R.GetPage(1); PdfDocument pdfDoc2 = new PdfDocument(new PdfWriter(destinationFolder + "copyObject5_2.pdf")); PdfPage page2 = page1.CopyTo(pdfDoc2); pdfDoc2.AddPage(page2); page2.Flush(); page2 = pdfDoc2.AddNewPage(); page2.GetContentStream(0).GetOutputStream().Write(ByteUtils.GetIsoBytes("%Page_2")); page2.Flush(); pdfDoc1R.Close(); pdfDoc2.Close(); PdfReader reader = new PdfReader(destinationFolder + "copyObject5_2.pdf"); PdfDocument pdfDocument = new PdfDocument(reader); NUnit.Framework.Assert.AreEqual(false, reader.HasRebuiltXref(), "Rebuilt"); NUnit.Framework.Assert.AreEqual(8, reader.trailer.GetAsNumber(PdfName.Size).IntValue()); byte[] bytes = pdfDocument.GetPage(1).GetContentBytes(); // getting content bytes results in adding '\n' for each content stream // so we should compare String with '\n' at the end NUnit.Framework.Assert.AreEqual(ByteUtils.GetIsoBytes("%Page_1\n"), bytes); bytes = pdfDocument.GetPage(2).GetContentBytes(); NUnit.Framework.Assert.AreEqual(ByteUtils.GetIsoBytes("%Page_2\n"), bytes); pdfDocument.Close(); }
public virtual void Copying2() { FileStream fos1 = new FileStream(destinationFolder + "copying2_1.pdf", FileMode.Create); PdfWriter writer1 = new PdfWriter(fos1); PdfDocument pdfDoc1 = new PdfDocument(writer1); for (int i = 0; i < 10; i++) { PdfPage page1 = pdfDoc1.AddNewPage(); page1.GetContentStream(0).GetOutputStream().Write(ByteUtils.GetIsoBytes("%page " + (i + 1).ToString() + "\n" )); page1.Flush(); } pdfDoc1.Close(); FileStream fis1 = new FileStream(destinationFolder + "copying2_1.pdf", FileMode.Open, FileAccess.Read); PdfReader reader1 = new PdfReader(fis1); pdfDoc1 = new PdfDocument(reader1); FileStream fos2 = new FileStream(destinationFolder + "copying2_2.pdf", FileMode.Create); PdfWriter writer2 = new PdfWriter(fos2); PdfDocument pdfDoc2 = new PdfDocument(writer2); for (int i_1 = 0; i_1 < 10; i_1++) { if (i_1 % 2 == 0) { pdfDoc2.AddPage(pdfDoc1.GetPage(i_1 + 1).CopyTo(pdfDoc2)); } } pdfDoc2.Close(); pdfDoc1.Close(); PdfReader reader = new PdfReader(destinationFolder + "copying2_2.pdf"); PdfDocument pdfDocument = new PdfDocument(reader); NUnit.Framework.Assert.AreEqual(false, reader.HasRebuiltXref(), "Rebuilt"); for (int i_2 = 0; i_2 < 5; i_2++) { byte[] bytes = pdfDocument.GetPage(i_2 + 1).GetContentBytes(); NUnit.Framework.Assert.AreEqual("%page " + (i_2 * 2 + 1).ToString() + "\n", iText.IO.Util.JavaUtil.GetStringForBytes (bytes)); } reader.Close(); }
public virtual void CopyObject5() { FileStream fos1 = new FileStream(destinationFolder + "copyObject5_1.pdf", FileMode.Create); PdfWriter writer1 = new PdfWriter(fos1); PdfDocument pdfDoc1 = new PdfDocument(writer1); PdfPage page1 = pdfDoc1.AddNewPage(); page1.GetContentStream(0).GetOutputStream().Write(ByteUtils.GetIsoBytes("%Page_1")); page1.Flush(); pdfDoc1.Close(); PdfDocument pdfDoc1R = new PdfDocument(new PdfReader(destinationFolder + "copyObject5_1.pdf")); page1 = pdfDoc1R.GetPage(1); FileStream fos2 = new FileStream(destinationFolder + "copyObject5_2.pdf", FileMode.Create); PdfWriter writer2 = new PdfWriter(fos2); PdfDocument pdfDoc2 = new PdfDocument(writer2); PdfPage page2 = page1.CopyTo(pdfDoc2); pdfDoc2.AddPage(page2); page2.Flush(); page2 = pdfDoc2.AddNewPage(); page2.GetContentStream(0).GetOutputStream().Write(ByteUtils.GetIsoBytes("%Page_2")); page2.Flush(); pdfDoc1R.Close(); pdfDoc2.Close(); PdfReader reader = new PdfReader(destinationFolder + "copyObject5_2.pdf"); PdfDocument pdfDocument = new PdfDocument(reader); NUnit.Framework.Assert.AreEqual(false, reader.HasRebuiltXref(), "Rebuilt"); NUnit.Framework.Assert.AreEqual(8, reader.trailer.GetAsNumber(PdfName.Size).IntValue()); byte[] bytes = pdfDocument.GetPage(1).GetContentBytes(); NUnit.Framework.Assert.AreEqual(ByteUtils.GetIsoBytes("%Page_1"), bytes); bytes = pdfDocument.GetPage(2).GetContentBytes(); NUnit.Framework.Assert.AreEqual(ByteUtils.GetIsoBytes("%Page_2"), bytes); reader.Close(); }
public virtual void Copying2() { PdfDocument pdfDoc1 = new PdfDocument(new PdfWriter(destinationFolder + "copying2_1.pdf")); for (int i = 0; i < 10; i++) { PdfPage page1 = pdfDoc1.AddNewPage(); page1.GetContentStream(0).GetOutputStream().Write(ByteUtils.GetIsoBytes("%page " + (i + 1).ToString() + "\n" )); page1.Flush(); } pdfDoc1.Close(); pdfDoc1 = new PdfDocument(new PdfReader(destinationFolder + "copying2_1.pdf")); PdfDocument pdfDoc2 = new PdfDocument(new PdfWriter(destinationFolder + "copying2_2.pdf")); for (int i = 0; i < 10; i++) { if (i % 2 == 0) { pdfDoc2.AddPage(pdfDoc1.GetPage(i + 1).CopyTo(pdfDoc2)); } } pdfDoc2.Close(); pdfDoc1.Close(); PdfReader reader = new PdfReader(destinationFolder + "copying2_2.pdf"); PdfDocument pdfDocument = new PdfDocument(reader); NUnit.Framework.Assert.AreEqual(false, reader.HasRebuiltXref(), "Rebuilt"); for (int i = 0; i < 5; i++) { byte[] bytes = pdfDocument.GetPage(i + 1).GetContentBytes(); NUnit.Framework.Assert.AreEqual("%page " + (i * 2 + 1).ToString() + "\n", iText.IO.Util.JavaUtil.GetStringForBytes (bytes)); } pdfDocument.Close(); }