com.lowagie.text.DocWriter Java Examples

The following examples show how to use com.lowagie.text.DocWriter. 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: RtfCell.java    From itext2 with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Write the content of this RtfCell
 */    
public void writeContent(final OutputStream result) throws IOException
{
    if(this.content.size() == 0) {
        result.write(RtfParagraph.PARAGRAPH_DEFAULTS);
        if(this.parentRow.getParentTable().getTableFitToPage()) {
            result.write(RtfParagraphStyle.KEEP_TOGETHER_WITH_NEXT);
        }
        result.write(RtfParagraph.IN_TABLE);
    } else {
        for(int i = 0; i < this.content.size(); i++) {
            RtfBasicElement rtfElement = (RtfBasicElement) this.content.get(i);
            if(rtfElement instanceof RtfParagraph) {
                ((RtfParagraph) rtfElement).setKeepTogetherWithNext(this.parentRow.getParentTable().getTableFitToPage());
            }
            rtfElement.writeContent(result);
            if(rtfElement instanceof RtfParagraph && i < (this.content.size() - 1)) {
                result.write(RtfParagraph.PARAGRAPH);
            }
        }
    }
    result.write(DocWriter.getISOBytes("\\cell"));
}
 
Example #2
Source File: PatchRtfCell.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Write the content of this PatchRtfCell
 */
public void writeContent( final OutputStream result ) throws IOException {
  if ( this.content.size() == 0 ) {
    result.write( RtfParagraph.PARAGRAPH_DEFAULTS );
    if ( this.parentRow.getParentTable().getTableFitToPage() ) {
      result.write( RtfParagraphStyle.KEEP_TOGETHER_WITH_NEXT );
    }
    result.write( RtfParagraph.IN_TABLE );
  } else {
    for ( int i = 0; i < this.content.size(); i++ ) {
      RtfBasicElement rtfElement = this.content.get( i );
      if ( rtfElement instanceof RtfParagraph ) {
        ( (RtfParagraph) rtfElement ).setKeepTogetherWithNext( this.parentRow.getParentTable().getTableFitToPage() );
      }
      rtfElement.writeContent( result );
      if ( rtfElement instanceof RtfParagraph && i < ( this.content.size() - 1 ) ) {
        result.write( RtfParagraph.PARAGRAPH );
      }
    }
  }
  result.write( DocWriter.getISOBytes( "\\cell" ) );
}
 
Example #3
Source File: RtfAnnotation.java    From itext2 with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Writes the content of the RtfAnnotation
 */
public void writeContent(final OutputStream result) throws IOException
{
    result.write(OPEN_GROUP);
    result.write(ANNOTATION_ID);
    result.write(DELIMITER);
    result.write(intToByteArray(document.getRandomInt()));
    result.write(CLOSE_GROUP);
    result.write(OPEN_GROUP);
    result.write(ANNOTATION_AUTHOR);
    result.write(DELIMITER);
    result.write(DocWriter.getISOBytes(title));
    result.write(CLOSE_GROUP);
    result.write(OPEN_GROUP);
    result.write(ANNOTATION);
    result.write(RtfParagraph.PARAGRAPH_DEFAULTS);
    result.write(DELIMITER);
    result.write(DocWriter.getISOBytes(content));
    result.write(CLOSE_GROUP);    	
}
 
Example #4
Source File: MPdfWriter.java    From javamelody with Apache License 2.0 6 votes vote down vote up
/**
 * We create a writer that listens to the document and directs a PDF-stream to out
 *
 * @param table
 *           MBasicTable
 * @param document
 *           Document
 * @param out
 *           OutputStream
 * @return DocWriter
 * @throws DocumentException
 *            e
 */
protected DocWriter createWriter(final MBasicTable table, final Document document,
		final OutputStream out) throws DocumentException {
	final PdfWriter writer = PdfWriter.getInstance(document, out);
	// writer.setViewerPreferences(PdfWriter.PageLayoutTwoColumnLeft);

	// title
	if (table.getName() != null) {
		final HeaderFooter header = new HeaderFooter(new Phrase(table.getName()), false);
		header.setAlignment(Element.ALIGN_LEFT);
		header.setBorder(Rectangle.NO_BORDER);
		document.setHeader(header);
		document.addTitle(table.getName());
	}

	// simple page numbers : x
	// HeaderFooter footer = new HeaderFooter(new Phrase(), true);
	// footer.setAlignment(Element.ALIGN_RIGHT);
	// footer.setBorder(Rectangle.TOP);
	// document.setFooter(footer);

	// add the event handler for advanced page numbers : x/y
	writer.setPageEvent(new AdvancedPageNumberEvents());

	return writer;
}
 
Example #5
Source File: RtfChapter.java    From itext2 with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Writes the RtfChapter and its contents
 */    
