Java 类com.lowagie.text.pdf.PdfName 实例源码

项目:itext2    文件:Image.java   
/**
 * Reuses an existing image.
 * @param ref the reference to the image dictionary
 * @throws BadElementException on error
 * @return the image
 */    
public static Image getInstance(PRIndirectReference ref) throws BadElementException {
    PdfDictionary dic = (PdfDictionary)PdfReader.getPdfObjectRelease(ref);
    int width = ((PdfNumber)PdfReader.getPdfObjectRelease(dic.get(PdfName.WIDTH))).intValue();
    int height = ((PdfNumber)PdfReader.getPdfObjectRelease(dic.get(PdfName.HEIGHT))).intValue();
    Image imask = null;
    PdfObject obj = dic.get(PdfName.SMASK);
    if (obj != null && obj.isIndirect()) {
        imask = getInstance((PRIndirectReference)obj);
    }
    else {
        obj = dic.get(PdfName.MASK);
        if (obj != null && obj.isIndirect()) {
            PdfObject obj2 = PdfReader.getPdfObjectRelease(obj);
            if (obj2 instanceof PdfDictionary)
                imask = getInstance((PRIndirectReference)obj);
        }
    }
    Image img = new ImgRaw(width, height, 1, 1, null);
    img.imageMask = imask;
    img.directReference = ref;
    return img;
}
项目:itext2    文件:Image.java   
/**
 * Replaces CalRGB and CalGray colorspaces with DeviceRGB and DeviceGray.
 */    
public void simplifyColorspace() {
    if (additional == null)
        return;
    PdfArray value = additional.getAsArray(PdfName.COLORSPACE);
    if (value == null)
        return;
    PdfObject cs = simplifyColorspace(value);
    PdfObject newValue;
    if (cs.isName())
        newValue = cs;
    else {
        newValue = value;
        PdfName first = value.getAsName(0);
        if (PdfName.INDEXED.equals(first)) {
            if (value.size() >= 2) {
                PdfArray second = value.getAsArray(1);
                if (second != null) {
                    value.set(1, simplifyColorspace(second));
                }
            }
        }
    }
    additional.put(PdfName.COLORSPACE, newValue);
}
项目:itext2    文件:Image.java   
/**
* Gets a PDF Name from an array or returns the object that was passed.
*/
  private PdfObject simplifyColorspace(PdfArray obj) {
      if (obj == null)
          return obj;
      PdfName first = obj.getAsName(0);
      if (PdfName.CALGRAY.equals(first))
          return PdfName.DEVICEGRAY;
      else if (PdfName.CALRGB.equals(first))
          return PdfName.DEVICERGB;
      else
          return obj;
  }
项目:itext2    文件:PdfTextExtractor.java   
/**
   * Gets the text from a page.
   * @param page    the page number of the page
   * @return    a String with the content as plain text (without PDF syntax)
   * @throws IOException
   */
  public String getTextFromPage(int page) throws IOException {
    int totalPages = reader.getNumberOfPages();
    if (totalPages < page) {
        throw new IOException("indicated page does not exists, requested page " + page + " document pages " + totalPages);
    }
    if (page <= 0) {
        throw new IOException("page number must be postive:" + page);
    }
      PdfDictionary pageDic = reader.getPageN(page);
if (pageDic == null) {
    return "";
}
      PdfDictionary resourcesDic = pageDic.getAsDict(PdfName.RESOURCES);
      extractionProcessor.processContent(getContentBytesForPage(page), resourcesDic);        
      return extractionProcessor.getResultantText();
  }
项目:itext2    文件:PdfContentStreamProcessor.java   
public void invoke(PdfContentStreamProcessor processor, PdfLiteral operator, ArrayList operands) {
    PdfName dictionaryName = (PdfName) operands.get(0);
    PdfDictionary extGState = processor.resources.getAsDict(PdfName.EXTGSTATE);
    if (extGState == null) {
        throw new IllegalArgumentException(
                "Resources do not contain ExtGState entry. Unable to process operator " + operator);
    }
    PdfDictionary gsDic = extGState.getAsDict(dictionaryName);
    if (gsDic == null) {
        throw new IllegalArgumentException(dictionaryName + " is an unknown graphics state dictionary");
    }

    // at this point, all we care about is the FONT entry in the GS dictionary
    PdfArray fontParameter = gsDic.getAsArray(PdfName.FONT);
    if (fontParameter != null) {
        CMapAwareDocumentFont font = new CMapAwareDocumentFont(
                (PRIndirectReference) fontParameter.getPdfObject(0));
        float size = fontParameter.getAsNumber(1).floatValue();

        processor.gs().font = font;
        processor.gs().fontSize = size;
    }
}
项目:itext2    文件:PdfVersionImp.java   
/**
 * Returns the PDF version as a name.
 * @param version   the version character.
 */
