Package com.lowagie.text.pdf

Examples of com.lowagie.text.pdf.PdfReader


     * @param inputCommand
     * @return temporary file with pages rotation
     */
    private File applyRotations(File inputFile, ConcatParsedCommand inputCommand) throws Exception {

        rotationReader = new PdfReader(inputFile.getAbsolutePath());
        rotationReader.removeUnusedObjects();
        rotationReader.consolidateNamedDestinations();

        int pdfNumberOfPages = rotationReader.getNumberOfPages();
        PageRotation[] rotations = inputCommand.getRotations();
View Full Code Here


      transitions = parseXmlInput(inputCommand.getInputXmlFile(), transitions);
      try{
        prefixParser = new PrefixParser(inputCommand.getOutputFilesPrefix(), inputCommand.getInputFile().getFile().getName());       
        File tmpFile = FileUtility.generateTmpFile(inputCommand.getOutputFile());
       
        pdfReader = new PdfReader(new RandomAccessFileOrArray(inputCommand.getInputFile().getFile().getAbsolutePath()),inputCommand.getInputFile().getPasswordBytes());
        pdfReader.removeUnusedObjects();
        pdfReader.consolidateNamedDestinations();
       
        //version
        LOG.debug("Creating a new document.");
View Full Code Here

     */
    public static void createSignatur(PrivateKey privateKey,
            Certificate[] chain, String originalPdfName, String outputPdfName)
            throws Exception {

        PdfReader reader = new PdfReader(originalPdfName);
        FileOutputStream fout = new FileOutputStream(outputPdfName);

        //createSignature(PdfReader reader, OutputStream os, char pdfVersion)
        //pdfVersion - the new pdf version or '\0' to keep the same version as
        // the original document
View Full Code Here

     * @param password password to open the file
     * @return the item to add to the table
     */
    PdfSelectionTableItem getPdfSelectionTableItem(File fileToAdd, String password, String pageSelection){
      PdfSelectionTableItem tableItem = null;
      PdfReader pdfReader = null;
        if (fileToAdd != null){
          tableItem = new PdfSelectionTableItem();
          tableItem.setInputFile(fileToAdd);
          tableItem.setPassword(password);
          tableItem.setPageSelection(pageSelection);
            try{
                //fix 04/11/08 for memory usage
               pdfReader = new PdfReader(new RandomAccessFileOrArray(fileToAdd.getAbsolutePath()), (password != null)?password.getBytes():null);                 
                 tableItem.setEncrypted(pdfReader.isEncrypted());
                 tableItem.setFullPermission(pdfReader.isOpenedWithFullPermissions());
                 if(tableItem.isEncrypted()){
                   tableItem.setPermissions(getPermissionsVerbose(pdfReader.getPermissions()));
                   int cMode = pdfReader.getCryptoMode();
                   switch (cMode){
                   case PdfWriter.STANDARD_ENCRYPTION_40:
                     tableItem.setEncryptionAlgorithm(EncryptionUtility.RC4_40);
                     break;
                   case PdfWriter.STANDARD_ENCRYPTION_128:
                     tableItem.setEncryptionAlgorithm(EncryptionUtility.RC4_128);
                     break;
                   case PdfWriter.ENCRYPTION_AES_128:
                     tableItem.setEncryptionAlgorithm(EncryptionUtility.AES_128);
                     break;
                   default:
                     break;                         
                   }
                 }
                 tableItem.setPagesNumber(Integer.toString(pdfReader.getNumberOfPages()));
                 tableItem.setFileSize(fileToAdd.length());
                 tableItem.setPdfVersion(pdfReader.getPdfVersion());
                 tableItem.setSyntaxErrors(pdfReader.isRebuilt());
                 initTableItemDocumentData(pdfReader, tableItem);
            }
            catch (Exception e){
              tableItem.setLoadedWithErrors(true);
              LOG.error(GettextResource.gettext(Configuration.getInstance().getI18nResourceBundle(),"Error loading ")+fileToAdd.getAbsolutePath()+" :", e);
            }
            finally{
              if(pdfReader != null){
                pdfReader.close();
          pdfReader = null;
              }
            }              
        }
        return tableItem;   
View Full Code Here

                String inputMimeType = null;
                if (dataResource != null) {
                    inputMimeType = dataResource.getString("mimeTypeId");
                }
                byte [] inputByteArray = null;
                PdfReader reader = null;
                if (inputMimeType != null && inputMimeType.equals("application/pdf")) {
                    ByteBuffer byteBuffer = DataResourceWorker.getContentAsByteBuffer(delegator, thisDataResourceId, https, webSiteId, locale, rootDir);
                    inputByteArray = byteBuffer.array();
                    reader = new PdfReader(inputByteArray);
                } else if (inputMimeType != null && inputMimeType.equals("text/html")) {
                    ByteBuffer byteBuffer = DataResourceWorker.getContentAsByteBuffer(delegator, thisDataResourceId, https, webSiteId, locale, rootDir);
                    inputByteArray = byteBuffer.array();
                    String s = new String(inputByteArray);
                    Debug.logInfo("text/html string:" + s, module);
                    continue;
                } else if (inputMimeType != null && inputMimeType.equals("application/vnd.ofbiz.survey.response")) {
                    String surveyResponseId = dataResource.getString("relatedDetailId");
                    String surveyId = null;
                    String acroFormContentId = null;
                    GenericValue surveyResponse = null;
                    if (UtilValidate.isNotEmpty(surveyResponseId)) {
                        surveyResponse = delegator.findByPrimaryKey("SurveyResponse", UtilMisc.toMap("surveyResponseId", surveyResponseId));
                        if (surveyResponse != null) {
                            surveyId = surveyResponse.getString("surveyId");
                        }
                    }
                    if (UtilValidate.isNotEmpty(surveyId)) {
                        GenericValue survey = delegator.findByPrimaryKey("Survey", UtilMisc.toMap("surveyId", surveyId));
                        if (survey != null) {
                            acroFormContentId = survey.getString("acroFormContentId");
                            if (UtilValidate.isNotEmpty(acroFormContentId)) {
                                // TODO: is something supposed to be done here?
                            }
                        }
                    }
                    if (surveyResponse != null) {
                        if (UtilValidate.isEmpty(acroFormContentId)) {
                            // Create AcroForm PDF
                            Map<String, Object> survey2PdfResults = dispatcher.runSync("buildPdfFromSurveyResponse", UtilMisc.toMap("surveyResponseId", surveyId));
                            if (ServiceUtil.isError(survey2PdfResults)) {
                                return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ContentSurveyErrorBuildingPDF", locale), null, null, survey2PdfResults);
                            }

                            ByteBuffer outByteBuffer = (ByteBuffer) survey2PdfResults.get("outByteBuffer");
                            inputByteArray = outByteBuffer.array();
                            reader = new PdfReader(inputByteArray);
                        } else {
                            // Fill in acroForm
                            Map<String, Object> survey2AcroFieldResults = dispatcher.runSync("setAcroFieldsFromSurveyResponse", UtilMisc.toMap("surveyResponseId", surveyResponseId));
                            if (ServiceUtil.isError(survey2AcroFieldResults)) {
                                return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ContentSurveyErrorSettingAcroFields", locale), null, null, survey2AcroFieldResults);
                            }

                            ByteBuffer outByteBuffer = (ByteBuffer) survey2AcroFieldResults.get("outByteBuffer");
                            inputByteArray = outByteBuffer.array();
                            reader = new PdfReader(inputByteArray);
                        }
                    }
                } else {
                    ByteBuffer inByteBuffer = DataResourceWorker.getContentAsByteBuffer(delegator, thisDataResourceId, https, webSiteId, locale, rootDir);

                    Map<String, Object> convertInMap = UtilMisc.<String, Object>toMap("userLogin", userLogin, "inByteBuffer", inByteBuffer, "inputMimeType", inputMimeType, "outputMimeType", "application/pdf");
                    if (UtilValidate.isNotEmpty(oooHost)) convertInMap.put("oooHost", oooHost);
                    if (UtilValidate.isNotEmpty(oooPort)) convertInMap.put("oooPort", oooPort);

                    Map<String, Object> convertResult = dispatcher.runSync("convertDocumentByteBuffer", convertInMap);

                    if (ServiceUtil.isError(convertResult)) {
                        return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ContentConvertingDocumentByteBuffer", locale), null, null, convertResult);
                    }

                    ByteBuffer outByteBuffer = (ByteBuffer) convertResult.get("outByteBuffer");
                    inputByteArray = outByteBuffer.array();
                    reader = new PdfReader(inputByteArray);
                }
                if (reader != null) {
                    int n = reader.getNumberOfPages();
                    for (int i=0; i < n; i++) {
                        PdfImportedPage pg = writer.getImportedPage(reader, i + 1);
                        //cb.addTemplate(pg, left, height * pgCnt);
                        writer.addPage(pg);
                        pgCnt++;
View Full Code Here

        String surveyId = null;
        try {
            String surveyName = (String) context.get("surveyName");
            ByteArrayOutputStream os = new ByteArrayOutputStream();
            ByteBuffer byteBuffer = getInputByteBuffer(context, delegator);
            PdfReader pdfReader = new PdfReader(byteBuffer.array());
            PdfStamper pdfStamper = new PdfStamper(pdfReader, os);
            AcroFields acroFields = pdfStamper.getAcroFields();
            Map<String, Object> acroFieldMap = UtilGenerics.checkMap(acroFields.getFields());

            String contentId = (String) context.get("contentId");
View Full Code Here

                surveyResponse.create();
            }

            ByteArrayOutputStream os = new ByteArrayOutputStream();
            ByteBuffer byteBuffer = getInputByteBuffer(context, delegator);
            PdfReader r = new PdfReader(byteBuffer.array());
            PdfStamper s = new PdfStamper(r,os);
            AcroFields fs = s.getAcroFields();
            Map<String, Object> hm = UtilGenerics.checkMap(fs.getFields());
            s.setFormFlattening(true);
            Iterator<String> i = hm.keySet().iterator();
View Full Code Here

        Map<String, Object> acroFieldMap = FastMap.newInstance();
        try {
            ByteArrayOutputStream os = new ByteArrayOutputStream();
            Delegator delegator = dctx.getDelegator();
            ByteBuffer byteBuffer = getInputByteBuffer(context, delegator);
            PdfReader r = new PdfReader(byteBuffer.array());
            PdfStamper s = new PdfStamper(r,os);
            AcroFields fs = s.getAcroFields();
            Map<String, Object> map = UtilGenerics.checkMap(fs.getFields());
            s.setFormFlattening(true);
View Full Code Here

        Map<String, Object> results = ServiceUtil.returnSuccess();
        Delegator delegator = dctx.getDelegator();
        try {
            Map<String, Object> acroFieldMap = UtilGenerics.checkMap(context.get("acroFieldMap"));
            ByteBuffer byteBuffer = getInputByteBuffer(context, delegator);
            PdfReader r = new PdfReader(byteBuffer.array());
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            PdfStamper s = new PdfStamper(r, baos);
            AcroFields fs = s.getAcroFields();
            Map<String, Object> map = UtilGenerics.checkMap(fs.getFields());
            s.setFormFlattening(true);
View Full Code Here

   public Properties getProperties(InputStream is) throws IOException, DocumentReadException
   {

      Properties props = null;

      PdfReader reader = new PdfReader(is, "".getBytes());

      // Read the file metadata
      byte[] metadata = reader.getMetadata();

      if (metadata != null)
      {
         // there is XMP metadata try exctract it
         props = getPropertiesFromMetadata(metadata);
      }

      if (props == null)
      {
         // it's old pdf document version
         props = getPropertiesFromInfo(reader.getInfo());
      }
      reader.close();
      if (is != null)
         try
         {
            is.close();
         }
View Full Code Here

TOP

Related Classes of com.lowagie.text.pdf.PdfReader

Copyright © 2018 www.massapicom. 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.