public void writeContent(final OutputStream result) throws IOException
{
    if(this.document.getLastElementWritten() != null && !(this.document.getLastElementWritten() instanceof RtfChapter)) {
        result.write(DocWriter.getISOBytes("\\page"));
    }
    result.write(DocWriter.getISOBytes("\\sectd"));
    document.getDocumentHeader().writeSectionDefinition(result);
    if(this.title != null) {
        this.title.writeContent(result);
    }
    for(int i = 0; i < items.size(); i++) {
    	RtfBasicElement rbe = (RtfBasicElement)items.get(i);
    	rbe.writeContent(result);
    }
    result.write(DocWriter.getISOBytes("\\sect"));
}
 
Example #6
Source File: RtfParagraphStyle.java    From itext2 with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Writes the definition of this RtfParagraphStyle for the stylesheet list.
 */
public void writeDefinition(final OutputStream result) throws IOException 
{
    result.write(DocWriter.getISOBytes("{"));
    result.write(DocWriter.getISOBytes("\\style"));
    result.write(DocWriter.getISOBytes("\\s"));
    result.write(intToByteArray(this.styleNumber));
    result.write(RtfBasicElement.DELIMITER);
    writeParagraphSettings(result);
    super.writeBegin(result);
    result.write(RtfBasicElement.DELIMITER);
    result.write(DocWriter.getISOBytes(this.styleName));
    result.write(DocWriter.getISOBytes(";"));
    result.write(DocWriter.getISOBytes("}"));
    this.document.outputDebugLinebreak(result);   	
}
 
Example #7
Source File: RtfProtectionTest.java    From itext2 with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Tests that the <code>RtfProtection</code> generates the correct hash
 * for a null password
 * @throws IOException On I/O errors
 */
@Test
public void testPasswordNull() throws IOException {
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    out.write(DocWriter.getISOBytes(RtfProtection.generateHash(null)));
    assertEquals("00000000", out);
}
 
Example #8
Source File: RtfGenerator.java    From itext2 with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
   * Writes the RTF generator group.
   */    
  public void writeContent(final OutputStream result) throws IOException
  {
  	result.write(OPEN_GROUP);
result.write(GENERATOR);
result.write(DELIMITER);
result.write(DocWriter.getISOBytes(Document.getVersion()));
result.write(CLOSE_GROUP);
this.document.outputDebugLinebreak(result);
  }
 
Example #9
Source File: RtfInfoElement.java    From itext2 with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Writes the content of one RTF information element.
 */    
public void writeContent(final OutputStream result) throws IOException
{
    result.write(OPEN_GROUP);
    switch(infoType) {
        case Meta.AUTHOR:
            result.write(INFO_AUTHOR);
        	break;
        case Meta.SUBJECT:
            result.write(INFO_SUBJECT);
    		break;
        case Meta.KEYWORDS:
            result.write(INFO_KEYWORDS);
    		break;
        case Meta.TITLE:
            result.write(INFO_TITLE);
    		break;
        case Meta.PRODUCER:
            result.write(INFO_PRODUCER);
    		break;
        case Meta.CREATIONDATE:
            result.write(INFO_CREATION_DATE);
        	break;
        default:
            result.write(INFO_AUTHOR);
        	break;
    }
    result.write(DELIMITER);
    if(infoType == Meta.CREATIONDATE) {
        result.write(DocWriter.getISOBytes(convertDate(content)));
    } else {
        document.filterSpecialChar(result, content, false, false);
    }
    result.write(CLOSE_GROUP);
}
 
Example #10
Source File: RtfShapePosition.java    From itext2 with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Write this RtfShapePosition.
 */
public void writeContent(final OutputStream result) throws IOException
{    	
	result.write(DocWriter.getISOBytes("\\shpleft"));
	result.write(intToByteArray(this.left));
	result.write(DocWriter.getISOBytes("\\shptop"));
	result.write(intToByteArray(this.top));
	result.write(DocWriter.getISOBytes("\\shpright"));
	result.write(intToByteArray(this.right));
	result.write(DocWriter.getISOBytes("\\shpbottom"));
	result.write(intToByteArray(this.bottom));
	result.write(DocWriter.getISOBytes("\\shpz"));
	result.write(intToByteArray(this.zOrder));
	switch(this.xRelativePos) {
	case POSITION_X_RELATIVE_PAGE: result.write(DocWriter.getISOBytes("\\shpbxpage")); break;
	case POSITION_X_RELATIVE_MARGIN: result.write(DocWriter.getISOBytes("\\shpbxmargin")); break;
	case POSITION_X_RELATIVE_COLUMN: result.write(DocWriter.getISOBytes("\\shpbxcolumn")); break;
	}
	if(this.ignoreXRelative) {
		result.write(DocWriter.getISOBytes("\\shpbxignore"));
	}
	switch(this.yRelativePos) {
	case POSITION_Y_RELATIVE_PAGE: result.write(DocWriter.getISOBytes("\\shpbypage")); break;
	case POSITION_Y_RELATIVE_MARGIN: result.write(DocWriter.getISOBytes("\\shpbymargin")); break;
	case POSITION_Y_RELATIVE_PARAGRAPH: result.write(DocWriter.getISOBytes("\\shpbypara")); break;
	}
	if(this.ignoreYRelative) {
		result.write(DocWriter.getISOBytes("\\shpbyignore"));
	}
	if(this.shapeBelowText) {
		result.write(DocWriter.getISOBytes("\\shpfblwtxt1"));
	} else {
		result.write(DocWriter.getISOBytes("\\shpfblwtxt0"));
	}
}
 
