Examples of PdfReader


Examples of com.itextpdf.text.pdf.PdfReader

          newFileName, newFileExtDot, roomName, true, completeName);
    } else if (isPdf) {
      boolean isEncrypted = false;
      try {
        // Check if PDF is encrpyted
        PdfReader pdfReader = new PdfReader(completeName
            + newFileExtDot);

        log.debug("pdfReader.isEncrypted() :: "
            + pdfReader.isEncrypted());

        log.debug("isMetadataEncrypted : "
            + pdfReader.isMetadataEncrypted());
        log.debug("is128Key : " + pdfReader.is128Key());
        log.debug("isEncrypted : " + pdfReader.isEncrypted());

        if (pdfReader.isEncrypted()) {
          isEncrypted = true;
        }

      } catch (Exception err) {
        log.error("isEncrypted ", err);
View Full Code Here

Examples of com.itextpdf.text.pdf.PdfReader

        System.out.println("command is one of 'crop', 'twoup', 'booklet'");
    }

    private static void crop(String input) throws Exception {
        String output = input.replace(".pdf", "-crop.pdf");
        PdfReader reader = new PdfReader(input);
        final int n = reader.getNumberOfPages();
        Rectangle pageSize = reader.getPageSize(1);

        System.out.println("Input page size: " + pageSize);
        float left = (pageSize.getWidth() - kTextWidth) / 2 - kMargin;
        float right = pageSize.getWidth() - left;
        float bottom = (pageSize.getHeight() - kTextHeight) / 2;
        float top = pageSize.getHeight() - bottom;
        PdfRectangle rect = new PdfRectangle(left, bottom + kOffset, right, top + kOffset);
        for (int i = 1; i <= n; i++) {
            PdfDictionary pageDict = reader.getPageN(i);
            pageDict.put(PdfName.CROPBOX, rect);
        }
        PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(output));
        stamper.close();
    }
View Full Code Here

