/** * 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); }
/** * 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")); }
/** * 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); }
/** * 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")); }
/** * 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; }
/** * 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); }
/** * * @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); }
/** * 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; } } } }
/** * 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); }
/** * 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); }
/** * 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)); }
/** * 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); }
/** * 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); }
/** * 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")); } }
/** * 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); }
/** * 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); }
/** * 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); }
/** * 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); }
/** * 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); }
/** * 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); }
/** * 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; }
/** * 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); }