PdfStamper implements PdfViewerPreferences, PdfEncryptionSettings { public void close() throws DocumentException, IOException { if (stamper.closed) return; if (!hasSignature) { mergeVerification(); stamper.close(moreInfo); } else { throw new DocumentException("Signature defined. Must be closed in PdfSignatureAppearance."); } } PdfStamper(final PdfReader reader, final OutputStream os);  PdfStamper(final PdfReader reader, final OutputStream os, final char pdfVersion);  PdfStamper(final PdfReader reader, final OutputStream os, final char pdfVersion, final boolean append); protected  PdfStamper(); Map<String, String> getMoreInfo(); void setMoreInfo(final Map<String, String> moreInfo); void replacePage(final PdfReader r, final int pageImported, final int pageReplaced); void insertPage(final int pageNumber, final Rectangle mediabox); PdfSignatureAppearance getSignatureAppearance(); XmlSignatureAppearance getXmlSignatureAppearance(); void flush(); void close(); PdfContentByte getUnderContent(final int pageNum); PdfContentByte getOverContent(final int pageNum); boolean isRotateContents(); void setRotateContents(final boolean rotateContents); void setEncryption(final byte userPassword[], final byte ownerPassword[], final int permissions, final boolean strength128Bits); void setEncryption(final byte userPassword[], final byte ownerPassword[], final int permissions, final int encryptionType); void setEncryption(final boolean strength, final String userPassword, final String ownerPassword, final int permissions); void setEncryption(final int encryptionType, final String userPassword, final String ownerPassword, final int permissions); void setEncryption(final Certificate[] certs, final int[] permissions, final int encryptionType); PdfImportedPage getImportedPage(final PdfReader reader, final int pageNumber); PdfWriter getWriter(); PdfReader getReader(); AcroFields getAcroFields(); void setFormFlattening(final boolean flat); void setFreeTextFlattening(final boolean flat); void setAnnotationFlattening(final boolean flat); void addAnnotation(final PdfAnnotation annot, final int page); PdfFormField addSignature(final String name, final int page, final float llx, final float lly, final float urx, final float ury); void addComments(final FdfReader fdf); void setOutlines(final List<HashMap<String, Object>> outlines); void setThumbnail(final Image image, final int page); boolean partialFormFlattening(final String name); void addJavaScript(final String js); void addJavaScript(final String name, final String js); void addFileAttachment(final String description, final byte fileStore[], final String file, final String fileDisplay); void addFileAttachment(final String description, final PdfFileSpecification fs); void makePackage( final PdfName initialView ); void makePackage(final PdfCollection collection); void setViewerPreferences(final int preferences); void addViewerPreference(final PdfName key, final PdfObject value); void setXmpMetadata(final byte[] xmp); void createXmpMetadata(); XmpWriter getXmpWriter(); boolean isFullCompression(); void setFullCompression(); void setPageAction(final PdfName actionType, final PdfAction action, final int page); void setDuration(final int seconds, final int page); void setTransition(final PdfTransition transition, final int page); static PdfStamper createSignature(final PdfReader reader, final OutputStream os, final char pdfVersion, File tempFile, final boolean append); static PdfStamper createSignature(final PdfReader reader, final OutputStream os, final char pdfVersion); static PdfStamper createSignature(final PdfReader reader, final OutputStream os, final char pdfVersion, final File tempFile); static PdfStamper createXmlSignature(final PdfReader reader, final OutputStream os); Map<String, PdfLayer> getPdfLayers(); void markUsed(PdfObject obj); LtvVerification getLtvVerification(); boolean addNamedDestination(final String name, final int page, final PdfDestination dest);  }
@Test public void setPageContentTest01() throws IOException, DocumentException, InterruptedException { String outPdf = DEST_FOLDER + "out1.pdf"; String testFile = RESOURCE_FOLDER + "in.pdf"; PdfReader reader = new PdfReader(testFile); PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(outPdf)); reader.eliminateSharedStreams(); int total = reader.getNumberOfPages() + 1; for (int i = 1; i < total; i++) { byte[] bb = reader.getPageContent(i); reader.setPageContent(i, bb); } stamper.close(); Assert.assertNull(new CompareTool().compareByContent(outPdf, RESOURCE_FOLDER + "cmp_out1.pdf", DEST_FOLDER, "diff_")); }
@Test public void setPageContentTest02() throws IOException, DocumentException, InterruptedException { String outPdf = DEST_FOLDER + "out2.pdf"; String testFile = RESOURCE_FOLDER + "in.pdf"; PdfReader reader = new PdfReader(testFile); PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(outPdf)); int total = reader.getNumberOfPages() + 1; for (int i = 1; i < total; i++) { byte[] bb = reader.getPageContent(i); reader.setPageContent(i, bb); } reader.removeUnusedObjects(); stamper.close(); Assert.assertNull(new CompareTool().compareByContent(outPdf, RESOURCE_FOLDER + "cmp_out2.pdf", DEST_FOLDER, "diff_")); }