Examples of PDFDocument


Examples of railo.runtime.text.pdf.PDFDocument

    required("pdf", "write", "destination", destination);
   
    if(destination.exists() && !overwrite)
      throw new ApplicationException("destination file ["+destination+"] already exists");
   
    PDFDocument doc = toPDFDocument(source, password, null);
    //PdfReader pr = doc.getPdfReader();
    // output
    boolean destIsSource = doc.getResource()!=null && destination.equals(doc.getResource());
   
    OutputStream os=null;
    if(destIsSource){
      os=new ByteArrayOutputStream();
    }
View Full Code Here

Examples of railo.runtime.text.pdf.PDFDocument


  private void doActionThumbnail() throws PageException, IOException, DocumentException {
    required("pdf", "thumbnail", "source", source);

    PDFDocument doc = toPDFDocument(source, password, null);
    PdfReader pr = doc.getPdfReader();
    boolean isEnc=pr.isEncrypted();
    pr.close();
    if(isEnc) {
      ByteArrayOutputStream baos = new ByteArrayOutputStream();
      //PDFUtil.concat(new PDFDocument[]{doc}, baos, true, true, true, (char)0);
      PDFUtil.encrypt(doc,baos,null,null,0,PDFUtil.ENCRYPT_NONE);
      baos.close();
      doc = new PDFDocument(baos.toByteArray(),doc.getResource(),null);
    }
   
    doc.setPages(pages);
   
    // scale
    if(scale<1)
      throw new ApplicationException("value of attribute scale ["+scale+"] should be at least 1");
   
    // destination
    if(destination==null)
      destination=ResourceUtil.toResourceNotExisting(pageContext, "thumbnails");
   
    // imagePrefix
    if(imagePrefix==null){
      Resource res = doc.getResource();
      if(res!=null){
        String n = res.getName();
        int index=n.lastIndexOf('.');
        if(index!=-1)imagePrefix=n.substring(0,index);
        else imagePrefix=n;
      }
      else imagePrefix="memory";
    }
   
    // MUST password
    PDFUtil.writeImages(doc.getRaw(), doc.getPages(), destination, imagePrefix, format, scale,overwrite,
        resolution==RESOLUTION_HIGH,transparent);
   
   
   
  }
View Full Code Here

Examples of railo.runtime.text.pdf.PDFDocument

      if(!StringUtil.isEmpty(strY))y = Caster.toIntValue(strY);
     
    }
   
   
    PDFDocument doc = toPDFDocument(source, password, null);
    doc.setPages(pages);
    PdfReader reader = doc.getPdfReader();
    reader.consolidateNamedDestinations();
    boolean destIsSource = destination!=null && doc.getResource()!=null && destination.equals(doc.getResource());
    java.util.List bookmarks = SimpleBookmark.getBookmark(reader);
      ArrayList master = new ArrayList()
    if(bookmarks!=null)master.addAll(bookmarks);
     
    // output
    OutputStream os=null;
    if(!StringUtil.isEmpty(name) || destIsSource){
      os=new ByteArrayOutputStream();
    }
    else if(destination!=null) {
      os=destination.getOutputStream();
    }
   
    try {
     
      int len = reader.getNumberOfPages();
        PdfStamper stamp = new PdfStamper(reader, os);
       
        if(len >0){
          if(x==UNDEFINED || y==UNDEFINED) {
            PdfImportedPage first = stamp.getImportedPage(reader, 1);
            if(y==UNDEFINED)y=(first.getHeight()-img.getHeight())/2;
            if(x==UNDEFINED)x=(first.getWidth()-img.getWidth())/2;       
          }
          img.setAbsolutePosition(x, y);
          //img.setAlignment(Image.ALIGN_JUSTIFIED); ration geht nicht anhand mitte
         
        }
       
      // rotation
      if(rotation!=0) {
        img.setRotationDegrees(rotation);
      }
     
      Set _pages = doc.getPages();
        for (int i=1;i<=len;i++) {
          if(_pages!=null && !_pages.contains(Integer.valueOf(i))) continue;
          PdfContentByte cb =foreground? stamp.getOverContent(i):stamp.getUnderContent(i);
          PdfGState gs1 = new PdfGState();
          //print.out("op:"+opacity);
          gs1.setFillOpacity(opacity);
          //gs1.setStrokeOpacity(opacity);
            cb.setGState(gs1);
          cb.addImage(img);
        }
        if(bookmarks!=null)stamp.setOutlines(master);
        stamp.close();
    }
    finally {
      IOUtil.closeEL(os);
      if(os instanceof ByteArrayOutputStream) {
        if(destination!=null)IOUtil.copy(new ByteArrayInputStream(((ByteArrayOutputStream)os).toByteArray()), destination,true);// MUST overwrite
        if(!StringUtil.isEmpty(name)){
          pageContext.setVariable(name,new PDFDocument(((ByteArrayOutputStream)os).toByteArray(),password));
        }
      }
    }
  }
