Examples of PdfReader


Examples of com.lowagie.text.pdf.PdfReader

                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

Examples of com.lowagie.text.pdf.PdfReader

            }
            int fontsize = Integer.parseInt((String) getValue("fontsize"));
            float opacity = Float.parseFloat((String) getValue("opacity"));
            BaseFont bf = BaseFont.createFont("Helvetica", BaseFont.WINANSI,
                                              false);
            PdfReader reader = new PdfReader(((File) getValue("srcfile"))
                                             .getAbsolutePath());
            int pagecount = reader.getNumberOfPages();
            PdfGState gs1 = new PdfGState();
            gs1.setFillOpacity(opacity);
            String text = (String) getValue("watermark");
            PdfStamper stamp = new PdfStamper(reader, new FileOutputStream(
                    (File) getValue("destfile")));
            float txtwidth = bf.getWidthPoint(text, fontsize);
            for (int i = 1; i <= pagecount; i++) {
                PdfContentByte seitex = stamp.getOverContent(i);
                LwgRectangle recc = reader.getCropBox(i);
                float winkel = (float) Math.atan(recc.getHeight() /
                                                 recc.getWidth());
                float m1 = (float) Math.cos(winkel);
                float m2 = (float) - Math.sin(winkel);
                float m3 = (float) Math.sin(winkel);
View Full Code Here

Examples of com.lowagie.text.pdf.PdfReader

        y1[i] = y2[i - 1] - 20f;
        y2[i] = y1[i] - height;
      }

      // we create a reader for a certain document
      PdfReader reader = new PdfReader(src.getAbsolutePath());
      // we retrieve the total number of pages
      int n = reader.getNumberOfPages();
      System.out.println("There are " + n + " pages in the original file.");

      // step 1: creation of a document-object
      LwgDocument document = new LwgDocument(LwgPageSize.A4);
      // step 2: we create a writer that listens to the document
      PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(dest));
      // step 3: we open the document
      document.open();
      PdfContentByte cb = writer.getDirectContent();
      PdfImportedPage page;
      int rotation;
      int i = 0;
      int p = 0;
      // step 4: we add content
      while (i < n) {
        i++;
        LwgRectangle rect = reader.getPageSizeWithRotation(i);
        float factorx = (x2 - x1) / rect.getWidth();
        float factory = (y1[p] - y2[p]) / rect.getHeight();
        float factor = (factorx < factory ? factorx : factory);
        float dx = (factorx == factor ? 0f : ((x2 - x1) - rect.getWidth() * factor) / 2f);
        float dy = (factory == factor ? 0f : ((y1[p] - y2[p]) - rect.getHeight() * factor) / 2f);
        page = writer.getImportedPage(reader, i);
        rotation = reader.getPageRotation(i);
        if (rotation == 90 || rotation == 270) {
          cb.addTemplate(page, 0, -factor, factor, 0, x1 + dx, y2[p] + dy + rect.getHeight() * factor);
        }
        else {
          cb.addTemplate(page, factor, 0, 0, factor, x1 + dx, y2[p] + dy);
View Full Code Here

Examples of com.lowagie.text.pdf.PdfReader

          if (getValue("destfile") == null) throw new InstantiationException("You need to choose a destination file for the first part of the PDF");
          File dest = (File)getValue("destfile");
          String selection = (String)getValue("selection");

          // we create a reader for a certain document
      PdfReader reader = new PdfReader(src.getAbsolutePath());
      System.out.println("The original file had " + reader.getNumberOfPages() + " pages.");
      reader.selectPages(selection);
      int pages = reader.getNumberOfPages();
      System.err.println("The new file has " + pages + " pages.");
      LwgDocument document = new LwgDocument(reader.getPageSizeWithRotation(1));
      PdfCopy copy = new PdfCopy(document, new FileOutputStream(dest.getAbsolutePath()));
      document.open();
            PdfImportedPage page;
            for (int i = 0; i < pages; ) {
                ++i;
                System.out.println("Processed page " + i);
                page = copy.getImportedPage(reader, i);
                copy.addPage(page);
            }
            PRAcroForm form = reader.getAcroForm();
      if (form != null)
                copy.copyAcroForm(reader);
      document.close();
        }
        catch(Exception e) {
View Full Code Here

Examples of com.lowagie.text.pdf.PdfReader

         LwgDocument document = null;
         PdfCopy writer = null;
         for (int i = 0; i < 2; i++)
         {
            // we create a reader for a certain document
            PdfReader reader = new PdfReader(files[i]);
            reader.consolidateNamedDestinations();
            // we retrieve the total number of pages
            int n = reader.getNumberOfPages();
            List<HashMap<String, Object>> bookmarks = SimpleBookmark.getBookmark(reader);
            if (bookmarks != null)
            {
               if (pageOffset != 0)
                  SimpleBookmark.shiftPageNumbers(bookmarks, pageOffset, null);
               master.addAll(bookmarks);
            }
            pageOffset += n;
            System.out.println("There are " + n + " pages in " + files[i]);
            if (i == 0)
            {
               // step 1: creation of a document-object
               document = new LwgDocument(reader.getPageSizeWithRotation(1));
               // step 2: we create a writer that listens to the document
               writer = new PdfCopy(document, new FileOutputStream(pdf_file));
               // step 3: we open the document
               document.open();
            }
View Full Code Here

Examples of com.lowagie.text.pdf.PdfReader

   */
  public void execute() {
    try {
      if (getValue("xmlfile") == null) throw new InstantiationException("You need to choose an xml file");
      if (getValue("pdffile") == null) throw new InstantiationException("You need to choose a source PDF file");
      PdfReader reader = new PdfReader(((File)getValue("pdffile")).getAbsolutePath());
            reader.consolidateNamedDestinations();
            List<HashMap<String, Object>> bookmarks = SimpleBookmark.getBookmark( reader );
            // save them in XML format
            FileOutputStream bmWriter = new FileOutputStream( (File)getValue("xmlfile") );
            SimpleBookmark.exportToXML(bookmarks, bmWriter, "UTF-8", false);
            bmWriter.close();
View Full Code Here

Examples of com.lowagie.text.pdf.PdfReader

        throw new InstantiationException(
            "You need to choose a sourcefile");
      EventDispatchingThread task = new EventDispatchingThread() {
        public Object construct() {
          try {
            PdfReader reader = new PdfReader(
                ((File) getValue("srcfile")).getAbsolutePath());
            for (int i = 0; i < reader.getXrefSize(); i++) {
              PdfObject pdfobj = reader.getPdfObject(i);
              if (pdfobj != null) {
                if (pdfobj.isStream()) {
                  PdfStream pdfdict = (PdfStream) pdfobj;
                  PdfObject pdfsubtype = pdfdict
                      .get(PdfName.SUBTYPE);
View Full Code Here

Examples of com.lowagie.text.pdf.PdfReader

      if (getValue("destfile") == null) throw new InstantiationException("You need to choose a destination file");
      byte[] ownerpassword = null;
      if (getValue("ownerpassword") != null) {
        ownerpassword = ((String)getValue("ownerpassword")).getBytes();
      }
      PdfReader reader = new PdfReader(((File)getValue("srcfile")).getAbsolutePath(), ownerpassword);
      PdfStamper stamper = new PdfStamper(reader, new FileOutputStream((File)getValue("destfile")));
      stamper.close();
    }
    catch(Exception e) {
          JOptionPane.showMessageDialog(internalFrame,
View Full Code Here

Examples of com.lowagie.text.pdf.PdfReader

        throw new InstantiationException(
            "You need to choose a sourcefile");
      File src = (File) getValue("srcfile");

      // we create a reader for a certain document
      PdfReader reader = new PdfReader(src.getAbsolutePath());
      final File parentFile = src.getParentFile();
      final String outPath;
      if (parentFile != null) {
        outPath = parentFile.getAbsolutePath();
      } else {
        outPath = "";
      }
      PdfDictionary catalog = reader.getCatalog();
      PdfDictionary names = catalog.getAsDict(PdfName.NAMES);
      if (names != null) {
        PdfDictionary embFiles = names.getAsDict(new PdfName("EmbeddedFiles"));
        if (embFiles != null) {
            HashMap<String, PdfObject> embMap = PdfNameTree.readTree(embFiles);
          for (Iterator<PdfObject> i = embMap.values().iterator(); i.hasNext();) {
            PdfDictionary filespec = (PdfDictionary) PdfReader
                .getPdfObject(i.next());
            unpackFile(reader, filespec, outPath);
          }
        }
      }
      for (int k = 1; k <= reader.getNumberOfPages(); ++k) {
        PdfArray annots = reader.getPageN(k).getAsArray(PdfName.ANNOTS);
        if (annots == null)
          continue;
        for (Iterator<PdfObject> i = annots.listIterator(); i.hasNext();) {
          PdfDictionary annot = (PdfDictionary) PdfReader
              .getPdfObject(i.next());
View Full Code Here

Examples of com.lowagie.text.pdf.PdfReader

  public void execute() {
    try {
      if (getValue("srcfile") == null) throw new InstantiationException("You need to choose a sourcefile");
      if (getValue("destfile") == null) throw new InstantiationException("You need to choose a destination file");
      boolean compress = "true".equals(getValue("compress"));
      PdfReader reader = new PdfReader(((File)getValue("srcfile")).getAbsolutePath());
      PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(getDestPathPDF()));
      synchronized(arguments) {
        LwgDocument.compress = compress;
        int total = reader.getNumberOfPages() + 1;
        for (int i = 1; i < total; i++) {
          reader.setPageContent(i, reader.getPageContent(i));
        }
        stamper.close();
        LwgDocument.compress = true;
      }
    }
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.