public PdfName getVersionAsName(char version) {
    switch(version) {
    case PdfWriter.VERSION_1_2:
        return PdfWriter.PDF_VERSION_1_2;
    case PdfWriter.VERSION_1_3:
        return PdfWriter.PDF_VERSION_1_3;
    case PdfWriter.VERSION_1_4:
        return PdfWriter.PDF_VERSION_1_4;
    case PdfWriter.VERSION_1_5:
        return PdfWriter.PDF_VERSION_1_5;
    case PdfWriter.VERSION_1_6:
        return PdfWriter.PDF_VERSION_1_6;
    case PdfWriter.VERSION_1_7:
        return PdfWriter.PDF_VERSION_1_7;
    default:
        return PdfWriter.PDF_VERSION_1_4;
    }
}
项目:itext2    文件:PdfAnnotationsImp.java   
public PdfArray rotateAnnotations(PdfWriter writer, Rectangle pageSize) {
    PdfArray array = new PdfArray();
    int rotation = pageSize.getRotation() % 360;
    int currentPage = writer.getCurrentPageNumber();
    for (int k = 0; k < annotations.size(); ++k) {
        PdfAnnotation dic = (PdfAnnotation)annotations.get(k);
        int page = dic.getPlaceInPage();
        if (page > currentPage) {
            delayedAnnotations.add(dic);
            continue;
        }
        if (dic.isForm()) {
            if (!dic.isUsed()) {
                HashMap templates = dic.getTemplates();
                if (templates != null)
                    acroForm.addFieldTemplates(templates);
            }
            PdfFormField field = (PdfFormField)dic;
            if (field.getParent() == null)
                acroForm.addDocumentField(field.getIndirectReference());
        }
        if (dic.isAnnotation()) {
            array.add(dic.getIndirectReference());
            if (!dic.isUsed()) {
                PdfRectangle rect = (PdfRectangle)dic.get(PdfName.RECT);
                if (rect != null) {
                    switch (rotation) {
                        case 90:
                            dic.put(PdfName.RECT, new PdfRectangle(
                                    pageSize.getTop() - rect.bottom(),
                        rect.left(),
                        pageSize.getTop() - rect.top(),
                        rect.right()));
                            break;
                        case 180:
                            dic.put(PdfName.RECT, new PdfRectangle(
                                    pageSize.getRight() - rect.left(),
                        pageSize.getTop() - rect.bottom(),
                        pageSize.getRight() - rect.right(),
                        pageSize.getTop() - rect.top()));
                            break;
                        case 270:
                            dic.put(PdfName.RECT, new PdfRectangle(
                                    rect.bottom(),
                        pageSize.getRight() - rect.left(),
                        rect.top(),
                        pageSize.getRight() - rect.right()));
                            break;
                    }
                }
            }
        }
        if (!dic.isUsed()) {
            dic.setUsed();
            try {
                writer.addToBody(dic, dic.getIndirectReference());
            }
            catch (IOException e) {
                throw new ExceptionConverter(e);
            }
        }
    }
    return array;
}
项目:itext2    文件:PdfXConformanceImp.java   
public void completeInfoDictionary(PdfDictionary info) {
    if (isPdfX() && !isPdfA1()) {
        if (info.get(PdfName.GTS_PDFXVERSION) == null) {
            if (isPdfX1A2001()) {
                info.put(PdfName.GTS_PDFXVERSION, new PdfString("PDF/X-1:2001"));
                info.put(new PdfName("GTS_PDFXConformance"), new PdfString("PDF/X-1a:2001"));
            }
            else if (isPdfX32002())
                info.put(PdfName.GTS_PDFXVERSION, new PdfString("PDF/X-3:2002"));
        }
        if (info.get(PdfName.TITLE) == null) {
            info.put(PdfName.TITLE, new PdfString("Pdf document"));
        }
        if (info.get(PdfName.CREATOR) == null) {
            info.put(PdfName.CREATOR, new PdfString("Unknown"));
        }
        if (info.get(PdfName.TRAPPED) == null) {
            info.put(PdfName.TRAPPED, new PdfName("False"));
        }
    }
}
项目:itext2    文件:PngImage.java   
PdfObject getColorspace() {
    if (icc_profile != null) {
        if ((colorType & 2) == 0)
            return PdfName.DEVICEGRAY;
        else
            return PdfName.DEVICERGB;
    }
    if (gamma == 1f && !hasCHRM) {
        if ((colorType & 2) == 0)
            return PdfName.DEVICEGRAY;
        else
            return PdfName.DEVICERGB;
    }
    else {
        PdfArray array = new PdfArray();
        PdfDictionary dic = new PdfDictionary();
        if ((colorType & 2) == 0) {
            if (gamma == 1f)
                return PdfName.DEVICEGRAY;
            array.add(PdfName.CALGRAY);
            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);
                gm.add(n);
                gm.add(n);
                dic.put(PdfName.GAMMA, gm);
            }
            if (hasCHRM) {
                float z = yW*((xG-xB)*yR-(xR-xB)*yG+(xR-xG)*yB);
                float YA = yR*((xG-xB)*yW-(xW-xB)*yG+(xW-xG)*yB)/z;
                float XA = YA*xR/yR;
                float ZA = YA*((1-xR)/yR-1);
                float YB = -yG*((xR-xB)*yW-(xW-xB)*yR+(xW-xR)*yB)/z;
                float XB = YB*xG/yG;
                float ZB = YB*((1-xG)/yG-1);
                float YC = yB*((xR-xG)*yW-(xW-xG)*yW+(xW-xR)*yG)/z;
                float XC = YC*xB/yB;
                float ZC = YC*((1-xB)/yB-1);
                float XW = XA+XB+XC;
                float YW = 1;//YA+YB+YC;
                float ZW = ZA+ZB+ZC;
                PdfArray wpa = new PdfArray();
                wpa.add(new PdfNumber(XW));
                wpa.add(new PdfNumber(YW));
                wpa.add(new PdfNumber(ZW));
                wp = wpa;
                PdfArray matrix = new PdfArray();
                matrix.add(new PdfNumber(XA));
                matrix.add(new PdfNumber(YA));
                matrix.add(new PdfNumber(ZA));
                matrix.add(new PdfNumber(XB));
                matrix.add(new PdfNumber(YB));
                matrix.add(new PdfNumber(ZB));
                matrix.add(new PdfNumber(XC));
                matrix.add(new PdfNumber(YC));
                matrix.add(new PdfNumber(ZC));
                dic.put(PdfName.MATRIX, matrix);
            }
            dic.put(PdfName.WHITEPOINT, wp);
            array.add(dic);
        }
        return array;
    }
}
项目:itext2    文件:FieldPositioningEvents.java   
/**
 * @see com.lowagie.text.pdf.PdfPageEvent#onGenericTag(com.lowagie.text.pdf.PdfWriter, com.lowagie.text.Document, com.lowagie.text.Rectangle, java.lang.String)
 */
