Java Code Examples for com.lowagie.text.Chunk#setLocalDestination()

The following examples show how to use com.lowagie.text.Chunk#setLocalDestination() . 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: JRPdfExporter.java    From jasperreports with GNU Lesser General Public License v3.0 6 votes vote down vote up
protected void writePageAnchor(int pageIndex) throws DocumentException 
{
	Map<Attribute,Object> attributes = new HashMap<Attribute,Object>();
	fontUtil.getAttributesWithoutAwtFont(attributes, new JRBasePrintText(jasperPrint.getDefaultStyleProvider()));
	Font pdfFont = getFont(attributes, getLocale(), false);
	Chunk chunk = new Chunk(" ", pdfFont);
	
	chunk.setLocalDestination(JR_PAGE_ANCHOR_PREFIX + reportIndex + "_" + (pageIndex + 1));

	tagHelper.startPageAnchor();
	
	ColumnText colText = new ColumnText(pdfContentByte);
	colText.setSimpleColumn(
		new Phrase(chunk),
		0,
		pageFormat.getPageHeight(),
		1,
		1,
		0,
		Element.ALIGN_LEFT
		);

	colText.go();

	tagHelper.endPageAnchor();
}
 
Example 2
Source File: JRPdfExporter.java    From jasperreports with GNU Lesser General Public License v3.0 6 votes vote down vote up
protected void setAnchor(Chunk chunk, JRPrintAnchor anchor, JRPrintElement element)
{
	String anchorName = anchor.getAnchorName();
	if (anchorName != null)
	{
		chunk.setLocalDestination(anchorName);

		if (anchor.getBookmarkLevel() != JRAnchor.NO_BOOKMARK)
		{
			int x = OrientationEnum.PORTRAIT.equals(pageFormat.getOrientation()) 
					? getOffsetX() + element.getX() 
					: getOffsetY() + element.getY();
			int y = OrientationEnum.PORTRAIT.equals(pageFormat.getOrientation()) 
					? getOffsetY() + element.getY() 
					: getOffsetX() + element.getX();
			addBookmark(anchor.getBookmarkLevel(), anchor.getAnchorName(), x, y);
		}
	}
}
 
Example 3
Source File: IndexEvents.java    From gcs with Mozilla Public License 2.0 5 votes vote down vote up
/**
 * Create an index entry.
 *
 * @param text The text for the Chunk.
 * @param in1 The first level.
 * @param in2 The second level.
 * @param in3 The third level.
 * @return Returns the Chunk.
 */
public Chunk create(final String text, final String in1, final String in2, final String in3) {

	Chunk chunk = new Chunk(text);
	String tag = "idx_" + indexcounter++;
	chunk.setGenericTag(tag);
	chunk.setLocalDestination(tag);
	Entry entry = new Entry(in1, in2, in3, tag);
	indexentry.add(entry);
	return chunk;
}
 
Example 4
Source File: IndexEvents.java    From gcs with Mozilla Public License 2.0 5 votes vote down vote up
/**
 * Create an index entry.
 *
 * @param text The text.
 * @param in1 The first level.
 * @param in2 The second level.
 * @param in3 The third level.
 */
public void create(final Chunk text, final String in1, final String in2, final String in3) {

	String tag = "idx_" + indexcounter++;
	text.setGenericTag(tag);
	text.setLocalDestination(tag);
	Entry entry = new Entry(in1, in2, in3, tag);
	indexentry.add(entry);
}
 
Example 5
Source File: IndexEvents.java    From itext2 with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Create an index entry.
 *
 * @param text  The text for the Chunk.
 * @param in1   The first level.
 * @param in2   The second level.
 * @param in3   The third level.
 * @return Returns the Chunk.
 */
public Chunk create(final String text, final String in1, final String in2,
        final String in3) {

    Chunk chunk = new Chunk(text);
    String tag = "idx_" + (indexcounter++);
    chunk.setGenericTag(tag);
    chunk.setLocalDestination(tag);
    Entry entry = new Entry(in1, in2, in3, tag);
    indexentry.add(entry);
    return chunk;
}
 
Example 6
Source File: IndexEvents.java    From itext2 with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Create an index entry.
 *
 * @param text  The text.
 * @param in1   The first level.
 * @param in2   The second level.
 * @param in3   The third level.
 */
