Java Code Examples for com.lowagie.text.Element#CHUNK

The following examples show how to use com.lowagie.text.Element#CHUNK . 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: PdfDocument.java    From gcs with Mozilla Public License 2.0 5 votes vote down vote up
/**
 * Ensures that a new line has been started.
 */
protected void ensureNewLine() {
	try {
		if (lastElementType == Element.PHRASE || lastElementType == Element.CHUNK) {
			newLine();
			flushLines();
		}
	} catch (DocumentException ex) {
		throw new ExceptionConverter(ex);
	}
}
 
Example 2
Source File: PdfCell.java    From gcs with Mozilla Public License 2.0 5 votes vote down vote up
/**
 * Processes all actions contained in the cell.
 * 
 * @param element an element in the cell
 * @param action an action that should be coupled to the cell
 * @param allActions
 */

protected void processActions(Element element, PdfAction action, ArrayList allActions) {
	if (element.type() == Element.ANCHOR) {
		String url = ((Anchor) element).getReference();
		if (url != null) {
			action = new PdfAction(url);
		}
	}
	Iterator i;
	switch (element.type()) {
		case Element.PHRASE:
		case Element.SECTION:
		case Element.ANCHOR:
		case Element.CHAPTER:
		case Element.LISTITEM:
		case Element.PARAGRAPH:
			for (i = ((ArrayList) element).iterator(); i.hasNext();) {
				processActions((Element) i.next(), action, allActions);
			}
			break;
		case Element.CHUNK:
			allActions.add(action);
			break;
		case Element.LIST:
			for (i = ((List) element).getItems().iterator(); i.hasNext();) {
				processActions((Element) i.next(), action, allActions);
			}
			break;
		default:
			int n = element.getChunks().size();
			while (n-- > 0) {
				allActions.add(action);
			}
			break;
	}
}
 
Example 3
Source File: PdfDocument.java    From itext2 with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Ensures that a new line has been started.
 */
protected void ensureNewLine() {
  try {
    if ((lastElementType == Element.PHRASE) ||
        (lastElementType == Element.CHUNK)) {
      newLine();
      flushLines();
    }
  } catch (DocumentException ex) {
    throw new ExceptionConverter(ex);
    }
}
 
Example 4
Source File: PdfCell.java    From itext2 with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Processes all actions contained in the cell.
 * @param element	an element in the cell
 * @param action	an action that should be coupled to the cell
 * @param allActions
 */

protected void processActions(Element element, PdfAction action, ArrayList allActions) {
    if (element.type() == Element.ANCHOR) {
        String url = ((Anchor) element).getReference();
        if (url != null) {
            action = new PdfAction(url);
        }
    }
    Iterator i;
    switch (element.type()) {
        case Element.PHRASE:
        case Element.SECTION:
        case Element.ANCHOR:
        case Element.CHAPTER:
        case Element.LISTITEM:
        case Element.PARAGRAPH:
            for (i = ((ArrayList) element).iterator(); i.hasNext();) {
                processActions((Element) i.next(), action, allActions);
            }
            break;
        case Element.CHUNK:
            allActions.add(action);
            break;
        case Element.LIST:
            for (i = ((List) element).getItems().iterator(); i.hasNext();) {
                processActions((Element) i.next(), action, allActions);
            }
            break;
        default:
            int n = element.getChunks().size();
            while (n-- > 0)
                allActions.add(action);
            break;
    }
}
 
Example 5
Source File: PdfDocument.java    From MesquiteCore with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Ensures that a new line has been started. 
 */
private void ensureNewLine() {
  try {
    if ((lastElementType == Element.PHRASE) || 
        (lastElementType == Element.CHUNK)) {
      newLine();
      flushLines();
    }
  } catch (DocumentException ex) {
    throw new ExceptionConverter(ex);
    }
}
 