Example #11
Source File: RtfTestBase.java    From itext2 with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Tests that the <code>RtfTestBase</code> works correctly for special characters.
 * 
 * @throws IOException On I/O errors.
 */
@Test
public void testSelfSpecialChar() throws IOException {
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    out.write(DocWriter.getISOBytes("\n\t"));
    assertEquals("\n\t", out);
}
 
Example #12
Source File: RtfTestBase.java    From itext2 with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Tests that the <code>RtfTestBase</code> works correctly for arbitrary text.
 * 
 * @throws IOException On I/O errors.
 */
@Test
public void testRandomText() throws IOException {
    StringBuffer text = new StringBuffer();
    for(int i = 0; i < 100; i++) {
        text.append(Character.toString((char) (Math.random() * 52)));
    }
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    out.write(DocWriter.getISOBytes(text.toString()));
    assertEquals(text.toString(), out);
}
 
Example #13
Source File: RtfTab.java    From itext2 with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
* Writes the tab settings.
*/
  public void writeContent(final OutputStream result) throws IOException
  {
  	switch(this.type) {
  		case TAB_CENTER_ALIGN: result.write(DocWriter.getISOBytes("\\tqc")); break;
  		case TAB_RIGHT_ALIGN: result.write(DocWriter.getISOBytes("\\tqr")); break;
  		case TAB_DECIMAL_ALIGN: result.write(DocWriter.getISOBytes("\\tqdec")); break;
      }
      result.write(DocWriter.getISOBytes("\\tx"));
      result.write(intToByteArray(this.position));    	
  }
 
Example #14
Source File: RtfParagraph.java    From itext2 with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Writes the content of this RtfParagraph. First paragraph specific data is written
 * and then the RtfChunks of this RtfParagraph are added.
 */    
public void writeContent(final OutputStream result) throws IOException
{
    result.write(PARAGRAPH_DEFAULTS);
    result.write(PLAIN);

    if(inTable) {
        result.write(IN_TABLE);
    }
    
    if(this.paragraphStyle != null) {
        this.paragraphStyle.writeBegin(result);
    }
    result.write(DocWriter.getISOBytes("\\plain"));
    
    for(int i = 0; i < chunks.size(); i++) {
    	RtfBasicElement rbe = (RtfBasicElement)chunks.get(i);
    	rbe.writeContent(result);
    }
    
    if(this.paragraphStyle != null) {
        this.paragraphStyle.writeEnd(result);
    }
    
    if(!inTable) {
        result.write(PARAGRAPH);
    }
    this.document.outputDebugLinebreak(result);
}
 
Example #15
Source File: RtfProtectionTest.java    From itext2 with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Tests that the <code>RtfProtection</code> generates the correct hash
 * for a normal 1 to 15 character password
 * @throws IOException On I/O errors
 */
@Test
public void testPasswordNormal() throws IOException {
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    out.write(DocWriter.getISOBytes(RtfProtection.generateHash("apple")));
    assertEquals("acc6b84a", out);
}
 
Example #16
Source File: RtfStylesheetList.java    From itext2 with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Writes the definition of the stylesheet list.
 */
public void writeDefinition(final OutputStream result) throws IOException
{
    result.write(DocWriter.getISOBytes("{"));
    result.write(DocWriter.getISOBytes("\\stylesheet"));
    result.write(RtfBasicElement.DELIMITER);
    this.document.outputDebugLinebreak(result);
    Iterator it = this.styleMap.values().iterator();
    while(it.hasNext()) {
    	RtfParagraphStyle rps = (RtfParagraphStyle)it.next();
    	rps.writeDefinition(result);
    }
    result.write(DocWriter.getISOBytes("}"));
    this.document.outputDebugLinebreak(result);  	
}
 
Example #17
Source File: RtfProtectionTest.java    From itext2 with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Tests that the <code>RtfProtection</code> generates the correct hash
 * for an empty password
 * @throws IOException On I/O errors
 */
@Test
public void testPasswordEmpty() throws IOException {
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    out.write(DocWriter.getISOBytes(RtfProtection.generateHash("")));
    assertEquals("00000000", out);
}
 