View Full Code Here

Examples of railo.runtime.text.pdf.PDFDocument

    railo.runtime.img.Image ri = new railo.runtime.img.Image(1,1,BufferedImage.TYPE_INT_RGB,Color.BLACK);
    Image img = Image.getInstance(ri.getBufferedImage(),null,false);
    img.setAbsolutePosition(1,1);
   
   
    PDFDocument doc = toPDFDocument(source, password, null);
    doc.setPages(pages);
    PdfReader reader = doc.getPdfReader();

    boolean destIsSource = destination!=null && doc.getResource()!=null && destination.equals(doc.getResource());
    java.util.List bookmarks = SimpleBookmark.getBookmark(reader);
      ArrayList master = new ArrayList()
    if(bookmarks!=null)master.addAll(bookmarks);
     
    // output
    OutputStream os=null;
    if(!StringUtil.isEmpty(name) || destIsSource){
      os=new ByteArrayOutputStream();
    }
    else if(destination!=null) {
      os=destination.getOutputStream();
    }
   
    try {
      int len = reader.getNumberOfPages();
        PdfStamper stamp = new PdfStamper(reader, os);
     
      Set _pages = doc.getPages();
        for (int i=1;i<=len;i++) {
          if(_pages!=null && !_pages.contains(Integer.valueOf(i))) continue;
          PdfContentByte cb =foreground? stamp.getOverContent(i):stamp.getUnderContent(i);
          PdfGState gs1 = new PdfGState();
            gs1.setFillOpacity(0);
            cb.setGState(gs1);
          cb.addImage(img);
        }
        if(bookmarks!=null)stamp.setOutlines(master);
        stamp.close();
    }
    finally {
      IOUtil.closeEL(os);
      if(os instanceof ByteArrayOutputStream) {
        if(destination!=null)IOUtil.copy(new ByteArrayInputStream(((ByteArrayOutputStream)os).toByteArray()), destination,true);// MUST overwrite
        if(!StringUtil.isEmpty(name)){
          pageContext.setVariable(name,new PDFDocument(((ByteArrayOutputStream)os).toByteArray(),password));
        }
      }
    }
  }
View Full Code Here

Examples of railo.runtime.text.pdf.PDFDocument

 
  private void doActionDeletePages() throws PageException, IOException, DocumentException {
    required("pdf", "deletePage", "pages", pages,true);
    required("pdf", "deletePage", "source", source);
   
    PDFDocument doc = toPDFDocument(source, password, null);
    doc.setPages(pages);
   
   
    if(destination==null && StringUtil.isEmpty(name)){
      if(doc.getResource()==null)
        throw new ApplicationException("source is not based on a resource, destination attribute is required");
      destination=doc.getResource();
    }
    else if(destination!=null && destination.exists() && !overwrite)
      throw new ApplicationException("destination file ["+destination+"] already exists");
   
    boolean destIsSource = destination!=null && doc.getResource()!=null && destination.equals(doc.getResource());
   
    // output
    OutputStream os=null;
    if(!StringUtil.isEmpty(name) || destIsSource){
      os=new ByteArrayOutputStream();
    }
    else if(destination!=null) {
      os=destination.getOutputStream();
    }
   
    try {
      PDFUtil.concat(new PDFDocument[]{doc}, os, true, true,true,version);
    }
    finally {
      //if(document!=null)document.close();
      IOUtil.closeEL(os);
      if(os instanceof ByteArrayOutputStream) {
        if(destination!=null)IOUtil.copy(new ByteArrayInputStream(((ByteArrayOutputStream)os).toByteArray()), destination,true);// MUST overwrite
        if(!StringUtil.isEmpty(name)){
          pageContext.setVariable(name,new PDFDocument(((ByteArrayOutputStream)os).toByteArray(),password));
        }
      }
    }
  }
View Full Code Here

