String[] files = { MovieLinks1.RESULT, MovieHistory.RESULT }; // step 1 Document document = new Document(); // step 2 PdfCopy copy = new PdfCopy(document, new FileOutputStream(RESULT)); // step 3 document.open(); // step 4 PdfReader reader; int n; // loop over the documents you want to concatenate for (int i = 0; i < files.length; i++) { reader = new PdfReader(files[i]); // loop over the pages in that document n = reader.getNumberOfPages(); for (int page = 0; page < n; ) { copy.addPage(copy.getImportedPage(reader, ++page)); } copy.freeReader(reader); reader.close(); } // step 5 document.close();
String inFile = args[0].toLowerCase(); System.out.println ("Reading " + inFile); PdfReader reader = new PdfReader(inFile); int n = reader.getNumberOfPages(); System.out.println ("Number of pages : " + n); int i = 0; + "-" + String.format("%03d", i + 1) + ".pdf"; System.out.println ("Writing " + outFile); Document document = new Document(reader.getPageSizeWithRotation(1)); PdfCopy writer = new PdfCopy(document, new FileOutputStream(outFile)); document.open(); PdfImportedPage page = writer.getImportedPage(reader, ++i); writer.addPage(page); document.close(); writer.close();
PdfObject direct = PdfReader.getPdfObject(indirect);
/** * Initialize opens the document for reading. This is done implicitly * by the constuctor. This should only need to be called directly following * a reset. * @throws IOException */ protected void initialize() throws IOException{ if(document != null){ documentReader = new PdfReader(document); } catalog = documentReader.getCatalog(); }
int efficientPDFPageCount(String path) { RandomAccessFileOrArray file = new RandomAccessFileOrArray(path, false, true ); PdfReader reader = new PdfReader(file); int ret = reader.getNumberOfPages(); reader.close(); return ret; }
PdfReader reader = new PdfReader(src); PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(dest)); stamper.insertPage(reader.getNumberOfPages() + 1, reader.getPageSizeWithRotation(1)); stamper.close(); reader.close();
public void resize (float x, float y, float scale) throws Exception { PdfReader reader = new PdfReader(pdfIn); Document doc = new Document(PageSize.LEGAL, 0, 0, 0, 0); PdfWriter writer = PdfWriter.getInstance(doc, new FileOutputStream(pdfOut)); doc.open(); PdfContentByte cb = writer.getDirectContent(); for(int i=1; i<=reader.getNumberOfPages(); i++){ doc.newPage(); PdfImportedPage page = writer.getImportedPage(reader, i); cb.addTemplate(page, scale, 0, 0, scale, x, y); } doc.close(); }
public void addAnnotation(String src, String dest) throws IOException, DocumentException { PdfReader reader = new PdfReader(src); PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(dest), '\0', true); PdfAnnotation comment = PdfAnnotation.createText(stamper.getWriter(), new Rectangle(200, 800, 250, 820), "Finally Signed!", "Bruno Specimen has finally signed the document", true, "Comment"); stamper.addAnnotation(comment, 1); stamper.close(); }
public void manipulatePdf(String src, String dest) throws IOException, DocumentException { PdfReader.unethicalreading = true; PdfReader reader = new PdfReader(src); PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(dest)); stamper.close(); reader.close(); }
PdfReader reader = new PdfReader(pdf); PrintWriter out = new PrintWriter(new FileOutputStream(txt)); Rectangle rect = new Rectangle(70, 80, 490, 580); RenderFilter filter = new RegionTextRenderFilter(rect); TextExtractionStrategy strategy; for (int i = 1; i <= reader.getNumberOfPages(); i++) { strategy = new FilteredTextRenderListener(new LocationTextExtractionStrategy(), filter); out.println(PdfTextExtractor.getTextFromPage(reader, i, strategy)); } out.flush(); out.close(); reader.close();
while (f < args.length-1) { PdfReader reader = new PdfReader(args[f]); reader.consolidateNamedDestinations(); int n = reader.getNumberOfPages(); List bookmarks = SimpleBookmark.getBookmark(reader); if (bookmarks != null) { document = new Document(reader.getPageSizeWithRotation(1)); writer = new PdfCopy(document, new FileOutputStream(outFile), Calendar.getInstance());
public void makeImageFromPDF throws DocumentException, IOException { String INPUTFILE = Environment.getExternalStorageDirectory() .getAbsolutePath()+"/YOUR_DIRECTORY/inputFile.pdf"; String OUTPUTFILE = Environment.getExternalStorageDirectory() .getAbsolutePath()+"/YOUR_DIRECTORY/outputFile.pdf"; Document document = new Document(); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(OUTPUTFILE)); document.open(); PdfReader reader = new PdfReader(INPUTFILE); int n = reader.getNumberOfPages(); PdfImportedPage page; // Traversing through all the pages for (int i = 1; i <= n; i++) { page = writer.getImportedPage(reader, i); Image instance = Image.getInstance(page); //Save a specific page threshold for displaying in a scroll view inside your App } document.close(); }
public void manipulatePdf(String src, String dest) throws IOException, DocumentException { PdfReader reader = new PdfReader(src); PdfDictionary root = reader.getCatalog(); PdfDictionary names = root.getAsDict(PdfName.NAMES); names.remove(PdfName.EMBEDDEDFILES); PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(dest)); stamper.close(); }
PdfReader cover = new PdfReader("hero.pdf"); PdfReader reader = new PdfReader("pages.pdf"); Document document = new Document(); PdfCopy copy = new PdfCopy(document, new FileOutputStream("pages_with_cover.pdf")); document.open(); copy.addDocument(cover); copy.addDocument(reader); document.close(); cover.close(); reader.close();
Document doc = new Document(); PdfSmartCopy copy = new PdfSmartCopy(doc, new FileOutputStream("result.pdf")); doc.open(); copyPdf(i); reader = new PdfReader(String.format("%d%s", i, "template.pdf")); baos = new ByteArrayOutputStream(); stamper = new PdfStamper(reader, baos); stamper.close(); reader = new PdfReader(baos.toByteArray()); copy.addPage(copy.getImportedPage(reader, 1)); PdfReader reader = new PdfReader("timesheet.pdf"); Document doc = new Document(); File file = new File(String.format("%d%s", currentPage, "template.pdf")); file.deleteOnExit(); PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(file)); stamper.close();
String in = "Original.pdf"; String out = "Original.pdf"; PdfReader reader = new PdfReader(in); ByteArrayOutputStream baos = new ByteArrayOutputStream(); PdfStamper stamper = new PdfStamper(reader, baos ); int totalPages = reader.getNumberOfPages(); stamper.insertPage(totalPages + 1, PageSize.A4); stamper.addAnnotation(PdfAnnotation.createText(stamper.getWriter(), new Rectangle(30f, 750f, 80f, 800f), "inserted page", "This page is the title page.", true, null), reader.getNumberOfPages()); stamper.close(); FileOutputStream fileOutputStream = new FileOutputStream(out); IOUtils.write(baos.toByteArray(), fileOutputStream);
PdfReader reader = new PdfReader(pdf); PrintWriter out= new PrintWriter(new FileOutputStream(txt)); //Creating the rectangle Rectangle rect=new Rectangle(70,80,420,500); //creating a filter based on the rectangle RenderFilter filter = new RegionTextRenderFilter(rect); TextExtractionStrategy strategy; for(int i=1;i<=reader.getNumberOfPages();i+){ //setting the filter on the text extraction strategy strategy= new FilteredTextRenderListener( new LocationTextExtractionStrategy(),filter); out.println(PdfTextExtractor.getTextFromPage(reader,i,strategy)); } out.flush();out.close();
public void manipulatePdf(String src, String dest) throws IOException, DocumentException { PdfReader reader = new PdfReader(src); PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(dest)); // Here we define the location: Rectangle linkLocation = new Rectangle(320, 695, 560, 741); // here we add the actual content at this location: ColumnText ct = new ColumnText(stamper.getOverContent(1)); ct.setSimpleColumn(linkLocation); ct.addElement(new Paragraph("This is a link. Click it and you'll be forwarded to another page in this document.")); ct.go(); // now we create the link that will jump to a specific destination: PdfDestination destination = new PdfDestination(PdfDestination.FIT); PdfAnnotation link = PdfAnnotation.createLink(stamper.getWriter(), linkLocation, PdfAnnotation.HIGHLIGHT_INVERT, 3, destination); // If you don't want a border, here's where you remove it: link.setBorder(new PdfBorderArray(0, 0, 0)); // We add the link (that is the clickable area, not the text!) stamper.addAnnotation(link, 1); stamper.close(); reader.close(); }
public void sign(String src, String dest, Certificate[] chain, PrivateKey pk, String digestAlgorithm, String provider, CryptoStandard subfilter, String reason, String location) throws GeneralSecurityException, IOException, DocumentException { // Creating the reader and the stamper PdfReader reader = new PdfReader(src); FileOutputStream os = new FileOutputStream(dest); PdfStamper stamper = PdfStamper.createSignature(reader, os, '\0'); // Creating the appearance PdfSignatureAppearance appearance = stamper.getSignatureAppearance(); appearance.setReason(reason); appearance.setLocation(location); appearance.setVisibleSignature(new Rectangle(36, 748, 144, 780), 1, "sig"); // Creating the signature ExternalDigest digest = new BouncyCastleDigest(); ExternalSignature signature = new PrivateKeySignature(pk, digestAlgorithm, provider); MakeSignature.signDetached(appearance, digest, signature, chain, null, null, null, 0, subfilter); }
static public void sign(String src, String dest, Certificate[] chain, PrivateKey pk, String digestAlgorithm, String provider, MakeSignature.CryptoStandard subfilter, String reason, String location) throws GeneralSecurityException, IOException, DocumentException { // Creating the reader and the stamper PdfReader reader = new PdfReader(src); FileOutputStream os = new FileOutputStream(dest); PdfAStamper stamper = PdfAStamper.createSignature(reader, os, '\0', PdfAConformanceLevel.PDF_A_1B); // Creating the appearance PdfSignatureAppearance appearance = stamper.getSignatureAppearance(); appearance.setLayer2Font(FontFactory.getFont("FreeMonoBold.ttf", BaseFont.WINANSI, BaseFont.EMBEDDED, 12)); appearance.setReason(reason); appearance.setLocation(location); appearance.setVisibleSignature(new Rectangle(36, 748, 144, 780), 1, "sig"); ICC_Profile icc = ICC_Profile.getInstance(new FileInputStream("sRGB Color Space Profile.icm")); stamper.getWriter().setOutputIntents("Custom", "", "http://www.color.org", "sRGB IEC61966-2.1", icc); // Creating the signature ExternalDigest digest = new BouncyCastleDigest(); ExternalSignature signature = new PrivateKeySignature(pk, digestAlgorithm, provider); MakeSignature.signDetached(appearance, digest, signature, chain, null, null, null, 0, subfilter); }