com.lowagie.text.pdf.PdfLiteral Java Examples

The following examples show how to use com.lowagie.text.pdf.PdfLiteral. 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: Prd5873Test.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
public void invokeOperator(PdfLiteral pdfLiteral, ArrayList arrayList) {
    super.invokeOperator(pdfLiteral, arrayList);
    String op = pdfLiteral.toString();
    if (Objects.equals(op, "q")) {
        if (textModeActive) {
            throw new RuntimeException("Cannot mix text mode and graphics operations.");
        }

        graphicsState.push(Boolean.TRUE);
    } else if (Objects.equals(op, "Q")) {
        if (textModeActive) {
            throw new RuntimeException("Cannot mix text mode and graphics operations.");
        }

        graphicsState.pop();
    } else if (Objects.equals(op, "BT")) {
        textModeActive = true;
    } else if (Objects.equals(op, "ET")) {
        textModeActive = false;
    }
}
 
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: 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) {
	PdfNumber aw = (PdfNumber) operands.get(0);
	PdfNumber ac = (PdfNumber) operands.get(1);
	PdfString string = (PdfString) operands.get(2);

	ArrayList twOperands = new ArrayList(1);
	twOperands.add(0, aw);
	processor.invokeOperator(new PdfLiteral("Tw"), twOperands);

	ArrayList tcOperands = new ArrayList(1);
	tcOperands.add(0, ac);
	processor.invokeOperator(new PdfLiteral("Tc"), tcOperands);

	ArrayList tickOperands = new ArrayList(1);
	tickOperands.add(0, string);
	processor.invokeOperator(new PdfLiteral("'"), tickOperands);
}
 
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 6 votes vote down vote up
@Override
public void invoke(PdfContentStreamProcessor processor, PdfLiteral operator, ArrayList operands) {
	PdfNumber aw = (PdfNumber) operands.get(0);
	PdfNumber ac = (PdfNumber) operands.get(1);
	PdfString string = (PdfString) operands.get(2);

	ArrayList twOperands = new ArrayList(1);
	twOperands.add(0, aw);
	processor.invokeOperator(new PdfLiteral("Tw"), twOperands);

	ArrayList tcOperands = new ArrayList(1);
	tcOperands.add(0, ac);
	processor.invokeOperator(new PdfLiteral("Tc"), tcOperands);

	ArrayList tickOperands = new ArrayList(1);
	tickOperands.add(0, string);
	processor.invokeOperator(new PdfLiteral("'"), tickOperands);
}
 
Example #6
Source File: ITextPDFSignatureService.java    From dss with GNU Lesser General Public License v2.1 6 votes vote down vote up
private PdfObject generateFileId(PAdESCommonParameters parameters) {
	try (ByteBuffer buf = new ByteBuffer(90)) {
		String deterministicId = DSSUtils.getDeterministicId(parameters.getSigningDate(), null);
		byte[] id = deterministicId.getBytes();
		buf.append('[').append('<');
		for (int k = 0; k < 16; ++k) {
			buf.appendHex(id[k]);
		}
		buf.append('>').append('<');
		for (int k = 0; k < 16; ++k) {
			buf.appendHex(id[k]);
		}
		buf.append('>').append(']');
		return new PdfLiteral(buf.toByteArray());
	} catch (IOException e) {
		throw new DSSException("Unable to generate the fileId", e);
	}
}
 
Example #7
Source File: PdfContentStreamProcessor.java    From gcs with Mozilla Public License 2.0 6 votes vote down vote up
/**
 * Processes PDF syntax
 *
 * @param contentBytes the bytes of a content stream
 * @param resources the resources that come with the content stream
 */
public void processContent(byte[] contentBytes, PdfDictionary resources) {

	reset();
	this.resources = resources;
	try {
		PdfContentParser ps = new PdfContentParser(new PRTokeniser(contentBytes));
		ArrayList operands = new ArrayList();
		while (ps.parse(operands).size() > 0) {
			PdfLiteral operator = (PdfLiteral) operands.get(operands.size() - 1);
			invokeOperator(operator, operands);
		}

	} catch (Exception e) {
		throw new ExceptionConverter(e);
	}

}
 
