com.lowagie.text.pdf.PRIndirectReference Java Examples

The following examples show how to use com.lowagie.text.pdf.PRIndirectReference. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Image.java    From gcs with Mozilla Public License 2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example #2
Source File: PdfContentStreamProcessor.java    From gcs with Mozilla Public License 2.0 6 votes vote down vote up
@Override
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;
	}
}
 
Example #3
Source File: Image.java    From itext2 with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * 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;
}
 
Example #4
Source File: PdfContentStreamProcessor.java    From itext2 with GNU Lesser General Public License v3.0 6 votes vote down vote up
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;
	}
}
 
Example #5
Source File: PdfContentStreamProcessor.java    From gcs with Mozilla Public License 2.0 5 votes vote down vote up
@Override
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;

}
 
Example #6
Source File: PdfContentStreamProcessor.java    From itext2 with GNU Lesser General Public License v3.0 5 votes vote down vote up
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;

}
 
Example #7
Source File: PdfContentStreamProcessorTest.java    From itext2 with GNU Lesser General Public License v3.0 5 votes vote down vote up
private byte[] readContentBytes(final PdfObject contentObject) throws IOException {
	final byte[] result;
	switch (contentObject.type()) {
	case PdfObject.INDIRECT:
		final PRIndirectReference ref = (PRIndirectReference) contentObject;
		final PdfObject directObject = PdfReader.getPdfObject(ref);
		result = readContentBytes(directObject);
		break;
	case PdfObject.STREAM:
		final PRStream stream = (PRStream) PdfReader.getPdfObject(contentObject);
		result = PdfReader.getStreamBytes(stream);
		break;
	case PdfObject.ARRAY:
		// Stitch together all content before calling processContent(),
		// because
		// processContent() resets state.
		final ByteArrayOutputStream allBytes = new ByteArrayOutputStream();
		final PdfArray contentArray = (PdfArray) contentObject;
		final ListIterator<?> iter = contentArray.listIterator();
		while (iter.hasNext()) {
			final PdfObject element = (PdfObject) iter.next();
			allBytes.write(readContentBytes(element));
		}
		result = allBytes.toByteArray();
		break;
	default:
		final String msg = "Unable to handle Content of type " + contentObject.getClass();
		throw new IllegalStateException(msg);
	}
	return result;
}
 
Example #8
Source File: ITextPDFSignatureService.java    From dss with GNU Lesser General Public License v2.1 5 votes vote down vote up
private PdfObject getPdfObjectForToken(Token token, Map<String, Long> knownObjects, PdfReader reader, PdfWriter writer)
		throws IOException {
	String digest = getTokenDigest(token);
	Long objectNumber = knownObjects.get(digest);
	if (objectNumber == null) {
		PdfStream ps = new PdfStream(token.getEncoded());
		return writer.addToBody(ps, false).getIndirectReference();
	} else {
		return new PRIndirectReference(reader, objectNumber.intValue());
	}
}