Example #18
Source File: RtfProtectionTest.java    From itext2 with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Tests that the <code>RtfProtection</code> generates the correct hash
 * for a long password (>15 characters)
 * @throws IOException On I/O errors
 */
@Test
public void testPasswordLong() throws IOException {
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    out.write(DocWriter.getISOBytes(RtfProtection.generateHash("0123456789ABCDEFHIJKLMNOP")));
    assertEquals("fab7c3b6", out);
}
 
Example #19
Source File: RtfListItem.java    From itext2 with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Writes the content of this RtfListItem.
 */    
public void writeContent(final OutputStream result) throws IOException
{
    if(this.paragraphStyle.getSpacingBefore() > 0) {
        result.write(RtfParagraphStyle.SPACING_BEFORE);
        result.write(intToByteArray(paragraphStyle.getSpacingBefore()));
    }
    if(this.paragraphStyle.getSpacingAfter() > 0) {
        result.write(RtfParagraphStyle.SPACING_AFTER);
        result.write(intToByteArray(this.paragraphStyle.getSpacingAfter()));
    }
    if(this.paragraphStyle.getLineLeading() > 0) {
    	result.write(RtfParagraph.LINE_SPACING);
    	result.write(intToByteArray(this.paragraphStyle.getLineLeading()));
    }
    for(int i = 0; i < chunks.size(); i++) {
        RtfBasicElement rtfElement = (RtfBasicElement) chunks.get(i);
        if(rtfElement instanceof RtfChunk) {
            ((RtfChunk) rtfElement).setSoftLineBreaks(true);
        } else if(rtfElement instanceof RtfList) {
            result.write(RtfParagraph.PARAGRAPH);
            this.containsInnerList = true;
        }
        rtfElement.writeContent(result);
        if(rtfElement instanceof RtfList) {
            switch(this.parentList.getLevelFollowValue()) {
            case RtfListLevel.LIST_LEVEL_FOLLOW_NOTHING:
            	break;
            case RtfListLevel.LIST_LEVEL_FOLLOW_TAB:
                this.parentList.writeListBeginning(result);
                result.write(RtfList.TAB);
                break;
            case RtfListLevel.LIST_LEVEL_FOLLOW_SPACE:
                this.parentList.writeListBeginning(result);
                result.write(DocWriter.getISOBytes(" "));
                break;
            }
        }
    }
}
 
Example #20
Source File: RtfList.java    From itext2 with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * 
 * @param result
 * @param itemNr
 * @param listLevel
 * @throws IOException
 * @since 2.1.3
 */
protected void writeListTextBlock(final OutputStream result, int itemNr, RtfListLevel listLevel) 
throws IOException {
	result.write(OPEN_GROUP);
    result.write(RtfList.LIST_TEXT);
    result.write(RtfParagraph.PARAGRAPH_DEFAULTS);
    if(this.inTable) {
        result.write(RtfParagraph.IN_TABLE);
    }
    result.write(RtfFontList.FONT_NUMBER);
    if(listLevel.getListType() != RtfListLevel.LIST_TYPE_BULLET) {
        result.write(intToByteArray(listLevel.getFontNumber().getFontNumber()));
    } else {
        result.write(intToByteArray(listLevel.getFontBullet().getFontNumber()));
    }
    listLevel.writeIndentation(result);
    result.write(DELIMITER);
    if(listLevel.getListType() != RtfListLevel.LIST_TYPE_BULLET) {
        switch(listLevel.getListType()) {
            case RtfListLevel.LIST_TYPE_NUMBERED      : result.write(intToByteArray(itemNr)); break;
            case RtfListLevel.LIST_TYPE_UPPER_LETTERS : result.write(DocWriter.getISOBytes(RomanAlphabetFactory.getUpperCaseString(itemNr))); break;
            case RtfListLevel.LIST_TYPE_LOWER_LETTERS : result.write(DocWriter.getISOBytes(RomanAlphabetFactory.getLowerCaseString(itemNr))); break;
            case RtfListLevel.LIST_TYPE_UPPER_ROMAN   : result.write(DocWriter.getISOBytes(RomanNumberFactory.getUpperCaseString(itemNr))); break;
            case RtfListLevel.LIST_TYPE_LOWER_ROMAN   : result.write(DocWriter.getISOBytes(RomanNumberFactory.getLowerCaseString(itemNr))); break;
        }
        result.write(LIST_NUMBER_END);
    } else {
        this.document.filterSpecialChar(result, listLevel.getBulletCharacter(), true, false);
    }
    result.write(TAB);
    result.write(CLOSE_GROUP);
}
 
Example #21
Source File: PdfIndirectObject.java    From itext2 with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
* Writes efficiently to a stream
*
* @param os the stream to write to
* @throws IOException on write error
*/
   void writeTo(OutputStream os) throws IOException
   {
       os.write(DocWriter.getISOBytes(String.valueOf(number)));
       os.write(' ');
       os.write(DocWriter.getISOBytes(String.valueOf(generation)));
       os.write(STARTOBJ);
       object.toPdf(writer, os);
       os.write(ENDOBJ);
   }
 