Example #8
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) {
	float a = ((PdfNumber) operands.get(0)).floatValue();
	float b = ((PdfNumber) operands.get(1)).floatValue();
	float c = ((PdfNumber) operands.get(2)).floatValue();
	float d = ((PdfNumber) operands.get(3)).floatValue();
	float e = ((PdfNumber) operands.get(4)).floatValue();
	float f = ((PdfNumber) operands.get(5)).floatValue();
	Matrix matrix = new Matrix(a, b, c, d, e, f);
	GraphicsState gs = (GraphicsState) processor.gsStack.peek();
	gs.ctm = gs.ctm.multiply(matrix);
}
 
Example #9
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 #10
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) {
	float tx = ((PdfNumber) operands.get(0)).floatValue();
	float ty = ((PdfNumber) operands.get(1)).floatValue();

	Matrix translationMatrix = new Matrix(tx, ty);
	processor.textMatrix = translationMatrix.multiply(processor.textLineMatrix);
	processor.textLineMatrix = processor.textMatrix;
}
 
Example #11
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) {
	float ty = ((PdfNumber) operands.get(1)).floatValue();

	ArrayList tlOperands = new ArrayList(1);
	tlOperands.add(0, new PdfNumber(-ty));
	processor.invokeOperator(new PdfLiteral("TL"), tlOperands);
	processor.invokeOperator(new PdfLiteral("Td"), operands);
}
 
Example #12
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) {
	float a = ((PdfNumber) operands.get(0)).floatValue();
	float b = ((PdfNumber) operands.get(1)).floatValue();
	float c = ((PdfNumber) operands.get(2)).floatValue();
	float d = ((PdfNumber) operands.get(3)).floatValue();
	float e = ((PdfNumber) operands.get(4)).floatValue();
	float f = ((PdfNumber) operands.get(5)).floatValue();

	processor.textLineMatrix = new Matrix(a, b, c, d, e, f);
	processor.textMatrix = processor.textLineMatrix;
}
 
Example #13
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) {
	PdfArray array = (PdfArray) operands.get(0);
	float tj = 0;
	for (Iterator i = array.listIterator(); i.hasNext();) {
		Object entryObj = i.next();
		if (entryObj instanceof PdfString) {
			processor.displayPdfString((PdfString) entryObj, tj);
			tj = 0;
		} else {
			tj = ((PdfNumber) entryObj).floatValue();
		}
	}

}
 
Example #14
Source File: PdfContentStreamProcessor.java    From itext2 with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
    * Processes PDF syntax
    * @param contentBytes	the bytes of a content stream
    * @param resources		the resources that come with the content stream
    */
public void processContent(byte[] contentBytes, PdfDictionary resources) {
	this.resources.push(resources);
	try {
		PdfContentParser ps = new PdfContentParser(new PRTokeniser(contentBytes));
		ArrayList operands = new ArrayList();
		while (ps.parse(operands).size() > 0) {
			PdfLiteral operator = (PdfLiteral) operands.get(operands.size() - 1);
			invokeOperator(operator, operands);
		}
	} catch (Exception e) {
		throw new ExceptionConverter(e);
	}
	this.resources.pop();
}
 
Example #15
Source File: PdfContentStreamProcessor.java    From itext2 with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
    * Invokes an operator.
    * @param operator	the PDF Syntax of the operator
    * @param operands	a list with operands
    */
public void invokeOperator(PdfLiteral operator, ArrayList operands) {
	ContentOperator op = operators.get(operator.toString());
	if (op == null) {
		// skipping unssupported operator
		return;
	}
	op.invoke(this, operator, operands);
}
 
Example #16
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) {
	float a = ((PdfNumber) operands.get(0)).floatValue();
	float b = ((PdfNumber) operands.get(1)).floatValue();
	float c = ((PdfNumber) operands.get(2)).floatValue();
	float d = ((PdfNumber) operands.get(3)).floatValue();
	float e = ((PdfNumber) operands.get(4)).floatValue();
	float f = ((PdfNumber) operands.get(5)).floatValue();
	Matrix matrix = new Matrix(a, b, c, d, e, f);
	GraphicsState gs = (GraphicsState) processor.gsStack.peek();
	gs.ctm = gs.ctm.multiply(matrix);
}
 
Example #17
Source File: PdfContentStreamProcessor.java    From gcs with Mozilla Public License 2.0 5 votes vote down vote up
/**
 * Invokes an operator.
 *
 * @param operator the PDF Syntax of the operator
 * @param operands a list with operands
 */
public void invokeOperator(PdfLiteral operator, ArrayList operands) {
	ContentOperator op = (ContentOperator) operators.get(operator.toString());
	if (op == null) {
		// System.out.println("Skipping operator " + operator);
		return;
	}

	op.invoke(this, operator, operands);
}
 