Examples of com.itextpdf.text.pdf.PdfReader

            return null;
    }

    private static void twoup(String input) throws Exception {
        String output = input.replace(".pdf", "-twoup.pdf");
        PdfReader reader = new PdfReader(input);
        int n = reader.getNumberOfPages();
        Rectangle pageSize = reader.getPageSize(1);

        System.out.println("Input page size: " + pageSize);
        Document doc = new Document(PageSize.A4.rotate(), 0, 0, 0, 0);
        PdfWriter writer = PdfWriter.getInstance(doc, new FileOutputStream(output));
        doc.open();
View Full Code Here

Examples of com.itextpdf.text.pdf.PdfReader

        cb.stroke();
    }

    private static void booklet(String input) throws Exception {
        String output = input.replace(".pdf", "-booklet.pdf");
        PdfReader reader = new PdfReader(input);
        int n = reader.getNumberOfPages();
        Rectangle pageSize = reader.getPageSize(1);

        System.out.println("Input page size: " + pageSize);
        Document doc = new Document(PageSize.A4.rotate(), 0, 0, 0, 0);
        PdfWriter writer = PdfWriter.getInstance(doc, new FileOutputStream(output));
        doc.open();
View Full Code Here

Examples of com.itextpdf.text.pdf.PdfReader

        outPath = FileUtils.appendFileSeparator(outputDirectory.getPath());
        File decryptedPdf = new File(FileUtils.getFilePrefix(pdfFile) + "_decrypted.pdf");
        File info = new File(FileUtils.appendFileSeparator(outputDirectory.getPath()) + "info");
        int pageCount = 0;
        if (!info.exists()) {
            PdfReader reader = new PdfReader(pdfPath);
            pageCount = reader.getNumberOfPages();
           
            if(!decryptedPdf.exists()){
                // if pdf is a encrypted file unencrypted
                if (reader.isEncrypted()) {
                    LOGGER.debug("encrypted pdf! 准备另存");
                    pdfPath = PDFSecurer.decrypt(reader, FileUtils.getFilePrefix(pdfFile) + "_decrypted.pdf").getPath();
                    LOGGER.debug("PDF解密完成");
                } else {
                    LOGGER.debug("---文档未加密---");
                }
            }else {
                pdfPath = decryptedPdf.getPath();
            }

            reader.close();

            if (pageCount != 0) {
                OutputStream out = null;
                try {

                    info.createNewFile();

                    out = new FileOutputStream(info);

                    out.write((pageCount + "").getBytes("UTF-8"));
                } finally {
                    if (out != null) {
                        out.flush();
                        out.close();
                    }
                }

            }
        } else {
            pdfPath = decryptedPdf.getPath();
           
            FileInputStream in = new FileInputStream(info);

            BufferedReader reader = new BufferedReader(new InputStreamReader(in, "UTF-8"));

            try {
                pageCount = Integer.parseInt(reader.readLine());
            } catch (Exception e) {
            } finally {
                reader.close();
                in.close();
            }
        }

        return new PDFConverterDeploy(outputDirectory, pageCount, COMMAND.replace("${in}", pdfPath)
View Full Code Here

Examples of com.itextpdf.text.pdf.PdfReader

        // Get the certificate chain.
        Certificate[] chain = keyStore.getCertificateChain(certificateAlias);

        // Open input file for reading.
        PdfReader reader = new PdfReader(inputFileName);

        // Open output file for writing.
        FileOutputStream output = new FileOutputStream(outputFileName);
        File temp = File.createTempFile("tmp", ".tmp");
        PdfStamper stamper = PdfStamper.createSignature(
View Full Code Here

Examples of com.itextpdf.text.pdf.PdfReader

        for (Object object : root) {
            rootCertificates.add((X509Certificate) object);
        }

        // Open the document for reading.
        PdfReader reader = new PdfReader(documentFileName);

        // Get the signatures in the document.
        AcroFields fields = reader.getAcroFields();
        ArrayList<String> signatures = fields.getSignatureNames();
        Map<String, PdfPKCS7> result = new LinkedHashMap<String, PdfPKCS7>();

        // Check if the input document is signed.
        if (signatures.size() == 0) {
View Full Code Here

Examples of com.itextpdf.text.pdf.PdfReader

    {
        // Initialize a Bouncy Castle security provider.
        Security.addProvider(new BouncyCastleProvider());

        // Open the document for reading.
        PdfReader reader = new PdfReader(documentFileName);

        // Get the signatures in the document.
        AcroFields fields = reader.getAcroFields();
        ArrayList<String> signatures = fields.getSignatureNames();
        Map<String, PdfPKCS7> result = new LinkedHashMap<String, PdfPKCS7>();

        // Get signature data encoded in PKCS #7 format for each signature.
        for (String signature : signatures) {
View Full Code Here

Examples of com.itextpdf.text.pdf.PdfReader

        for (Object object : collection) {
            rootCertificates.add((X509Certificate) object);
        }

        // Open input file for reading.
        PdfReader reader = new PdfReader(inputFileName);

        // Get the list of signatures in the document.
        AcroFields fields = reader.getAcroFields();
        ArrayList<String> signatures = fields.getSignatureNames();
        if (signatures.size() == 0) {
            throw new NoSignatureException(messages.getString(
                "Document_has_no_signature."));
        }
View Full Code Here

Examples of com.itextpdf.text.pdf.PdfReader

        for (Object object : root) {
            rootCertificates.add((X509Certificate) object);
        }

        // Open the document for reading.
        PdfReader reader = new PdfReader(documentFileName);

        // Get the signatures in the document.
        AcroFields fields = reader.getAcroFields();
        ArrayList<String> signatures = fields.getSignatureNames();
        if (signatures.size() == 0) {
            throw new NoSignatureException(messages.getString(
                "Document_has_no_signature."));
        }

        // Check if the last signature is a timestamp.
        String lastSignature = signatures.get(signatures.size() - 1);
        PdfPKCS7 pkcs7 = fields.verifySignature(lastSignature);
        if (!pkcs7.isTsp()) {
            throw new NoTimestampException(messages.getString(
                "Document_has_no_document_level_timestamp."));
        }

        // Get the expiration date of the last timestamp.
        Calendar expiration = Calendar.getInstance();
        expiration.setTime(pkcs7.getSigningCertificate().getNotAfter());

        // Validate last timestamp on the current date.
        SignatureValidator.validate(lastSignature, reader, rootCertificates);

        // Get OCSP responses and CRLs from DSS to validate old signatures.
        PdfDictionary dictionary = reader.getCatalog().getAsDict(PdfName.DSS);
        if (dictionary == null) {
            throw new NoDSSException(messages.getString(
                "Document_has_no_DSS_(Document_Security_Store)."));
        }
        PdfArray ocspArray = dictionary.getAsArray(PdfName.OCSPS);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.