public void onGenericTag(PdfWriter writer, Document document,
        Rectangle rect, String text) {
    rect.setBottom(rect.getBottom() - 3);
    PdfFormField field = (PdfFormField) genericChunkFields.get(text);
    if (field == null) {
        TextField tf = new TextField(writer, new Rectangle(rect.getLeft(padding), rect.getBottom(padding), rect.getRight(padding), rect.getTop(padding)), text);
        tf.setFontSize(14);
        try {
            field = tf.getTextField();
        } catch (Exception e) {
            throw new ExceptionConverter(e);
        }
    }
    else {
        field.put(PdfName.RECT,  new PdfRectangle(rect.getLeft(padding), rect.getBottom(padding), rect.getRight(padding), rect.getTop(padding)));
    }
    if (parent == null)
        writer.addAnnotation(field);
    else
        parent.addKid(field);
}
项目:itext2    文件:PdfTargetDictionary.java   
/**
 * Creates a dictionary referring to a target document.
 * @param child if false, this refers to the parent document; if true, this refers to a child document, and you'll have to specify where to find the child using the other methods of this class
 */
public PdfTargetDictionary(boolean child) {
    super();
    if (child) {
        put(PdfName.R, PdfName.C);
    }
    else {
        put(PdfName.R, PdfName.P);
    }
}
项目:itext2    文件:PdfCollectionItem.java   
/**
 * Adds a prefix for the Collection item.
 * 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));
    put(fieldname, dict);
}
项目:itext2    文件:PdfCollectionSort.java   
/**
 * 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 = 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();
        for (int i = 0; i < ascending.length; i++) {
            array.add(new PdfBoolean(ascending[i]));
        }
        put(PdfName.A, array);
    }
    else {
        throw new IllegalArgumentException("You need a single boolean for this collection sort dictionary.");
    }
}
项目:jasperreports    文件:PdfGlyphRenderer.java   
@Override
public void draw()
{
    if (addActualText)
    {
        PdfDictionary markedContentProps = new PdfDictionary();
        markedContentProps.put(PdfName.ACTUALTEXT, new PdfString(allText, PdfObject.TEXT_UNICODE));
        pdfContentByte.beginMarkedContentSequence(PdfName.SPAN, markedContentProps, true);
    }

    TabSegment segment = segments.get(segmentIndex);
    segment.layout.draw(
            pdfGraphics2D,
            x + drawPosX,// + leftPadding,
            y + topPadding + verticalAlignOffset + drawPosY
            );

    if (addActualText)
    {
        pdfContentByte.endMarkedContentSequence();
    }

    return;
}
项目:zugferd    文件:PdfInvoiceReader.java   
public PdfAttachment unpackFile(PdfDictionary filespec) throws IOException {
    if (filespec == null)
        return null;
    PdfName type = filespec.getAsName(PdfName.TYPE);
    if (!PdfName.F.equals(type) && !PdfName.FILESPEC.equals(type))
        return null;
    PdfDictionary ef = filespec.getAsDict(PdfName.EF);
    if (ef == null)
        return null;
    PRStream prs = (PRStream)PdfReader.getPdfObject(ef.get(PdfName.F));
    if (prs == null)
        return null;
    PdfString pdfDesc = filespec.getAsString(PdfName.DESC);
    String desc = pdfDesc != null ? pdfDesc.toString() : "";
    PdfString pdfName = filespec.getAsString(PdfName.F);
    String name = pdfName != null ? pdfName.toString() : "";
    byte[] data = PdfReader.getStreamBytes(prs);
    return new PdfAttachment(name, desc, data);
}
项目:DroidText    文件:Image.java   
/**
 * Reuses an existing image.
 * @param ref the reference to the image dictionary
 * @throws BadElementException on error
 * @return the image
 */    