public void create(final Chunk text, final String in1, final String in2,
        final String in3) {

    String tag = "idx_" + (indexcounter++);
    text.setGenericTag(tag);
    text.setLocalDestination(tag);
    Entry entry = new Entry(in1, in2, in3, tag);
    indexentry.add(entry);
}
 
Example 7
Source File: ElementFactory.java    From gcs with Mozilla Public License 2.0 4 votes vote down vote up
/**
 * Creates a Chunk object based on a list of properties.
 * 
 * @param attributes
 * @return a Chunk
 */
public static Chunk getChunk(Properties attributes) {
	Chunk chunk = new Chunk();

	chunk.setFont(FontFactory.getFont(attributes));
	String value;

	value = attributes.getProperty(ElementTags.ITEXT);
	if (value != null) {
		chunk.append(value);
	}
	value = attributes.getProperty(ElementTags.LOCALGOTO);
	if (value != null) {
		chunk.setLocalGoto(value);
	}
	value = attributes.getProperty(ElementTags.REMOTEGOTO);
	if (value != null) {
		String page = attributes.getProperty(ElementTags.PAGE);
		if (page != null) {
			chunk.setRemoteGoto(value, Integer.parseInt(page));
		} else {
			String destination = attributes.getProperty(ElementTags.DESTINATION);
			if (destination != null) {
				chunk.setRemoteGoto(value, destination);
			}
		}
	}
	value = attributes.getProperty(ElementTags.LOCALDESTINATION);
	if (value != null) {
		chunk.setLocalDestination(value);
	}
	value = attributes.getProperty(ElementTags.SUBSUPSCRIPT);
	if (value != null) {
		chunk.setTextRise(Float.parseFloat(value + "f"));
	}
	value = attributes.getProperty(Markup.CSS_KEY_VERTICALALIGN);
	if (value != null && value.endsWith("%")) {
		float p = Float.parseFloat(value.substring(0, value.length() - 1) + "f") / 100f;
		chunk.setTextRise(p * chunk.getFont().getSize());
	}
	value = attributes.getProperty(ElementTags.GENERICTAG);
	if (value != null) {
		chunk.setGenericTag(value);
	}
	value = attributes.getProperty(ElementTags.BACKGROUNDCOLOR);
	if (value != null) {
		chunk.setBackground(Markup.decodeColor(value));
	}
	return chunk;
}
 
Example 8
Source File: ElementFactory.java    From itext2 with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Creates a Chunk object based on a list of properties.
 * @param attributes
 * @return a Chunk
 */
public static Chunk getChunk(Properties attributes) {
	Chunk chunk = new Chunk();

	chunk.setFont(FontFactory.getFont(attributes));
	String value;

	value = attributes.getProperty(ElementTags.ITEXT);
	if (value != null) {
		chunk.append(value);
	}
	value = attributes.getProperty(ElementTags.LOCALGOTO);
	if (value != null) {
		chunk.setLocalGoto(value);
	}
	value = attributes.getProperty(ElementTags.REMOTEGOTO);
	if (value != null) {
		String page = attributes.getProperty(ElementTags.PAGE);
		if (page != null) {
			chunk.setRemoteGoto(value, Integer.parseInt(page));
		} else {
			String destination = attributes
					.getProperty(ElementTags.DESTINATION);
			if (destination != null) {
				chunk.setRemoteGoto(value, destination);
			}
		}
	}
	value = attributes.getProperty(ElementTags.LOCALDESTINATION);
	if (value != null) {
		chunk.setLocalDestination(value);
	}
	value = attributes.getProperty(ElementTags.SUBSUPSCRIPT);
	if (value != null) {
		chunk.setTextRise(Float.parseFloat(value + "f"));
	}
	value = attributes.getProperty(Markup.CSS_KEY_VERTICALALIGN);
	if (value != null && value.endsWith("%")) {
		float p = Float.parseFloat(value.substring(0, value.length() - 1)
				+ "f") / 100f;
		chunk.setTextRise(p * chunk.getFont().getSize());
	}
	value = attributes.getProperty(ElementTags.GENERICTAG);
	if (value != null) {
		chunk.setGenericTag(value);
	}
	value = attributes.getProperty(ElementTags.BACKGROUNDCOLOR);
	if (value != null) {
		chunk.setBackground(Markup.decodeColor(value));
	}
	return chunk;
}