当前位置: 首页>>代码示例>>Java>>正文


Java PdfName类代码示例

本文整理汇总了Java中com.lowagie.text.pdf.PdfName的典型用法代码示例。如果您正苦于以下问题:Java PdfName类的具体用法?Java PdfName怎么用?Java PdfName使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


PdfName类属于com.lowagie.text.pdf包,在下文中一共展示了PdfName类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: simplifyColorspace

import com.lowagie.text.pdf.PdfName; //导入依赖的package包/类
/**
 * 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);
}
 
开发者ID:albfernandez,项目名称:itext2,代码行数:28,代码来源:Image.java

示例2: getTextFromPage

import com.lowagie.text.pdf.PdfName; //导入依赖的package包/类
/**
   * 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();
  }
 
开发者ID:albfernandez,项目名称:itext2,代码行数:23,代码来源:PdfTextExtractor.java

示例3: invoke

import com.lowagie.text.pdf.PdfName; //导入依赖的package包/类
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;
	}
}
 
开发者ID:albfernandez,项目名称:itext2,代码行数:24,代码来源:PdfContentStreamProcessor.java

示例4: getVersionAsName

import com.lowagie.text.pdf.PdfName; //导入依赖的package包/类
/**
 * 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;
	}
}
 
开发者ID:albfernandez,项目名称:itext2,代码行数:23,代码来源:PdfVersionImp.java

示例5: rotateAnnotations

import com.lowagie.text.pdf.PdfName; //导入依赖的package包/类
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;
}
 
开发者ID:albfernandez,项目名称:itext2,代码行数:65,代码来源:PdfAnnotationsImp.java

示例6: completeInfoDictionary

import com.lowagie.text.pdf.PdfName; //导入依赖的package包/类
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"));
        }
    }
}
 
开发者ID:albfernandez,项目名称:itext2,代码行数:22,代码来源:PdfXConformanceImp.java

示例7: getColorspace

import com.lowagie.text.pdf.PdfName; //导入依赖的package包/类
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;
    }
}
 
开发者ID:albfernandez,项目名称:itext2,代码行数:73,代码来源:PngImage.java

示例8: onGenericTag

import com.lowagie.text.pdf.PdfName; //导入依赖的package包/类
/**
 * @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);
}
 
开发者ID:albfernandez,项目名称:itext2,代码行数:25,代码来源:FieldPositioningEvents.java

示例9: PdfTargetDictionary

import com.lowagie.text.pdf.PdfName; //导入依赖的package包/类
/**
 * 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);
	}
}
 
开发者ID:albfernandez,项目名称:itext2,代码行数:14,代码来源:PdfTargetDictionary.java

示例10: setPrefix

import com.lowagie.text.pdf.PdfName; //导入依赖的package包/类
/**
 * 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);
}
 
开发者ID:albfernandez,项目名称:itext2,代码行数:16,代码来源:PdfCollectionItem.java

示例11: setSortOrder

import com.lowagie.text.pdf.PdfName; //导入依赖的package包/类
/**
 * 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.");
	}
}
 
开发者ID:albfernandez,项目名称:itext2,代码行数:21,代码来源:PdfCollectionSort.java

示例12: draw

import com.lowagie.text.pdf.PdfName; //导入依赖的package包/类
@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;
}
 
开发者ID:TIBCOSoftware,项目名称:jasperreports,代码行数:25,代码来源:PdfGlyphRenderer.java

示例13: unpackFile

import com.lowagie.text.pdf.PdfName; //导入依赖的package包/类
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);
}
 
开发者ID:opendatalab-de,项目名称:zugferd,代码行数:20,代码来源:PdfInvoiceReader.java

示例14: getInstance

import com.lowagie.text.pdf.PdfName; //导入依赖的package包/类
/**
 * 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;
}
 
开发者ID:bullda,项目名称:DroidText,代码行数:29,代码来源:Image.java

示例15: invoke

import com.lowagie.text.pdf.PdfName; //导入依赖的package包/类
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;
    }            
}
 
开发者ID:bullda,项目名称:DroidText,代码行数:20,代码来源:PdfContentStreamProcessor.java


注:本文中的com.lowagie.text.pdf.PdfName类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。