public static Image getInstance(PRIndirectReference ref) throws BadElementException {
    PdfDictionary dic = (PdfDictionary)PdfReader.getPdfObjectRelease(ref);
    int width = ((PdfNumber)PdfReader.getPdfObjectRelease(dic.get(PdfName.WIDTH))).intValue();
    int height = ((PdfNumber)PdfReader.getPdfObjectRelease(dic.get(PdfName.HEIGHT))).intValue();
    Image imask = null;
    PdfObject obj = dic.get(PdfName.SMASK);
    if (obj != null && obj.isIndirect()) {
        imask = getInstance((PRIndirectReference)obj);
    }
    else {
        obj = dic.get(PdfName.MASK);
        if (obj != null && obj.isIndirect()) {
            PdfObject obj2 = PdfReader.getPdfObjectRelease(obj);
            if (obj2 instanceof PdfDictionary)
                imask = getInstance((PRIndirectReference)obj);
        }
    }
    Image img = new ImgRaw(width, height, 1, 1, null);
    img.imageMask = imask;
    img.directReference = ref;
    return img;
}
项目:DroidText    文件:Image.java   
/**
 * Replaces CalRGB and CalGray colorspaces with DeviceRGB and DeviceGray.
 */    
public void simplifyColorspace() {
    if (additional == null)
        return;
    PdfArray value = additional.getAsArray(PdfName.COLORSPACE);
    if (value == null)
        return;
    PdfObject cs = simplifyColorspace(value);
    PdfObject newValue;
    if (cs.isName())
        newValue = cs;
    else {
        newValue = value;
        PdfName first = value.getAsName(0);
        if (PdfName.INDEXED.equals(first)) {
            if (value.size() >= 2) {
                PdfArray second = value.getAsArray(1);
                if (second != null) {
                    value.set(1, simplifyColorspace(second));
                }
            }
        }
    }
    additional.put(PdfName.COLORSPACE, newValue);
}
项目:DroidText    文件:Image.java   
/**
* Gets a PDF Name from an array or returns the object that was passed.
*/
  private PdfObject simplifyColorspace(PdfArray obj) {
      if (obj == null)
          return obj;
      PdfName first = obj.getAsName(0);
      if (PdfName.CALGRAY.equals(first))
          return PdfName.DEVICEGRAY;
      else if (PdfName.CALRGB.equals(first))
          return PdfName.DEVICERGB;
      else
          return obj;
  }
项目:DroidText    文件:PdfContentStreamProcessor.java   
public void invoke(PdfContentStreamProcessor processor, PdfLiteral operator, ArrayList operands) {
    PdfName dictionaryName = (PdfName)operands.get(0);
    PdfDictionary extGState = processor.resources.getAsDict(PdfName.EXTGSTATE);
    if (extGState == null)
        throw new IllegalArgumentException("Resources do not contain ExtGState entry. Unable to process operator " + operator);
    PdfDictionary gsDic = extGState.getAsDict(dictionaryName);
    if (gsDic == null)
        throw new IllegalArgumentException(dictionaryName + " is an unknown graphics state dictionary");

    // at this point, all we care about is the FONT entry in the GS dictionary
    PdfArray fontParameter = gsDic.getAsArray(PdfName.FONT);
    if (fontParameter != null){
        CMapAwareDocumentFont font = new CMapAwareDocumentFont((PRIndirectReference)fontParameter.getPdfObject(0));
        float size = fontParameter.getAsNumber(1).floatValue();

        processor.gs().font = font;
        processor.gs().fontSize = size;
    }            
}
项目:DroidText    文件:PdfVersionImp.java   
/**
 * Returns the PDF version as a name.
 * @param version   the version character.
 */
