Package com.lowagie.text.pdf

Examples of com.lowagie.text.pdf.PdfObject


     * Replaces CalRGB and CalGray colorspaces with DeviceRGB and DeviceGray.
     */   
    public void simplifyColorspace() {
        if (additional == null)
            return;
        PdfObject value = additional.get(PdfName.COLORSPACE);
        if (value == null || !value.isArray())
            return;
        PdfObject cs = simplifyColorspace(value);
        if (cs.isName())
            value = cs;
        else {
            PdfObject first = (PdfObject)(((PdfArray)value).getArrayList().get(0));
            if (PdfName.INDEXED.equals(first)) {
                ArrayList array = ((PdfArray)value).getArrayList();
                if (array.size() >= 2 && ((PdfObject)array.get(1)).isArray()) {
                     array.set(1, simplifyColorspace((PdfObject)array.get(1)));
                }
View Full Code Here


   * Gets a PDF Name from an array or returns the object that was passed.
   */
    private PdfObject simplifyColorspace(PdfObject obj) {
        if (obj == null || !obj.isArray())
            return obj;
        PdfObject first = (PdfObject)(((PdfArray)obj).getArrayList().get(0));
        if (PdfName.CALGRAY.equals(first))
            return PdfName.DEVICEGRAY;
        else if (PdfName.CALRGB.equals(first))
            return PdfName.DEVICERGB;
        else
View Full Code Here

  /**
   * Defines the sort order of the field (ascending or descending).
   * @param ascending  true is the default, use false for descending order
   */
  public void setSortOrder(boolean ascending) {
    PdfObject o = (PdfObject)get(PdfName.S);
    if (o instanceof PdfName) {
      put(PdfName.A, new PdfBoolean(ascending));
    }
    else {
      throw new IllegalArgumentException("You have to define a boolean array for this collection sort dictionary.");
View Full Code Here

  /**
   * Defines the sort order of the field (ascending or descending).
   * @param ascending  an array with every element corresponding with a name of a field.
   */
  public void setSortOrder(boolean[] ascending) {
    PdfObject o = (PdfObject)get(PdfName.S);
    if (o instanceof PdfArray) {
      if (((PdfArray)o).size() != ascending.length) {
        throw new IllegalArgumentException("The number of booleans in this array doesn't correspond with the number of fields.");
      }
      PdfArray array = new PdfArray();
View Full Code Here

   * You can only use this method after you have set the value of the item.
   * @param prefix  a prefix
   */
  public void setPrefix(String key, String prefix) {
    PdfName fieldname = new PdfName(key);
    PdfObject o = get(fieldname);
    if (o == null)
      throw new IllegalArgumentException("You must set a value before adding a prefix.");
    PdfDictionary dict = new PdfDictionary(PdfName.COLLECTIONSUBITEM);
    dict.put(PdfName.D, o);
    dict.put(PdfName.P, new PdfString(prefix, PdfObject.TEXT_UNICODE));
View Full Code Here

                dic.put(PdfName.GAMMA, new PdfNumber(gamma));
                dic.put(PdfName.WHITEPOINT, new PdfLiteral("[1 1 1]"));
                array.add(dic);
            }
            else {
                PdfObject wp = new PdfLiteral("[1 1 1]");
                array.add(PdfName.CALRGB);
                if (gamma != 1f) {
                    PdfArray gm = new PdfArray();
                    PdfNumber n = new PdfNumber(gamma);
                    gm.add(n);
View Full Code Here

  public static PdfViewerPreferencesImp getViewerPreferences(PdfDictionary catalog) {
    PdfViewerPreferencesImp preferences = new PdfViewerPreferencesImp();
    int prefs = 0;
    PdfName name = null;
    // page layout
    PdfObject obj = PdfReader.getPdfObjectRelease(catalog.get(PdfName.PAGELAYOUT));
    if (obj != null && obj.isName()) {
      name = (PdfName) obj;
      if (name.equals(PdfName.SINGLEPAGE))
        prefs |= PdfWriter.PageLayoutSinglePage;
      else if (name.equals(PdfName.ONECOLUMN))
        prefs |= PdfWriter.PageLayoutOneColumn;
      else if (name.equals(PdfName.TWOCOLUMNLEFT))
        prefs |= PdfWriter.PageLayoutTwoColumnLeft;
      else if (name.equals(PdfName.TWOCOLUMNRIGHT))
        prefs |= PdfWriter.PageLayoutTwoColumnRight;
      else if (name.equals(PdfName.TWOPAGELEFT))
        prefs |= PdfWriter.PageLayoutTwoPageLeft;
      else if (name.equals(PdfName.TWOPAGERIGHT))
        prefs |= PdfWriter.PageLayoutTwoPageRight;
    }
    // page mode
    obj = PdfReader.getPdfObjectRelease(catalog.get(PdfName.PAGEMODE));
    if (obj != null && obj.isName()) {
      name = (PdfName) obj;
      if (name.equals(PdfName.USENONE))
        prefs |= PdfWriter.PageModeUseNone;
      else if (name.equals(PdfName.USEOUTLINES))
        prefs |= PdfWriter.PageModeUseOutlines;
      else if (name.equals(PdfName.USETHUMBS))
        prefs |= PdfWriter.PageModeUseThumbs;
      else if (name.equals(PdfName.USEOC))
        prefs |= PdfWriter.PageModeUseOC;
      else if (name.equals(PdfName.USEATTACHMENTS))
        prefs |= PdfWriter.PageModeUseAttachments;
    }
    // set page layout and page mode preferences
    preferences.setViewerPreferences(prefs);
    // other preferences
    obj = PdfReader.getPdfObjectRelease(catalog
        .get(PdfName.VIEWERPREFERENCES));
    if (obj != null && obj.isDictionary()) {
      PdfDictionary vp = (PdfDictionary) obj;
      for (int i = 0; i < VIEWER_PREFERENCES.length; i++) {
        obj = PdfReader.getPdfObjectRelease(vp.get(VIEWER_PREFERENCES[i]));
        preferences.addViewerPreference(VIEWER_PREFERENCES[i], obj);
      }
View Full Code Here

                PdfImage image = (PdfImage)obj1;
                if (image.get(PdfName.SMASK) != null)
                    throw new PdfXConformanceException("The /SMask key is not allowed in images.");
                switch (conf) {
                    case PdfWriter.PDFX1A2001:
                        PdfObject cs = image.get(PdfName.COLORSPACE);
                        if (cs == null)
                            return;
                        if (cs.isName()) {
                            if (PdfName.DEVICERGB.equals(cs))
                                throw new PdfXConformanceException("Colorspace RGB is not allowed.");
                        }
                        else if (cs.isArray()) {
                            if (PdfName.CALRGB.equals(((PdfArray)cs).getArrayList().get(0)))
                                throw new PdfXConformanceException("Colorspace CalRGB is not allowed.");
                        }
                        break;
                }
                break;
            case PDFXKEY_GSTATE:
                PdfDictionary gs = (PdfDictionary)obj1;
                PdfObject obj = gs.get(PdfName.BM);
                if (obj != null && !PdfGState.BM_NORMAL.equals(obj) && !PdfGState.BM_COMPATIBLE.equals(obj))
                    throw new PdfXConformanceException("Blend mode " + obj.toString() + " not allowed.");
                obj = gs.get(PdfName.CA);
                double v = 0.0;
                if (obj != null && (v = ((PdfNumber)obj).doubleValue()) != 1.0)
                    throw new PdfXConformanceException("Transparency is not allowed: /CA = " + v);
                obj = gs.get(PdfName.ca);
View Full Code Here

                PdfDictionary dictionary= (PdfDictionary)entity;

                Set<PdfName> allkeys = dictionary.getKeys();
                for (PdfName key: allkeys) {
                    PdfObject value = dictionary.get(key);

                    // see if it's the key is a UR[I,L]
                    if( key.toString().equals("/URI") ||
                key.toString().equals("/URL") ) {
                        foundURIs.add(value.toString());

                    }else{
                        this.extractURIs(value);
                    }

                }

            // deal with arrays
            }else if(entity.isArray()){

                PdfArray array = (PdfArray)entity;
                for (PdfObject pdfObject : (Iterable<PdfObject>)array.getArrayList()) {
                    this.extractURIs(pdfObject);
                }

            // deal with indirect references
            }else if(entity.getClass() == PRIndirectReference.class){

                    PRIndirectReference indirect = (PRIndirectReference)entity;

                    // if we've already seen a reference to this object
                    if( haveSeen( indirect.getGeneration(), indirect.getNumber()) ){
                        return;

                    // note that we've seen it if it's new
                    }else{
                        markAsSeen(indirect.getGeneration(), indirect.getNumber() );
                    }

                    // dereference the "pointer" and process the object
                    indirect.getReader(); // FIXME: examine side-effects
                    PdfObject direct = PdfReader.getPdfObject(indirect);

                    this.extractURIs(direct);
            }
    }
View Full Code Here

                PdfImage image = (PdfImage)obj1;
                if (image.get(PdfName.SMASK) != null)
                    throw new PdfXConformanceException(MessageLocalization.getComposedMessage("the.smask.key.is.not.allowed.in.images"));
                switch (conf) {
                    case PdfWriter.PDFX1A2001:
                        PdfObject cs = image.get(PdfName.COLORSPACE);
                        if (cs == null)
                            return;
                        if (cs.isName()) {
                            if (PdfName.DEVICERGB.equals(cs))
                                throw new PdfXConformanceException(MessageLocalization.getComposedMessage("colorspace.rgb.is.not.allowed"));
                        }
                        else if (cs.isArray()) {
                            if (PdfName.CALRGB.equals(((PdfArray)cs).getPdfObject(0)))
                                throw new PdfXConformanceException(MessageLocalization.getComposedMessage("colorspace.calrgb.is.not.allowed"));
                        }
                        break;
                }
                break;
            case PDFXKEY_GSTATE:
                PdfDictionary gs = (PdfDictionary)obj1;
                PdfObject obj = gs.get(PdfName.BM);
                if (obj != null && !PdfGState.BM_NORMAL.equals(obj) && !PdfGState.BM_COMPATIBLE.equals(obj))
                    throw new PdfXConformanceException(MessageLocalization.getComposedMessage("blend.mode.1.not.allowed", obj.toString()));
                obj = gs.get(PdfName.CA);
                double v = 0.0;
                if (obj != null && (v = ((PdfNumber)obj).doubleValue()) != 1.0)
                    throw new PdfXConformanceException(MessageLocalization.getComposedMessage("transparency.is.not.allowed.ca.eq.1", String.valueOf(v)));
                obj = gs.get(PdfName.ca);
View Full Code Here

TOP

Related Classes of com.lowagie.text.pdf.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.