Example #22
Source File: MRtfWriter.java    From javamelody with Apache License 2.0 5 votes vote down vote up
/**
 * We create a writer that listens to the document and directs a RTF-stream to out
 *
 * @param table
 *           MBasicTable
 * @param document
 *           Document
 * @param out
 *           OutputStream
 * @return DocWriter
 */
@Override
protected DocWriter createWriter(final MBasicTable table, final Document document,
		final OutputStream out) {
	final RtfWriter2 writer = RtfWriter2.getInstance(document, out);

	// title
	final String title = buildTitle(table);
	if (title != null) {
		final HeaderFooter header = new RtfHeaderFooter(new Paragraph(title));
		header.setAlignment(Element.ALIGN_LEFT);
		header.setBorder(Rectangle.NO_BORDER);
		document.setHeader(header);
		document.addTitle(title);
	}

	// advanced page numbers : x/y
	final Paragraph footerParagraph = new Paragraph();
	final Font font = FontFactory.getFont(FontFactory.TIMES_ROMAN, 12, Font.NORMAL);
	footerParagraph.add(new RtfPageNumber(font));
	footerParagraph.add(new Phrase(" / ", font));
	footerParagraph.add(new RtfTotalPageNumber(font));
	footerParagraph.setAlignment(Element.ALIGN_CENTER);
	final HeaderFooter footer = new RtfHeaderFooter(footerParagraph);
	footer.setBorder(Rectangle.TOP);
	document.setFooter(footer);

	return writer;
}
 
Example #23
Source File: PdfEncryptionValidateIT.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void testSaveEncrypted() throws Exception {
  final URL url = getClass().getResource( "pdf-encryption-validate.xml" );
  assertNotNull( url );
  final ResourceManager resourceManager = new ResourceManager();
  resourceManager.registerDefaults();
  final Resource directly = resourceManager.createDirectly( url, MasterReport.class );
  final MasterReport report = (MasterReport) directly.getResource();

  final byte[] b = createPDF( report );
  final PdfReader reader = new PdfReader( b, DocWriter.getISOBytes( "Duck" ) );
  assertTrue( reader.isEncrypted() );
}
 
Example #24
Source File: PdfIndirectObject.java    From gcs with Mozilla Public License 2.0 5 votes vote down vote up
/**
 * Writes efficiently to a stream
 *
 * @param os the stream to write to
 * @throws IOException on write error
 */
void writeTo(OutputStream os) throws IOException {
	os.write(DocWriter.getISOBytes(String.valueOf(number)));
	os.write(' ');
	os.write(DocWriter.getISOBytes(String.valueOf(generation)));
	os.write(STARTOBJ);
	object.toPdf(writer, os);
	os.write(ENDOBJ);
}
 
Example #25
Source File: PdfIndirectObject.java    From MesquiteCore with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
* Writes eficiently to a stream
*
* @param os the stream to write to
* @throws IOException on write error
*/
   void writeTo(OutputStream os) throws IOException
   {
       os.write(DocWriter.getISOBytes(String.valueOf(number)));
       os.write(' ');
       os.write(DocWriter.getISOBytes(String.valueOf(generation)));
       os.write(STARTOBJ);
       int type = object.type();
       if (type != PdfObject.ARRAY && type != PdfObject.DICTIONARY && type != PdfObject.NAME && type != PdfObject.STRING)
           os.write(' ');
       object.toPdf(writer, os);
       os.write(ENDOBJ);
   }
 
