com.lowagie.text.pdf.PdfArray Java Examples

The following examples show how to use com.lowagie.text.pdf.PdfArray. 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: PdfContentStreamProcessor.java    From itext2 with GNU Lesser General Public License v3.0 6 votes vote down vote up
public static byte[] getContentBytesFromPdfObject(PdfObject object) throws IOException {
	switch (object.type()) {
	case PdfObject.INDIRECT:
		return getContentBytesFromPdfObject(PdfReader.getPdfObject(object));
	case PdfObject.STREAM:
		return PdfReader.getStreamBytes((PRStream) PdfReader.getPdfObject(object));
	case PdfObject.ARRAY:
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		ListIterator<PdfObject> iter = ((PdfArray) object).listIterator();
		while (iter.hasNext()) {
			PdfObject element = iter.next();
			baos.write(getContentBytesFromPdfObject(element));
		}
		return baos.toByteArray();
	default:
		throw new IllegalStateException("Unsupported type: " + object.getClass().getCanonicalName());
	}
}
 
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) {
	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 #4
Source File: PdfCollectionSort.java    From itext2 with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * 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.");
	}
}
 
Example #5
Source File: Image.java    From itext2 with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * 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);
}
 
Example #6
Source File: PdfCollectionSort.java    From gcs with Mozilla Public License 2.0 6 votes vote down vote up
/**
 * 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.");
	}
}
 
Example #7
Source File: JRPdfExporterTagHelper.java    From jasperreports with GNU Lesser General Public License v3.0 5 votes vote down vote up
protected void createStartHeadingTags(String prop, PdfName pdfName)
{
	if (TAG_START.equals(prop) || TAG_FULL.equals(prop))
	{
		PdfStructureElement headingTag = new PdfStructureElement(tagStack.peek(), pdfName);
		//pdfContentByte.beginMarkedContentSequence(headingTag);
		headingTag.put(PdfName.K, new PdfArray());
		tagStack.push(headingTag);
		isTagEmpty = true;
	}
}
 
Example #8
Source File: BmpImage.java    From itext2 with GNU Lesser General Public License v3.0 5 votes vote down vote up
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;
}
 
Example #9
Source File: PdfCollectionSort.java    From itext2 with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * 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);
}
 
Example #10
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 #11
Source File: Image.java    From gcs with Mozilla Public License 2.0 5 votes vote down vote up
/**
 * 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;
	}
}
 
Example #12
Source File: JRPdfExporterTagHelper.java    From jasperreports with GNU Lesser General Public License v3.0 5 votes vote down vote up
protected void createTableStartTag()
{
	PdfStructureElement tableTag = new PdfStructureElement(allTag, PdfName.TABLE);
	//pdfContentByte.beginMarkedContentSequence(tableTag);
	tableTag.put(PdfName.K, new PdfArray());
	tagStack.push(tableTag);
}
 
Example #13
Source File: JRPdfExporterTagHelper.java    From jasperreports with GNU Lesser General Public License v3.0 5 votes vote down vote up
protected void createTrStartTag()
{
	PdfStructureElement tableRowTag = new PdfStructureElement(tagStack.peek(), PdfName.TABLEROW);
	//pdfContentByte.beginMarkedContentSequence(tableRowTag);
	tableRowTag.put(PdfName.K, new PdfArray());
	tagStack.push(tableRowTag);
}
 
Example #14
Source File: JRPdfExporterTagHelper.java    From jasperreports with GNU Lesser General Public License v3.0 5 votes vote down vote up
protected void createThStartTag(JRPrintElement element)
{
	PdfStructureElement tableHeaderTag = new PdfStructureElement(tagStack.peek(), PdfName.TH);
	//pdfContentByte.beginMarkedContentSequence(tableHeaderTag);
	tableHeaderTag.put(PdfName.K, new PdfArray());
	tagStack.push(tableHeaderTag);
	isTagEmpty = true;
	
	createSpanTags(element, tableHeaderTag);
}
 
Example #15
Source File: JRPdfExporterTagHelper.java    From jasperreports with GNU Lesser General Public License v3.0 5 votes vote down vote up
protected void createTdStartTag(JRPrintElement element)
{
	PdfStructureElement tableCellTag = new PdfStructureElement(tagStack.peek(), PdfName.TD);
	//pdfContentByte.beginMarkedContentSequence(tableCellTag);
	tableCellTag.put(PdfName.K, new PdfArray());
	tagStack.push(tableCellTag);
	isTagEmpty = true;
	
	createSpanTags(element, tableCellTag);
}
 
Example #16
Source File: JRPdfExporterTagHelper.java    From jasperreports with GNU Lesser General Public License v3.0 5 votes vote down vote up
protected void createListStartTag()
{
	PdfStructureElement listTag = new PdfStructureElement(allTag, PdfName.L);
	//pdfContentByte.beginMarkedContentSequence(tableTag);
	listTag.put(PdfName.K, new PdfArray());
	tagStack.push(listTag);
}
 
Example #17
Source File: JRPdfExporterTagHelper.java    From jasperreports with GNU Lesser General Public License v3.0 5 votes vote down vote up
protected void createListItemStartTag(JRPrintElement element)
{
	PdfStructureElement listItemTag = new PdfStructureElement(tagStack.peek(), PdfName.LI);
	//pdfContentByte.beginMarkedContentSequence(tableHeaderTag);
	listItemTag.put(PdfName.K, new PdfArray());
	tagStack.push(listItemTag);
	isTagEmpty = true;
}
 
Example #18
Source File: PaperightPdfConverter.java    From website with GNU Affero General Public License v3.0 5 votes vote down vote up
public String cropPdf(String pdfFilePath) throws DocumentException, IOException, Exception {
	String filename = FilenameUtils.getBaseName(pdfFilePath) + "_cropped." + FilenameUtils.getExtension(pdfFilePath);
	filename = FilenameUtils.concat(System.getProperty("java.io.tmpdir"), filename);
	PdfReader reader = new PdfReader(pdfFilePath);
	try {
		PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(filename));
		try {
			for (int i = 1; i <= reader.getNumberOfPages(); i++) {
				PdfDictionary pdfDictionary = reader.getPageN(i);
				PdfArray cropArray = new PdfArray();
				Rectangle box = getSmallestBox(reader, i);
				//Rectangle cropbox = reader.getCropBox(i);
				if (box != null) {
					cropArray.add(new PdfNumber(box.getLeft()));
					cropArray.add(new PdfNumber(box.getBottom()));
					cropArray.add(new PdfNumber(box.getLeft() + box.getWidth()));
					cropArray.add(new PdfNumber(box.getBottom() + box.getHeight()));
					pdfDictionary.put(PdfName.CROPBOX, cropArray);
					pdfDictionary.put(PdfName.MEDIABOX, cropArray);
					pdfDictionary.put(PdfName.TRIMBOX, cropArray);
					pdfDictionary.put(PdfName.BLEEDBOX, cropArray);
				}
			}
			return filename;
		} finally {
			stamper.close();
		}
	} catch (Exception e) {
		logger.error(e.getMessage(), e);
		throw e;
	} finally {
		reader.close();
	}
}
 
Example #19
Source File: Image.java    From gcs with Mozilla Public License 2.0 5 votes vote down vote up
/**
 * 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);
}
 
Example #20
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 #21
Source File: Image.java    From itext2 with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
* 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;
  }
 
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) {
	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 #23
Source File: PdfXConformanceImp.java    From gcs with Mozilla Public License 2.0 5 votes vote down vote up
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));
        }
    }
}
 
Example #24
Source File: PdfCollectionSort.java    From gcs with Mozilla Public License 2.0 5 votes vote down vote up
/**
 * 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);
}
 
Example #25
Source File: PdfXConformanceImp.java    From itext2 with GNU Lesser General Public License v3.0 5 votes vote down vote up
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));
        }
    }
}
 
Example #26
Source File: BmpImage.java    From gcs with Mozilla Public License 2.0 5 votes vote down vote up
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;
}
 
Example #27
Source File: ChartPdfHandler.java    From jasperreports with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public void exportElement(JRPdfExporterContext exporterContext,
		JRGenericPrintElement element)
{
	try
	{
		PdfWriter writer = exporterContext.getPdfWriter();
		PdfIndirectObject swfRef;
		boolean newContext = !existingContexts.containsKey(exporterContext);
		if (newContext)
		{
			// add the Adobe 1.7 extensions catalog dictionary
			PdfDictionary extensions = new PdfDictionary();
			PdfDictionary adobeExtension = new PdfDictionary();
			adobeExtension.put(new PdfName("BaseVersion"), PdfWriter.PDF_VERSION_1_7);
			adobeExtension.put(new PdfName("ExtensionLevel"), new PdfNumber(3));
			extensions.put(new PdfName("ADBE"), adobeExtension);
			writer.getExtraCatalog().put(new PdfName("Extensions"), extensions);
			
			// add the swf file
			byte[] swfData = readSwf();
			PdfFileSpecification swfFile = PdfFileSpecification.fileEmbedded(writer, 
					null, "Open Flash Chart", swfData);
			swfRef = writer.addToBody(swfFile);
			existingContexts.put(exporterContext, swfRef);
		}
		else
		{
			swfRef = existingContexts.get(exporterContext);
		}
		
		Rectangle rect = new Rectangle(element.getX() + exporterContext.getOffsetX(), 
				exporterContext.getExportedReport().getPageHeight() - element.getY() - exporterContext.getOffsetY(), 
				element.getX() + exporterContext.getOffsetX() + element.getWidth(),
				exporterContext.getExportedReport().getPageHeight() - element.getY() - exporterContext.getOffsetY() - element.getHeight());
		PdfAnnotation ann = new PdfAnnotation(writer, rect);
		ann.put(PdfName.SUBTYPE, new PdfName("RichMedia"));
		
		PdfDictionary settings = new PdfDictionary();
		PdfDictionary activation = new PdfDictionary();
		activation.put(new PdfName("Condition"), new PdfName("PV"));
		settings.put(new PdfName("Activation"), activation);
		ann.put(new PdfName("RichMediaSettings"), settings);
		
		PdfDictionary content = new PdfDictionary();
		
		HashMap<String, PdfIndirectReference> assets = new HashMap<String, PdfIndirectReference>();
		assets.put("map.swf", swfRef.getIndirectReference());
		PdfDictionary assetsDictionary = PdfNameTree.writeTree(assets, writer);
		content.put(new PdfName("Assets"), assetsDictionary);
		
		PdfArray configurations = new PdfArray();
		PdfDictionary configuration = new PdfDictionary();
		
		PdfArray instances = new PdfArray();
		PdfDictionary instance = new PdfDictionary();
		instance.put(new PdfName("Subtype"), new PdfName("Flash"));
		PdfDictionary params = new PdfDictionary();
		
		String chartData = (String) element.getParameterValue(PARAMETER_CHART_DATA);
		String vars = "inline_data=" + chartData;
		params.put(new PdfName("FlashVars"), new PdfString(vars));
		instance.put(new PdfName("Params"), params);
		instance.put(new PdfName("Asset"), swfRef.getIndirectReference());
		PdfIndirectObject instanceRef = writer.addToBody(instance);
		instances.add(instanceRef.getIndirectReference());
		configuration.put(new PdfName("Instances"), instances);
		
		PdfIndirectObject configurationRef = writer.addToBody(configuration);
		configurations.add(configurationRef.getIndirectReference());
		content.put(new PdfName("Configurations"), configurations);
		
		ann.put(new PdfName("RichMediaContent"), content);
		
		writer.addAnnotation(ann);
	}
	catch (Exception e)
	{
		throw new RuntimeException(e);
	}
}
 
Example #28
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 #29
Source File: PolygonAnnotation.java    From pentaho-reporting with GNU Lesser General Public License v2.1 4 votes vote down vote up
public PolygonAnnotation( final PdfWriter writer, final float[] coords ) {
  super( writer, null );
  put( PdfName.SUBTYPE, POLYGON );
  put( PdfName.RECT, createRec( coords ) );
  put( VERTICES, new PdfArray( coords ) );
}
 
Example #30
Source File: ITextPdfArray.java    From dss with GNU Lesser General Public License v2.1 4 votes vote down vote up
ITextPdfArray(PdfArray wrapped) {
	this.wrapped = wrapped;
}