public PdfName getVersionAsName(char version) {
    switch(version) {
    case PdfWriter.VERSION_1_2:
        return PdfWriter.PDF_VERSION_1_2;
    case PdfWriter.VERSION_1_3:
        return PdfWriter.PDF_VERSION_1_3;
    case PdfWriter.VERSION_1_4:
        return PdfWriter.PDF_VERSION_1_4;
    case PdfWriter.VERSION_1_5:
        return PdfWriter.PDF_VERSION_1_5;
    case PdfWriter.VERSION_1_6:
        return PdfWriter.PDF_VERSION_1_6;
    case PdfWriter.VERSION_1_7:
        return PdfWriter.PDF_VERSION_1_7;
    default:
        return PdfWriter.PDF_VERSION_1_4;
    }
}
项目:DroidText    文件:PdfXConformanceImp.java   
public void completeInfoDictionary(PdfDictionary info) {
    if (isPdfX() && !isPdfA1()) {
        if (info.get(PdfName.GTS_PDFXVERSION) == null) {
            if (isPdfX1A2001()) {
                info.put(PdfName.GTS_PDFXVERSION, new PdfString("PDF/X-1:2001"));
                info.put(new PdfName("GTS_PDFXConformance"), new PdfString("PDF/X-1a:2001"));
            }
            else if (isPdfX32002())
                info.put(PdfName.GTS_PDFXVERSION, new PdfString("PDF/X-3:2002"));
        }
        if (info.get(PdfName.TITLE) == null) {
            info.put(PdfName.TITLE, new PdfString("Pdf document"));
        }
        if (info.get(PdfName.CREATOR) == null) {
            info.put(PdfName.CREATOR, new PdfString("Unknown"));
        }
        if (info.get(PdfName.TRAPPED) == null) {
            info.put(PdfName.TRAPPED, new PdfName("False"));
        }
    }
}
项目:DroidText    文件:FieldPositioningEvents.java   
/**
 * @see com.lowagie.text.pdf.PdfPageEvent#onGenericTag(com.lowagie.text.pdf.PdfWriter, com.lowagie.text.Document, com.lowagie.text.Rectangle, java.lang.String)
 */
public void onGenericTag(PdfWriter writer, Document document,
        Rectangle rect, String text) {
    rect.setBottom(rect.getBottom() - 3);
    PdfFormField field = (PdfFormField) genericChunkFields.get(text);
    if (field == null) {
        TextField tf = new TextField(writer, new Rectangle(rect.getLeft(padding), rect.getBottom(padding), rect.getRight(padding), rect.getTop(padding)), text);
        tf.setFontSize(14);
        try {
            field = tf.getTextField();
        } catch (Exception e) {
            throw new ExceptionConverter(e);
        }
    }
    else {
        field.put(PdfName.RECT,  new PdfRectangle(rect.getLeft(padding), rect.getBottom(padding), rect.getRight(padding), rect.getTop(padding)));
    }
    if (parent == null)
        writer.addAnnotation(field);
    else
        parent.addKid(field);
}
项目:DroidText    文件:PdfCollection.java   
/**
 * Constructs a PDF Collection.
 * @param   type    the type of PDF collection.
 */
public PdfCollection(int type) {
    super(PdfName.COLLECTION);
    switch(type) {
    case TILE:
        put(PdfName.VIEW, PdfName.T);
        break;
    case HIDDEN:
        put(PdfName.VIEW, PdfName.H);
        break;
    default:
        put(PdfName.VIEW, PdfName.D);
    }
}
项目:DroidText    文件:PdfCollectionSort.java   
/**
 * 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 = 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();
        for (int i = 0; i < ascending.length; i++) {
            array.add(new PdfBoolean(ascending[i]));
        }
        put(PdfName.A, array);
    }
    else {
        throw new IllegalArgumentException("You need a single boolean for this collection sort dictionary.");
    }
}
项目:itext2    文件:PdfContentStreamProcessor.java   
@Override
public PdfObject getDirectObject(PdfName key) {
    for (int i = stack.size() - 1; i >= 0; i--) {
        PdfDictionary dict = stack.get(i);
        PdfObject o = dict.getDirectObject(key);
        if (o != null) {
            return o;
        }
    }
    return null;
}
项目:itext2    文件:PdfContentStreamProcessor.java   
public void invoke(PdfContentStreamProcessor processor, PdfLiteral operator, ArrayList operands) {
    PdfName fontResourceName = (PdfName) operands.get(0);
    float size = ((PdfNumber) operands.get(1)).floatValue();

    PdfDictionary fontsDictionary = processor.resources.getAsDict(PdfName.FONT);
    CMapAwareDocumentFont font = new CMapAwareDocumentFont(
            (PRIndirectReference) fontsDictionary.get(fontResourceName));

    processor.gs().font = font;
    processor.gs().fontSize = size;

}
项目:itext2    文件:PdfVersionImp.java   
/** Adds the version to the Catalog dictionary. */
public void addToCatalog(PdfDictionary catalog) {
    if(catalog_version != null) {
        catalog.put(PdfName.VERSION, catalog_version);
    }
    if (extensions != null) {
        catalog.put(PdfName.EXTENSIONS, extensions);
    }
}
项目:itext2    文件:PdfXConformanceImp.java   
public void completeExtraCatalog(PdfDictionary extraCatalog) {
    if (isPdfX() && !isPdfA1()) {
        if (extraCatalog.get(PdfName.OUTPUTINTENTS) == null) {
            PdfDictionary out = new PdfDictionary(PdfName.OUTPUTINTENT);
            out.put(PdfName.OUTPUTCONDITION, new PdfString("SWOP CGATS TR 001-1995"));
            out.put(PdfName.OUTPUTCONDITIONIDENTIFIER, new PdfString("CGATS TR 001"));
            out.put(PdfName.REGISTRYNAME, new PdfString("http://www.color.org"));
            out.put(PdfName.INFO, new PdfString(""));
            out.put(PdfName.S, PdfName.GTS_PDFX);
            extraCatalog.put(PdfName.OUTPUTINTENTS, new PdfArray(out));
        }
    }
}
项目:itext2    文件:PdfViewerPreferencesImp.java   
/**
 * Sets the viewer preferences as the sum of several constants.
 * 
 * @param preferences
 *            the viewer preferences
 * @see PdfViewerPreferences#setViewerPreferences
 */