Example #26
Source File: RtfCell.java    From itext2 with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
* Write the cell definition part of this RtfCell
*/
  public void writeDefinition(final OutputStream result) throws IOException 
  {
      if(this.mergeType == MERGE_VERT_PARENT) {
          result.write(DocWriter.getISOBytes("\\clvmgf"));
      } else if(this.mergeType == MERGE_VERT_CHILD) {
          result.write(DocWriter.getISOBytes("\\clvmrg"));
      }
      switch (verticalAlignment) {
          case Element.ALIGN_BOTTOM:
              result.write(DocWriter.getISOBytes("\\clvertalb"));
              break;
          case Element.ALIGN_CENTER:
          case Element.ALIGN_MIDDLE:
              result.write(DocWriter.getISOBytes("\\clvertalc"));
              break;
          case Element.ALIGN_TOP:
              result.write(DocWriter.getISOBytes("\\clvertalt"));
              break;
      }
      this.borders.writeContent(result);

      if(this.backgroundColor != null) {
          result.write(DocWriter.getISOBytes("\\clcbpat"));
          result.write(intToByteArray(this.backgroundColor.getColorNumber()));
      }
      this.document.outputDebugLinebreak(result);
      
      result.write(DocWriter.getISOBytes("\\clftsWidth3"));
      this.document.outputDebugLinebreak(result);
      
      result.write(DocWriter.getISOBytes("\\clwWidth"));
      result.write(intToByteArray(this.cellWidth));
      this.document.outputDebugLinebreak(result);
      
      if(this.cellPadding > 0) {
          result.write(DocWriter.getISOBytes("\\clpadl"));
          result.write(intToByteArray(this.cellPadding / 2));
          result.write(DocWriter.getISOBytes("\\clpadt"));
          result.write(intToByteArray(this.cellPadding / 2));
          result.write(DocWriter.getISOBytes("\\clpadr"));
          result.write(intToByteArray(this.cellPadding / 2));
          result.write(DocWriter.getISOBytes("\\clpadb"));
          result.write(intToByteArray(this.cellPadding / 2));
          result.write(DocWriter.getISOBytes("\\clpadfl3"));
          result.write(DocWriter.getISOBytes("\\clpadft3"));
          result.write(DocWriter.getISOBytes("\\clpadfr3"));
          result.write(DocWriter.getISOBytes("\\clpadfb3"));
      }
      result.write(DocWriter.getISOBytes("\\cellx"));
      result.write(intToByteArray(this.cellRight));
  }
 
Example #27
Source File: PatchRtfCell.java    From pentaho-reporting with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * Write the cell definition part of this PatchRtfCell
 */
public void writeDefinition( final OutputStream result ) throws IOException {
  if ( this.mergeType == MERGE_VERT_PARENT ) {
    result.write( DocWriter.getISOBytes( "\\clvmgf" ) );
  } else if ( this.mergeType == MERGE_VERT_CHILD ) {
    result.write( DocWriter.getISOBytes( "\\clvmrg" ) );
  }
  switch ( verticalAlignment ) {
    case Element.ALIGN_BOTTOM:
      result.write( DocWriter.getISOBytes( "\\clvertalb" ) );
      break;
    case Element.ALIGN_CENTER:
    case Element.ALIGN_MIDDLE:
      result.write( DocWriter.getISOBytes( "\\clvertalc" ) );
      break;
    case Element.ALIGN_TOP:
      result.write( DocWriter.getISOBytes( "\\clvertalt" ) );
      break;
  }
  this.borders.writeContent( result );

  if ( this.backgroundColor != null ) {
    result.write( DocWriter.getISOBytes( "\\clcbpat" ) );
    result.write( intToByteArray( this.backgroundColor.getColorNumber() ) );
  }
  this.document.outputDebugLinebreak( result );

  result.write( DocWriter.getISOBytes( "\\clftsWidth3" ) );
  this.document.outputDebugLinebreak( result );

  result.write( DocWriter.getISOBytes( "\\clwWidth" ) );
  result.write( intToByteArray( this.cellWidth ) );
  this.document.outputDebugLinebreak( result );

  if ( this.cellPadding > 0 ) {
    result.write( DocWriter.getISOBytes( "\\clpadl" ) );
    result.write( intToByteArray( this.cellPadding / 2 ) );
    result.write( DocWriter.getISOBytes( "\\clpadt" ) );
    result.write( intToByteArray( this.cellPadding / 2 ) );
    result.write( DocWriter.getISOBytes( "\\clpadr" ) );
    result.write( intToByteArray( this.cellPadding / 2 ) );
    result.write( DocWriter.getISOBytes( "\\clpadb" ) );
    result.write( intToByteArray( this.cellPadding / 2 ) );
    result.write( DocWriter.getISOBytes( "\\clpadfl3" ) );
    result.write( DocWriter.getISOBytes( "\\clpadft3" ) );
    result.write( DocWriter.getISOBytes( "\\clpadfr3" ) );
    result.write( DocWriter.getISOBytes( "\\clpadfb3" ) );
  }
  result.write( DocWriter.getISOBytes( "\\cellx" ) );
  result.write( intToByteArray( this.cellRight ) );
}
 
