Package com.sun.pdfview

Examples of com.sun.pdfview.PDFObject


   * @param root - the root object
   */
  public LaunchAction(PDFObject obj, PDFObject root) throws IOException {
    super("Launch");
    // find the file/application and parse it
    PDFObject fileObj = obj.getDictRef("F");
    this.file = parseFileSpecification(fileObj);

    // find the new window flag and parse it
    PDFObject newWinObj = obj.getDictRef("NewWindow");
    if (newWinObj != null) {
      this.newWindow = newWinObj.getBooleanValue();
    }
    // parse the OS specific launch parameters:
    this.winParam = parseWinDict(obj.getDictRef("Win"));
    // unix and mac dictionaries are not further specified, so can not be parsed yet.
    this.unixParam = obj.getDictRef("Unix");
View Full Code Here


     */
    public GoToAction(PDFObject obj, PDFObject root) throws IOException {
        super("GoTo");
       
        // find the destination
        PDFObject destObj = obj.getDictRef("D");
        if (destObj == null) {
            throw new PDFParseException("No destination in GoTo action " + obj);
        }
       
        // parse it
View Full Code Here

   * @param mandatory
   * @return String - can be <code>null</code> if not mandatory
   * @throws IOException - in case of a parsing error
   ************************************************************************/
  public static String parseStringFromDict(String key, PDFObject parent, boolean mandatory) throws IOException{
    PDFObject val = parent;
    while (val.getType() == PDFObject.DICTIONARY) {
      val = val.getDictRef(key);
      if(val == null){
        if(mandatory){
          throw new PDFParseException(key + "value could not be parsed : " + parent.toString())
        }
        return null;
      }
    }
    return val.getStringValue();
  }
View Full Code Here

   * @param mandatory
   * @return boolean - <code>false</code> if not available and not mandatory
   * @throws IOException
   ************************************************************************/
  public static boolean parseBooleanFromDict(String key, PDFObject parent, boolean mandatory) throws IOException{
    PDFObject val = parent.getDictRef(key);
    if(val == null){
      if(mandatory){
        throw new PDFParseException(key + "value could not be parsed : " + parent.toString())
      }
      return false;
    }
    return val.getBooleanValue();
  }
View Full Code Here

   * @param mandatory
   * @return int - returns "0" in case the value is not a number
   * @throws IOException
   ************************************************************************/
  public static int parseIntegerFromDict(String key, PDFObject parent, boolean mandatory) throws IOException{
    PDFObject val = parent.getDictRef(key);
    if(val == null){
      if(mandatory){
        throw new PDFParseException(key + "value could not be parsed : " + parent.toString())
      }
      return 0;
    }
    return val.getIntValue();
  }
View Full Code Here

   * @param mandatory
   * @return PDFDestination  - can be <code>null</code> if not mandatory
   * @throws IOException
   ************************************************************************/
  public static PDFDestination parseDestination(String key, PDFObject parent, PDFObject root, boolean mandatory) throws IOException{
    PDFObject destObj = parent.getDictRef(key);
    if (destObj == null) {
      if(mandatory){
        throw new PDFParseException("Error parsing destination " + parent);
      }
      return null;
View Full Code Here

     */
    public static PDFAction getAction(PDFObject obj, PDFObject root)
        throws IOException
    {
        // figure out the action type
        PDFObject typeObj = obj.getDictRef("S");
        if (typeObj == null) {
            throw new PDFParseException("No action type in object: " + obj);
        }
       
        // create the action based on the type
        PDFAction action = null;
        String type = typeObj.getStringValue();
        if (type.equals("GoTo")) {
            action = new GoToAction(obj, root);
        }else if(type.equals("GoToE")){
          action = new GoToEAction(obj, root);
        }else if(type.equals("GoToR")){
          action = new GoToRAction(obj, root);
        }else if(type.equals("URI")){
          action = new UriAction(obj, root);
        }else if(type.equals("Launch")){
          action = new LaunchAction(obj, root);
        }
        else {
            /** [JK FIXME: Implement other action types! ] */
            throw new PDFParseException("Unknown Action type: " + type);
        }
       
        // figure out if there is a next action
        PDFObject nextObj = obj.getDictRef("Next");
        if (nextObj != null) {
            action.setNext(nextObj);
        }
       
        // return the action
View Full Code Here

        if (shader != null) {
            return shader;
        }
       
        // read the type (required)
        PDFObject typeObj = shaderObj.getDictRef("ShadingType");
        if (typeObj == null) {
            throw new PDFParseException("No shader type defined!");
        }
        int type = typeObj.getIntValue();
       
        // create the shader
        switch (type) {
            case AXIAL_SHADING:
                shader = new ShaderType2();
                break;
   
            case RADIAL_SHADING:
              shader = new ShaderType3();
              break;

            case FUNCTION_SHADING:
            case FREE_FORM_SHADING:
            case LATTICE_SHADING:
            case COONS_PATCH_MESH_SHADING:
            case TENSOR_PRODUCTS_MESH_SHADING:
            default:   
                throw new PDFParseException("Unsupported shader type: " + type);
        }
       
        // read the color space (required)
        PDFObject csObj = shaderObj.getDictRef("ColorSpace");
        if (csObj == null) {
            throw new PDFParseException("No colorspace defined!");
        }
        PDFColorSpace cs = PDFColorSpace.getColorSpace(csObj, resources);
        shader.setColorSpace(cs);
       
        // read the background color (optional)
        PDFObject bgObj = shaderObj.getDictRef("Background");
        if (bgObj != null) {
            PDFObject[] bgObjs = bgObj.getArray();
            float[] bgArray = new float[bgObjs.length];
            for (int i = 0; i < bgArray.length; i++) {
                bgArray[i] = bgObjs[i].getFloatValue();
            }
            PDFPaint paint = cs.getPaint(bgArray);
            shader.setBackground(paint);         
        }
       
        // read the bounding box (optional)
        PDFObject bboxObj = shaderObj.getDictRef("BBox");
        if (bboxObj != null) {
            PDFObject[] rectObj = bboxObj.getArray();
            float minX = rectObj[0].getFloatValue();
            float minY = rectObj[1].getFloatValue();
            float maxX = rectObj[2].getFloatValue();
            float maxY = rectObj[3].getFloatValue();
           
View Full Code Here

     */
    @Override
  public void parse(PDFObject shaderObj) throws IOException
    {
        // read the axis coordinates (required)
        PDFObject coordsObj = shaderObj.getDictRef("Coords");
        if (coordsObj == null) {
            throw new PDFParseException("No coordinates found!");
        }
        PDFObject[] coords = coordsObj.getArray();
        Point2D start = new Point2D.Float(coords[0].getFloatValue(),
                                          coords[1].getFloatValue());
        Point2D end   = new Point2D.Float(coords[2].getFloatValue(),
                                          coords[3].getFloatValue());
        setAxisStart(start);
        setAxisEnd(end);
       
        // read the domain (optional)
        PDFObject domainObj = shaderObj.getDictRef("Domain");
        if (domainObj != null) {
            PDFObject[] domain = domainObj.getArray();
            setMinT(domain[0].getFloatValue());
            setMaxT(domain[1].getFloatValue());
        }
       
        // read the functions (required)
        PDFObject functionObj = shaderObj.getDictRef("Function");
        if (functionObj == null) {
            throw new PDFParseException("No function defined for shader!");
        }
        PDFObject[] functionArray = functionObj.getArray();
        PDFFunction[] functions = new PDFFunction[functionArray.length];
        for (int i = 0; i < functions.length; i++) {
            functions[i] = PDFFunction.getFunction(functionArray[i]);
        }
        setFunctions(functions);
       
        // read the extend array (optional)
        PDFObject extendObj = shaderObj.getDictRef("Extend");
        if (extendObj != null) {
            PDFObject[] extendArray = extendObj.getArray();
            setExtendStart(extendArray[0].getBooleanValue());
            setExtendEnd(extendArray[1].getBooleanValue());
        }
       
    }
View Full Code Here

  }


  public static byte[] getOptionFieldBytes(PDFObject dict, String name) throws IOException {

    PDFObject dictParams =  dict.getDictRef("DecodeParms");

    if (dictParams == null) {
      return null;
    }
    PDFObject value = dictParams.getDictRef(name);
    if (value == null) {
      return null;
    }
    return value.getStream();
  }
View Full Code Here

TOP

Related Classes of com.sun.pdfview.PDFObject

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.