public void setViewerPreferences(int preferences) {
    this.pageLayoutAndMode |= preferences;
    // for backwards compatibility, it is also possible
    // to set the following viewer preferences with this method:
    if ((preferences & viewerPreferencesMask) != 0) {
        pageLayoutAndMode = ~viewerPreferencesMask & pageLayoutAndMode;
        if ((preferences & PdfWriter.HideToolbar) != 0)
            viewerPreferences.put(PdfName.HIDETOOLBAR, PdfBoolean.PDFTRUE);
        if ((preferences & PdfWriter.HideMenubar) != 0)
            viewerPreferences.put(PdfName.HIDEMENUBAR, PdfBoolean.PDFTRUE);
        if ((preferences & PdfWriter.HideWindowUI) != 0)
            viewerPreferences.put(PdfName.HIDEWINDOWUI, PdfBoolean.PDFTRUE);
        if ((preferences & PdfWriter.FitWindow) != 0)
            viewerPreferences.put(PdfName.FITWINDOW, PdfBoolean.PDFTRUE);
        if ((preferences & PdfWriter.CenterWindow) != 0)
            viewerPreferences.put(PdfName.CENTERWINDOW, PdfBoolean.PDFTRUE);
        if ((preferences & PdfWriter.DisplayDocTitle) != 0)
            viewerPreferences.put(PdfName.DISPLAYDOCTITLE, PdfBoolean.PDFTRUE);

        if ((preferences & PdfWriter.NonFullScreenPageModeUseNone) != 0)
            viewerPreferences.put(PdfName.NONFULLSCREENPAGEMODE, PdfName.USENONE);
        else if ((preferences & PdfWriter.NonFullScreenPageModeUseOutlines) != 0)
            viewerPreferences.put(PdfName.NONFULLSCREENPAGEMODE, PdfName.USEOUTLINES);
        else if ((preferences & PdfWriter.NonFullScreenPageModeUseThumbs) != 0)
            viewerPreferences.put(PdfName.NONFULLSCREENPAGEMODE, PdfName.USETHUMBS);
        else if ((preferences & PdfWriter.NonFullScreenPageModeUseOC) != 0)
            viewerPreferences.put(PdfName.NONFULLSCREENPAGEMODE, PdfName.USEOC);

        if ((preferences & PdfWriter.DirectionL2R) != 0)
            viewerPreferences.put(PdfName.DIRECTION, PdfName.L2R);
        else if ((preferences & PdfWriter.DirectionR2L) != 0)
            viewerPreferences.put(PdfName.DIRECTION, PdfName.R2L);

        if ((preferences & PdfWriter.PrintScalingNone) != 0)
            viewerPreferences.put(PdfName.PRINTSCALING, PdfName.NONE);          
    }
}
项目:itext2    文件:PdfViewerPreferencesImp.java   
/**
 * Given a key for a viewer preference (a PdfName object),
 * this method returns the index in the VIEWER_PREFERENCES array.
 * @param key   a PdfName referring to a viewer preference
 * @return  an index in the VIEWER_PREFERENCES array
 */
private int getIndex(PdfName key) {
    for (int i = 0; i < VIEWER_PREFERENCES.length; i++) {
        if (VIEWER_PREFERENCES[i].equals(key))
            return i;
    }
    return -1;
}
项目:itext2    文件:PdfViewerPreferencesImp.java   
/**
 * Checks if some value is valid for a certain key.
 */
private boolean isPossibleValue(PdfName value, PdfName[] accepted) {
    for (int i = 0; i < accepted.length; i++) {
        if (accepted[i].equals(value)) {
            return true;
        }
    }
    return false;
}
项目:itext2    文件:PdfViewerPreferencesImp.java   
/**
 * Adds the viewer preferences defined in the preferences parameter to a
 * PdfDictionary (more specifically the root or catalog of a PDF file).
 * 
 * @param catalog
 */