Example #28
Source File: PdfDocumentWriter.java    From pentaho-reporting with GNU Lesser General Public License v2.1 4 votes vote down vote up
public void open() throws DocumentException {
  this.document = new Document();
  // pageSize, marginLeft, marginRight, marginTop, marginBottom));

  writer = PdfWriter.getInstance( document, out );
  writer.setLinearPageMode();

  version = getVersion();
  writer.setPdfVersion( version );
  writer.setViewerPreferences( getViewerPreferences() );

  final String encrypt =
      config.getConfigProperty( "org.pentaho.reporting.engine.classic.core.modules.output.pageable.pdf.Encryption" );

  if ( encrypt != null ) {
    if ( encrypt.equals( PdfPageableModule.SECURITY_ENCRYPTION_128BIT ) == true
        || encrypt.equals( PdfPageableModule.SECURITY_ENCRYPTION_40BIT ) == true ) {
      final String userpassword =
          config
              .getConfigProperty( "org.pentaho.reporting.engine.classic.core.modules.output.pageable.pdf.UserPassword" );
      final String ownerpassword =
          config
              .getConfigProperty( "org.pentaho.reporting.engine.classic.core.modules.output.pageable.pdf.OwnerPassword" );
      // Log.debug ("UserPassword: " + userpassword + " - OwnerPassword: " + ownerpassword);
      final byte[] userpasswordbytes = DocWriter.getISOBytes( userpassword );
      byte[] ownerpasswordbytes = DocWriter.getISOBytes( ownerpassword );
      if ( ownerpasswordbytes == null ) {
        ownerpasswordbytes = PdfDocumentWriter.PDF_PASSWORD_PAD;
      }
      final int encryptionType;
      if ( encrypt.equals( PdfPageableModule.SECURITY_ENCRYPTION_128BIT ) ) {
        encryptionType = PdfWriter.STANDARD_ENCRYPTION_128;
      } else {
        encryptionType = PdfWriter.STANDARD_ENCRYPTION_40;
      }
      writer.setEncryption( userpasswordbytes, ownerpasswordbytes, getPermissions(), encryptionType );
    }
  }

  /**
   * MetaData can be set when the writer is registered to the document.
   */
  final String title =
      config.getConfigProperty( "org.pentaho.reporting.engine.classic.core.modules.output.pageable.pdf.Title", config
          .getConfigProperty( "org.pentaho.reporting.engine.classic.core.metadata.Title" ) );
  final String subject =
      config.getConfigProperty( "org.pentaho.reporting.engine.classic.core.modules.output.pageable.pdf.Description",
          config.getConfigProperty( "org.pentaho.reporting.engine.classic.core.metadata.Description" ) );
  final String author =
      config.getConfigProperty( "org.pentaho.reporting.engine.classic.core.modules.output.pageable.pdf.Author",
          config.getConfigProperty( "org.pentaho.reporting.engine.classic.core.metadata.Author" ) );
  final String keyWords =
      config.getConfigProperty( "org.pentaho.reporting.engine.classic.core.modules.output.pageable.pdf.Keywords",
          config.getConfigProperty( "org.pentaho.reporting.engine.classic.core.metadata.Keywords" ) );

  if ( title != null ) {
    document.addTitle( title );
  }
  if ( author != null ) {
    document.addAuthor( author );
  }
  if ( keyWords != null ) {
    document.addKeywords( keyWords );
  }
  if ( keyWords != null ) {
    document.addSubject( subject );
  }

  document.addCreator( PdfDocumentWriter.CREATOR );
  document.addCreationDate();

  // getDocument().open();
  awaitOpenDocument = true;
}
 