Example #18
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) {
	ArrayList tdoperands = new ArrayList(2);
	tdoperands.add(0, new PdfNumber(0));
	tdoperands.add(1, new PdfNumber(processor.gs().leading));
	processor.invokeOperator(new PdfLiteral("Td"), tdoperands);
}
 
Example #19
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) {
	PdfArray array = (PdfArray) operands.get(0);
	float tj = 0;
	for (Iterator i = array.listIterator(); i.hasNext();) {
		Object entryObj = i.next();
		if (entryObj instanceof PdfString) {
			processor.displayPdfString((PdfString) entryObj, tj);
			tj = 0;
		} else {
			tj = ((PdfNumber) entryObj).floatValue();
		}
	}

}
 
Example #20
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) {
	float a = ((PdfNumber) operands.get(0)).floatValue();
	float b = ((PdfNumber) operands.get(1)).floatValue();
	float c = ((PdfNumber) operands.get(2)).floatValue();
	float d = ((PdfNumber) operands.get(3)).floatValue();
	float e = ((PdfNumber) operands.get(4)).floatValue();
	float f = ((PdfNumber) operands.get(5)).floatValue();

	processor.textLineMatrix = new Matrix(a, b, c, d, e, f);
	processor.textMatrix = processor.textLineMatrix;
}
 
Example #21
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) {
	float ty = ((PdfNumber) operands.get(1)).floatValue();

	ArrayList tlOperands = new ArrayList(1);
	tlOperands.add(0, new PdfNumber(-ty));
	processor.invokeOperator(new PdfLiteral("TL"), tlOperands);
	processor.invokeOperator(new PdfLiteral("Td"), operands);
}
 
Example #22
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) {
	float tx = ((PdfNumber) operands.get(0)).floatValue();
	float ty = ((PdfNumber) operands.get(1)).floatValue();

	Matrix translationMatrix = new Matrix(tx, ty);
	processor.textMatrix = translationMatrix.multiply(processor.textLineMatrix);
	processor.textLineMatrix = processor.textMatrix;
}
 
Example #23
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 #24
Source File: PdfContentStreamProcessor.java    From itext2 with GNU Lesser General Public License v3.0 4 votes vote down vote up
public void invoke(PdfContentStreamProcessor processor, PdfLiteral operator, ArrayList operands) {
	PdfNumber wordSpace = (PdfNumber) operands.get(0);
	processor.gs().wordSpacing = wordSpace.floatValue();
}
 
Example #25
Source File: PdfContentStreamProcessor.java    From itext2 with GNU Lesser General Public License v3.0 4 votes vote down vote up
public void invoke(PdfContentStreamProcessor processor, PdfLiteral operator, ArrayList operands) {
	PdfNumber rise = (PdfNumber) operands.get(0);
	processor.gs().rise = rise.floatValue();
}
 
Example #26
Source File: PdfContentStreamProcessor.java    From itext2 with GNU Lesser General Public License v3.0 4 votes vote down vote up
public void invoke(PdfContentStreamProcessor processor, PdfLiteral operator, ArrayList operands) {
	PdfNumber leading = (PdfNumber) operands.get(0);
	processor.gs().leading = leading.floatValue();
}
 
Example #27
Source File: PdfContentStreamProcessor.java    From itext2 with GNU Lesser General Public License v3.0 4 votes vote down vote up
public void invoke(PdfContentStreamProcessor processor, PdfLiteral operator, ArrayList operands) {
	PdfNumber scale = (PdfNumber) operands.get(0);
	processor.gs().horizontalScaling = scale.floatValue();
}
 
Example #28
Source File: PdfContentStreamProcessor.java    From itext2 with GNU Lesser General Public License v3.0 4 votes vote down vote up
public void invoke(PdfContentStreamProcessor processor, PdfLiteral operator, ArrayList operands) {
	PdfNumber charSpace = (PdfNumber) operands.get(0);
	processor.gs().characterSpacing = charSpace.floatValue();
}
 
Example #29
Source File: PngImage.java    From MesquiteCore with GNU Lesser General Public License v3.0 4 votes vote down vote up
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;
    }
}
 
Example #30
Source File: PdfContentStreamProcessor.java    From gcs with Mozilla Public License 2.0 4 votes vote down vote up
@Override
public void invoke(PdfContentStreamProcessor processor, PdfLiteral operator, ArrayList operands) {
	PdfString string = (PdfString) operands.get(0);

	processor.displayPdfString(string, 0);
}