public void addToCatalog(PdfDictionary catalog) {
    // Page Layout
    catalog.remove(PdfName.PAGELAYOUT);
    if ((pageLayoutAndMode & PdfWriter.PageLayoutSinglePage) != 0)
        catalog.put(PdfName.PAGELAYOUT, PdfName.SINGLEPAGE);
    else if ((pageLayoutAndMode & PdfWriter.PageLayoutOneColumn) != 0)
        catalog.put(PdfName.PAGELAYOUT, PdfName.ONECOLUMN);
    else if ((pageLayoutAndMode & PdfWriter.PageLayoutTwoColumnLeft) != 0)
        catalog.put(PdfName.PAGELAYOUT, PdfName.TWOCOLUMNLEFT);
    else if ((pageLayoutAndMode & PdfWriter.PageLayoutTwoColumnRight) != 0)
        catalog.put(PdfName.PAGELAYOUT, PdfName.TWOCOLUMNRIGHT);
    else if ((pageLayoutAndMode & PdfWriter.PageLayoutTwoPageLeft) != 0)
        catalog.put(PdfName.PAGELAYOUT, PdfName.TWOPAGELEFT);
    else if ((pageLayoutAndMode & PdfWriter.PageLayoutTwoPageRight) != 0)
        catalog.put(PdfName.PAGELAYOUT, PdfName.TWOPAGERIGHT);

    // Page Mode
    catalog.remove(PdfName.PAGEMODE);
    if ((pageLayoutAndMode & PdfWriter.PageModeUseNone) != 0)
        catalog.put(PdfName.PAGEMODE, PdfName.USENONE);
    else if ((pageLayoutAndMode & PdfWriter.PageModeUseOutlines) != 0)
        catalog.put(PdfName.PAGEMODE, PdfName.USEOUTLINES);
    else if ((pageLayoutAndMode & PdfWriter.PageModeUseThumbs) != 0)
        catalog.put(PdfName.PAGEMODE, PdfName.USETHUMBS);
    else if ((pageLayoutAndMode & PdfWriter.PageModeFullScreen) != 0)
        catalog.put(PdfName.PAGEMODE, PdfName.FULLSCREEN);
    else if ((pageLayoutAndMode & PdfWriter.PageModeUseOC) != 0)
        catalog.put(PdfName.PAGEMODE, PdfName.USEOC);
    else if ((pageLayoutAndMode & PdfWriter.PageModeUseAttachments) != 0)
        catalog.put(PdfName.PAGEMODE, PdfName.USEATTACHMENTS);

    // viewer preferences (Table 8.1 of the PDF Reference)
    catalog.remove(PdfName.VIEWERPREFERENCES);
    if (viewerPreferences.size() > 0) {
        catalog.put(PdfName.VIEWERPREFERENCES, viewerPreferences);
    }
}
项目:itext2    文件:BmpImage.java   
private Image indexedModel(byte bdata[], int bpc, int paletteEntries) throws BadElementException {
    Image img = new ImgRaw(width, height, 1, bpc, bdata);
    PdfArray colorspace = new PdfArray();
    colorspace.add(PdfName.INDEXED);
    colorspace.add(PdfName.DEVICERGB);
    byte np[] = getPalette(paletteEntries);
    int len = np.length;
    colorspace.add(new PdfNumber(len / 3 - 1));
    colorspace.add(new PdfString(np));
    PdfDictionary ad = new PdfDictionary();
    ad.put(PdfName.COLORSPACE, colorspace);
    img.setAdditional(ad);
    return img;
}
项目:itext2    文件:FieldPositioningEvents.java   
/**
 * @see com.lowagie.text.pdf.PdfPCellEvent#cellLayout(com.lowagie.text.pdf.PdfPCell, com.lowagie.text.Rectangle, com.lowagie.text.pdf.PdfContentByte[])
 */
public void cellLayout(PdfPCell cell, Rectangle rect, PdfContentByte[] canvases) {
    if (cellField == null || (fieldWriter == null && parent == null)) throw new ExceptionConverter(new IllegalArgumentException("You have used the wrong constructor for this FieldPositioningEvents class."));
    cellField.put(PdfName.RECT, new PdfRectangle(rect.getLeft(padding), rect.getBottom(padding), rect.getRight(padding), rect.getTop(padding)));
    if (parent == null)
        fieldWriter.addAnnotation(cellField);
    else
        parent.addKid(cellField);
}
项目:itext2    文件:PdfCollectionField.java   
/**
 * Creates a PdfCollectionField.
 * @param name      the field name
 * @param type      the field type
 */