Example #29
Source File: RtfShape.java    From itext2 with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
   * Writes the RtfShape. Some settings are automatically translated into
   * or require other properties and these are set first.
   */    
  public void writeContent(final OutputStream result) throws IOException
  {
this.shapeNr = this.doc.getRandomInt();

this.properties.put("ShapeType", new RtfShapeProperty("ShapeType", this.type));
if(this.position.isShapeBelowText()) {
	this.properties.put("fBehindDocument", new RtfShapeProperty("fBehindDocument", true));
}
if(this.inTable) {
	this.properties.put("fLayoutInCell", new RtfShapeProperty("fLayoutInCell", true));
}
if(this.properties.containsKey("posh")) {
	this.position.setIgnoreXRelative(true);
}
if(this.properties.containsKey("posv")) {
	this.position.setIgnoreYRelative(true);
}
  	
  	result.write(OPEN_GROUP);
  	result.write(DocWriter.getISOBytes("\\shp"));
  	result.write(DocWriter.getISOBytes("\\shplid"));
  	result.write(intToByteArray(this.shapeNr));
  	this.position.writeContent(result);
  	switch(this.wrapping) {
  	case SHAPE_WRAP_NONE:
  		result.write(DocWriter.getISOBytes("\\shpwr3"));
  		break;
  	case SHAPE_WRAP_TOP_BOTTOM:
  		result.write(DocWriter.getISOBytes("\\shpwr1"));
  		break;
  	case SHAPE_WRAP_BOTH:
  		result.write(DocWriter.getISOBytes("\\shpwr2"));
  		result.write(DocWriter.getISOBytes("\\shpwrk0"));
  		break;
  	case SHAPE_WRAP_LEFT:
  		result.write(DocWriter.getISOBytes("\\shpwr2"));
  		result.write(DocWriter.getISOBytes("\\shpwrk1"));
  		break;
  	case SHAPE_WRAP_RIGHT:
  		result.write(DocWriter.getISOBytes("\\shpwr2"));
  		result.write(DocWriter.getISOBytes("\\shpwrk2"));
  		break;
  	case SHAPE_WRAP_LARGEST:
  		result.write(DocWriter.getISOBytes("\\shpwr2"));
  		result.write(DocWriter.getISOBytes("\\shpwrk3"));
  		break;
  	case SHAPE_WRAP_TIGHT_BOTH:
  		result.write(DocWriter.getISOBytes("\\shpwr4"));
  		result.write(DocWriter.getISOBytes("\\shpwrk0"));
  		break;
  	case SHAPE_WRAP_TIGHT_LEFT:
  		result.write(DocWriter.getISOBytes("\\shpwr4"));
  		result.write(DocWriter.getISOBytes("\\shpwrk1"));
  		break;
  	case SHAPE_WRAP_TIGHT_RIGHT:
  		result.write(DocWriter.getISOBytes("\\shpwr4"));
  		result.write(DocWriter.getISOBytes("\\shpwrk2"));
  		break;
  	case SHAPE_WRAP_TIGHT_LARGEST:
  		result.write(DocWriter.getISOBytes("\\shpwr4"));
  		result.write(DocWriter.getISOBytes("\\shpwrk3"));
  		break;
  	case SHAPE_WRAP_THROUGH:
  		result.write(DocWriter.getISOBytes("\\shpwr5"));
  		break;
  	default:
  		result.write(DocWriter.getISOBytes("\\shpwr3"));
  	}
  	if(this.inHeader) {
  		result.write(DocWriter.getISOBytes("\\shpfhdr1"));
  	} 
  	this.doc.outputDebugLinebreak(result);
  	result.write(OPEN_GROUP);
  	result.write(DocWriter.getISOBytes("\\*\\shpinst"));
  	Iterator it = this.properties.values().iterator();
  	while(it.hasNext()) {
  		RtfShapeProperty rsp = (RtfShapeProperty) it.next();
  		rsp.setRtfDocument(this.doc);
  		rsp.writeContent(result);
  	}
  	if(!this.shapeText.equals("")) {
  		result.write(OPEN_GROUP);
  		result.write(DocWriter.getISOBytes("\\shptxt"));
  		result.write(DELIMITER);
  		result.write(DocWriter.getISOBytes(this.shapeText));
  		result.write(CLOSE_GROUP);
  	}
  	result.write(CLOSE_GROUP);
  	this.doc.outputDebugLinebreak(result);
  	result.write(CLOSE_GROUP);

  }
 
Example #30
Source File: PdfContents.java    From MesquiteCore with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
* Constructs a <CODE>PdfContents</CODE>-object, containing text and general graphics.
*
* @param under the direct content that is under all others
* @param content the graphics in a page
* @param text the text in a page
* @param secondContent the direct content that is over all others
* @throws BadPdfFormatException on error
*/
   
   PdfContents(PdfContentByte under, PdfContentByte content, PdfContentByte text, PdfContentByte secondContent, Rectangle page) throws BadPdfFormatException {
       super();
       try {
           OutputStream out = null;
           streamBytes = new ByteArrayOutputStream();
           if (Document.compress)
           {
               compressed = true;
               out = new DeflaterOutputStream(streamBytes);
           }
           else
               out = streamBytes;
           int rotation = page.getRotation();
           switch (rotation) {
               case 90:
                   out.write(ROTATE90);
                   out.write(DocWriter.getISOBytes(ByteBuffer.formatDouble(page.top())));
                   out.write(' ');
                   out.write('0');
                   out.write(ROTATEFINAL);
                   break;
               case 180:
                   out.write(ROTATE180);
                   out.write(DocWriter.getISOBytes(ByteBuffer.formatDouble(page.right())));
                   out.write(' ');
                   out.write(DocWriter.getISOBytes(ByteBuffer.formatDouble(page.top())));
                   out.write(ROTATEFINAL);
                   break;
               case 270:
                   out.write(ROTATE270);
                   out.write('0');
                   out.write(' ');
                   out.write(DocWriter.getISOBytes(ByteBuffer.formatDouble(page.right())));
                   out.write(ROTATEFINAL);
                   break;
           }
           if (under.size() > 0) {
               out.write(SAVESTATE);
               under.getInternalBuffer().writeTo(out);
               out.write(RESTORESTATE);
           }
           if (content.size() > 0) {
               out.write(SAVESTATE);
               content.getInternalBuffer().writeTo(out);
               out.write(RESTORESTATE);
           }
           if (text != null) {
               out.write(SAVESTATE);
               text.getInternalBuffer().writeTo(out);
               out.write(RESTORESTATE);
           }
           if (secondContent.size() > 0) {
               secondContent.getInternalBuffer().writeTo(out);
           }
           out.close();
       }
       catch (Exception e) {
           throw new BadPdfFormatException(e.getMessage());
       }
       put(PdfName.LENGTH, new PdfNumber(streamBytes.size()));
       if (compressed)
           put(PdfName.FILTER, PdfName.FLATEDECODE);
   }