Example 6
Source File: PatchRtfDocument.java    From pentaho-reporting with GNU Lesser General Public License v2.1 4 votes vote down vote up
public RtfBasicElement[] mapElement( Element element ) throws DocumentException {
  ArrayList<RtfBasicElement> rtfElements = new ArrayList<RtfBasicElement>();
  if ( element instanceof RtfBasicElement ) {
    RtfBasicElement rtfElement = (RtfBasicElement) element;
    rtfElement.setRtfDocument( rtfDoc );
    return new RtfBasicElement[] { rtfElement };
  }
  switch ( element.type() ) {
    case Element.CHUNK:
      Chunk chunk = (Chunk) element;
      if ( chunk.hasAttributes() ) {
        if ( chunk.getAttributes().containsKey( Chunk.IMAGE ) ) {
          rtfElements.add( new RtfImage( rtfDoc, chunk.getImage() ) );
        } else if ( chunk.getAttributes().containsKey( Chunk.NEWPAGE ) ) {
          rtfElements.add( new RtfNewPage( rtfDoc ) );
        } else if ( chunk.getAttributes().containsKey( Chunk.TAB ) ) {
          Float tabPos = (Float) ( (Object[]) chunk.getAttributes().get( Chunk.TAB ) )[1];
          RtfTab tab = new RtfTab( tabPos.floatValue(), RtfTab.TAB_LEFT_ALIGN );
          tab.setRtfDocument( rtfDoc );
          rtfElements.add( tab );
          rtfElements.add( new RtfChunk( rtfDoc, new Chunk( "\t" ) ) );
        } else {
          rtfElements.add( new RtfChunk( rtfDoc, (Chunk) element ) );
        }
      } else {
        rtfElements.add( new RtfChunk( rtfDoc, (Chunk) element ) );
      }
      break;
    case Element.PHRASE:
      rtfElements.add( new RtfPhrase( rtfDoc, (Phrase) element ) );
      break;
    case Element.PARAGRAPH:
      rtfElements.add( new RtfParagraph( rtfDoc, (Paragraph) element ) );
      break;
    case Element.ANCHOR:
      rtfElements.add( new RtfAnchor( rtfDoc, (Anchor) element ) );
      break;
    case Element.ANNOTATION:
      rtfElements.add( new RtfAnnotation( rtfDoc, (Annotation) element ) );
      break;
    case Element.IMGRAW:
    case Element.IMGTEMPLATE:
    case Element.JPEG:
      rtfElements.add( new RtfImage( rtfDoc, (Image) element ) );
      break;
    case Element.AUTHOR:
    case Element.SUBJECT:
    case Element.KEYWORDS:
    case Element.TITLE:
    case Element.PRODUCER:
    case Element.CREATIONDATE:
      rtfElements.add( new RtfInfoElement( rtfDoc, (Meta) element ) );
      break;
    case Element.LIST:
      rtfElements.add( new RtfList( rtfDoc, (List) element ) ); // TODO: Testing
      break;
    case Element.LISTITEM:
      rtfElements.add( new RtfListItem( rtfDoc, (ListItem) element ) ); // TODO: Testing
      break;
    case Element.SECTION:
      rtfElements.add( new RtfSection( rtfDoc, (Section) element ) );
      break;
    case Element.CHAPTER:
      rtfElements.add( new RtfChapter( rtfDoc, (Chapter) element ) );
      break;
    case Element.TABLE:
      if ( element instanceof Table ) {
        rtfElements.add( new PatchRtfTable( rtfDoc, (Table) element ) );
      } else {
        rtfElements.add( new PatchRtfTable( rtfDoc, ( (SimpleTable) element ).createTable() ) );
      }
      break;
    case Element.PTABLE:
      if ( element instanceof PdfPTable ) {
        rtfElements.add( new PatchRtfTable( rtfDoc, (PdfPTable) element ) );
      } else {
        rtfElements.add( new PatchRtfTable( rtfDoc, ( (SimpleTable) element ).createTable() ) );
      }
      break;
  }

  return rtfElements.toArray( new RtfBasicElement[rtfElements.size()] );
}