public PdfCollectionField(String name, int type) {
    super(PdfName.COLLECTIONFIELD);
    put(PdfName.N, new PdfString(name, PdfObject.TEXT_UNICODE));
    this.fieldType = type;
    switch(type) {
    default:
        put(PdfName.SUBTYPE, PdfName.S);
        break;
    case DATE:
        put(PdfName.SUBTYPE, PdfName.D);
        break;
    case NUMBER:
        put(PdfName.SUBTYPE, PdfName.N);
        break;
    case FILENAME:
        put(PdfName.SUBTYPE, PdfName.F);
        break;
    case DESC:
        put(PdfName.SUBTYPE, PdfName.DESC);
        break;
    case MODDATE:
        put(PdfName.SUBTYPE, PdfName.MODDATE);
        break;
    case CREATIONDATE:
        put(PdfName.SUBTYPE, PdfName.CREATIONDATE);
        break;
    case SIZE:
        put(PdfName.SUBTYPE, PdfName.SIZE);
        break;
    }
}
项目:itext2    文件:PdfCollectionField.java   
/**
 * Returns a PdfObject that can be used as the value of a Collection Item.
 * @param v value   the value that has to be changed into a PdfObject (PdfString, PdfDate or PdfNumber) 
 */
public PdfObject getValue(String v) {
    switch(fieldType) {
    case TEXT:
        return new PdfString(v, PdfObject.TEXT_UNICODE);
    case DATE:
        return new PdfDate(PdfDate.decode(v));
    case NUMBER:
        return new PdfNumber(v);
    }
    throw new IllegalArgumentException(v + " is not an acceptable value for the field " + get(PdfName.N).toString());
}
项目:itext2    文件:PdfTargetDictionary.java   
/**
 * Creates dictionary referring to a target document that is the parent of the current document.
 * @param nested    null if this is the actual target, another target if this is only an intermediate target.
 */
public PdfTargetDictionary(PdfTargetDictionary nested) {
    super();
    put(PdfName.R, PdfName.P);
    if (nested != null)
        setAdditionalPath(nested);
}
项目:itext2    文件:PdfCollectionItem.java   
/**
 * Sets the value of the collection item.
 * @param n
 */
public void addItem(String key, PdfNumber n) {
    PdfName fieldname = new PdfName(key);
    PdfCollectionField field = (PdfCollectionField)schema.get(fieldname);
    if (field.fieldType == PdfCollectionField.NUMBER) {
        put(fieldname, n);
    }
}
项目:itext2    文件:PdfCollectionSort.java   
/**
 * Constructs a PDF Collection Sort Dictionary.
 * @param keys  the keys of the fields that will be used to sort entries
 */
public PdfCollectionSort(String[] keys) {
    super(PdfName.COLLECTIONSORT);
    PdfArray array = new PdfArray();
    for (int i = 0; i < keys.length; i++) {
        array.add(new PdfName(keys[i]));
    }
    put(PdfName.S, array);
}
项目:itext2    文件:LayersTest.java   
/**
 * Demonstrates some Layer functionality.
 * 
 */
@Test
public void main() throws Exception {

    // step 1: creation of a document-object
    Document document = new Document();
    // step 2:
    PdfWriter writer = PdfWriter.getInstance(document, PdfTestBase.getOutputStream("Layers.pdf"));
    writer.setPdfVersion(PdfWriter.VERSION_1_5);
    // step 3:
    writer.setViewerPreferences(PdfWriter.PageModeUseOC);
    document.open();
    // step 4:
    PdfContentByte cb = writer.getDirectContent();
    Phrase explanation = new Phrase("Layer grouping", new Font(Font.HELVETICA, 20, Font.BOLD, Color.red));
    ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, explanation, 50, 650, 0);
    PdfLayer l1 = new PdfLayer("Layer 1", writer);
    PdfLayer l2 = new PdfLayer("Layer 2", writer);
    PdfLayer l3 = new PdfLayer("Layer 3", writer);
    PdfLayerMembership m1 = new PdfLayerMembership(writer);
    m1.addMember(l2);
    m1.addMember(l3);
    Phrase p1 = new Phrase("Text in layer 1");
    Phrase p2 = new Phrase("Text in layer 2 or layer 3");
    Phrase p3 = new Phrase("Text in layer 3");
    cb.beginLayer(l1);
    ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, p1, 50, 600, 0);
    cb.endLayer();
    cb.beginLayer(m1);
    ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, p2, 50, 550, 0);
    cb.endLayer();
    cb.beginLayer(l3);
    ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, p3, 50, 500, 0);
    cb.endLayer();
    PdfOCProperties p = writer.getOCProperties();
    PdfArray order = new PdfArray();
    order.add(l1.getRef());
    PdfArray group = new PdfArray();
    group.add(new PdfString("A group of two", PdfObject.TEXT_UNICODE));
    group.add(l2.getRef());
    group.add(l3.getRef());
    order.add(group);
    PdfDictionary d = new PdfDictionary();
    d.put(PdfName.ORDER, order);
    p.put(PdfName.D, d);

    // step 5: we close the document
    document.close();
}