Examples of railo.runtime.text.pdf.PDFDocument

          "[destination,name]");
    if(destination!=null && !overwrite)
      throw new ApplicationException("destination file ["+destination+"] already exists");
   
    ArrayList docs = new ArrayList();
    PDFDocument doc;
    boolean isListing=false;
   
    // source
    if(source!=null) {
      if(Decision.isArray(source)) {
        Array arr = Caster.toArray(source);
        int len = arr.size();
        for(int i=1;i<=len;i++) {
          docs.add(doc=toPDFDocument(arr.getE(i),password,null));
          doc.setPages(pages);
        }
      }
      else if(source instanceof String) {
        String[] sources = ListUtil.toStringArrayTrim(ListUtil.listToArrayRemoveEmpty((String)source, ','));
        for(int i=0;i<sources.length;i++) {
          docs.add(doc=toPDFDocument(sources[i],password,null));
          doc.setPages(pages);
        }
      }
      else docs.add(toPDFDocument(source,password,null));
     
    }
    boolean destIsSource = false;
   
    // params
    if(directory!=null && !directory.isDirectory()) {
      if(!directory.exists())
        throw new ApplicationException("defined attribute directory does not exist");
      throw new ApplicationException("defined attribute directory is not a directory");
    }
    if(params!=null) {
      Iterator it = params.iterator();
      PDFParamBean param;
      while(it.hasNext()) {
        param=(PDFParamBean) it.next();
        docs.add(doc=toPDFDocument(param.getSource(), param.getPassword(),directory));
        doc.setPages(param.getPages());
      }
    }
    else if(directory!=null) {
      isListing=true;
      Resource[] children = ResourceUtil.listResources(directory, filter);
     
      if(ascending) {
        for(int i=children.length-1;i>=0;i--) {
          if(destination!=null && children[i].equals(destination))  destIsSource=true;
          docs.add(doc=toPDFDocument(children[i],password,null));
          doc.setPages(pages);
        }
      }
      else {
        for(int i=0;i<children.length;i++) {
          if(destination!=null && children[i].equals(destination))  destIsSource=true;
          docs.add(doc=toPDFDocument(children[i],password,null));
          doc.setPages(pages);
        }
      }
     
    }
   
View Full Code Here

Examples of railo.runtime.text.pdf.PDFDocument

   
    if(StringUtil.isEmpty(newUserPassword) && StringUtil.isEmpty(newOwnerPassword))
      throw new ApplicationException("at least one of the following attributes must be defined [newUserPassword,newOwnerPassword]");
       
   
    PDFDocument doc = toPDFDocument(source,password,null);
   
    if(destination==null){
      destination=doc.getResource();
      if(destination==null)
        throw new ApplicationException("source is not based on a resource, destination file is required");
    }
    else if(destination.exists() && !overwrite)
      throw new ApplicationException("destination file ["+destination+"] already exists");
   
    boolean destIsSource = doc.getResource()!=null && destination.equals(doc.getResource());
   
    // output
    OutputStream os=null;
    if(destIsSource){
      os=new ByteArrayOutputStream();
View Full Code Here

Examples of railo.runtime.text.pdf.PDFDocument

  private void doActionSetInfo() throws PageException, IOException, DocumentException {
    required("pdf", "setInfo", "info", info);
    required("pdf", "getInfo", "source", source);
   
    PDFDocument doc = toPDFDocument(source,password,null);
    PdfReader pr = doc.getPdfReader();
    OutputStream os=null;
    try {
      if(destination==null){
        if(doc.getResource()==null)
          throw new ApplicationException("source is not based on a resource, destination file is required");
        destination=doc.getResource();
      }
      else if(destination.exists() && !overwrite)
        throw new ApplicationException("destination file ["+destination+"] already exists");
     
      PdfStamper stamp = new PdfStamper(pr, os=destination.getOutputStream());
View Full Code Here

Examples of railo.runtime.text.pdf.PDFDocument

 
  private void doActionGetInfo() throws PageException {
    required("pdf", "getInfo", "name", name,true);
    required("pdf", "getInfo", "source", source);
   
    PDFDocument doc = toPDFDocument(source,password,null);
    pageContext.setVariable(name, doc.getInfo());
   
  }
View Full Code Here

Examples of railo.runtime.text.pdf.PDFDocument

   
  }
  private void doActionExtractText() throws PageException, IOException, CryptographyException, InvalidPasswordException {
    required("pdf", "extractText", "name", name,true);
   
    PDFDocument doc = toPDFDocument(source,password,null);
    doc.setPages(pages);
   
    pageContext.setVariable(name, PDFUtil.extractText(doc,doc.getPages()));
    /*
     <cfpdf
required
    action="extracttext" <!---extract all the words in the PDF.--->
    ***source= "absolute or relative path of the PDF file|PDF document variable|
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.