Java Code Examples for com.lowagie.text.Document#setPageSize()

The following examples show how to use com.lowagie.text.Document#setPageSize() . 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: LandscapePortraitTest.java    From itext2 with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Creates a PDF document with pages in portrait/landscape.
 */
@Test
public void main() throws Exception {

	// step 1: creation of a document-object
	Document document = new Document(PageSize.A4.rotate());

	// step 2:
	// we create a writer that listens to the document
	// and directs a PDF-stream to a file

	PdfWriter.getInstance(document, PdfTestBase.getOutputStream("LandscapePortrait.pdf"));

	// step 3: we open the document
	document.open();

	// step 4: we add some content
	document.add(new Paragraph(
			"To create a document in landscape format, just make the height smaller than the width. For instance by rotating the PageSize Rectangle: PageSize.A4.rotate()"));
	document.setPageSize(PageSize.A4);
	document.newPage();
	document.add(new Paragraph("This is portrait again"));

	// step 5: we close the document
	document.close();
}
 
Example 2
Source File: InvestmentSummaryController.java    From primefaces-blueprints with The Unlicense 6 votes vote down vote up
public void preProcessPDF(Object document) throws IOException, BadElementException, DocumentException {  
    Document pdf = (Document) document; 
    pdf.setPageSize(PageSize.A3); 
    pdf.open();  
     
    ServletContext servletContext = (ServletContext) FacesContext.getCurrentInstance().getExternalContext().getContext();  
    String logo = servletContext.getRealPath("") + File.separator +"resources" + File.separator + "images" + File.separator +"logo" + File.separator + "logo.png";  
    Image image=Image.getInstance(logo);
    image.scaleAbsolute(100f, 50f);
    pdf.add(image); 
    // add a couple of blank lines
       pdf.add( Chunk.NEWLINE );
       pdf.add( Chunk.NEWLINE );
    Font fontbold = FontFactory.getFont("Times-Roman", 16, Font.BOLD);
    fontbold.setColor(55, 55, 55);;
    pdf.add(new Paragraph("Investment Summary",fontbold));
    // add a couple of blank lines
    pdf.add( Chunk.NEWLINE );
    pdf.add( Chunk.NEWLINE );
}
 
Example 3
Source File: AccountSummaryController.java    From primefaces-blueprints with The Unlicense 6 votes vote down vote up
public void preProcessPDF(Object document) throws IOException, BadElementException, DocumentException {  
    Document pdf = (Document) document;  
    pdf.setPageSize(PageSize.A3);
    pdf.open(); 
    ServletContext servletContext = (ServletContext) FacesContext.getCurrentInstance().getExternalContext().getContext();  
    String logo = servletContext.getRealPath("") + File.separator +"resources" + File.separator + "images" + File.separator +"logo" + File.separator + "logo.png";  
    Image image=Image.getInstance(logo);
    image.scaleAbsolute(100f, 50f);
    pdf.add(image); 
    // add a couple of blank lines
       pdf.add( Chunk.NEWLINE );
       pdf.add( Chunk.NEWLINE );
    Font fontbold = FontFactory.getFont("Times-Roman", 16, Font.BOLD);
    fontbold.setColor(55, 55, 55);;
    pdf.add(new Paragraph("Account Summary",fontbold));
    // add a couple of blank lines
    pdf.add( Chunk.NEWLINE );
    pdf.add( Chunk.NEWLINE );
}
 
Example 4
Source File: TransactionSummaryController.java    From primefaces-blueprints with The Unlicense 6 votes vote down vote up
public void preProcessPDF(Object document) throws IOException,
		BadElementException, DocumentException {
	Document pdf = (Document) document;
	pdf.setPageSize(PageSize.A4);
	pdf.open();

	ServletContext servletContext = (ServletContext) FacesContext
			.getCurrentInstance().getExternalContext().getContext();
	String logo = servletContext.getRealPath("") + File.separator
			+ "resources" + File.separator + "images" + File.separator
			+ "logo" + File.separator + "logo.png";
	Image image = Image.getInstance(logo);
	image.scaleAbsolute(100f, 50f);
	pdf.add(image);
	// add a couple of blank lines
	pdf.add(Chunk.NEWLINE);
	pdf.add(Chunk.NEWLINE);
	Font fontbold = FontFactory.getFont("Times-Roman", 16, Font.BOLD);
	fontbold.setColor(55, 55, 55);
	;
	pdf.add(new Paragraph("Transaction Summary", fontbold));
	// add a couple of blank lines
	pdf.add(Chunk.NEWLINE);
	pdf.add(Chunk.NEWLINE);
}
 
Example 5
Source File: PdfDocumentWriter.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
public void processLogicalPage( final LogicalPageKey key, final LogicalPageBox logicalPage ) throws DocumentException {

    final float width = (float) StrictGeomUtility.toExternalValue( logicalPage.getPageWidth() );
    final float height = (float) StrictGeomUtility.toExternalValue( logicalPage.getPageHeight() );

    final Rectangle pageSize = new Rectangle( width, height );

    final Document document = getDocument();
    document.setPageSize( pageSize );
    document.setMargins( 0, 0, 0, 0 );

    if ( awaitOpenDocument ) {
      document.open();
      awaitOpenDocument = false;
    }

    final Graphics2D graphics = new PdfGraphics2D( writer.getDirectContent(), width, height, metaData );
    // and now process the box ..
    final PdfLogicalPageDrawable logicalPageDrawable = createLogicalPageDrawable( logicalPage, null );
    logicalPageDrawable.draw( graphics, new Rectangle2D.Double( 0, 0, width, height ) );

    graphics.dispose();

    document.newPage();
  }
 
Example 6
Source File: Prd5321IT.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
protected TestPdfLogicalPageDrawable createDrawableForTest( final MasterReport report,
    final LogicalPageBox logicalPageBox ) throws DocumentException {
  Document document = new Document();
  PdfWriter writer = PdfWriter.getInstance( document, new NullOutputStream() );
  writer.setLinearPageMode();
  writer.open();

  document.setPageSize( new com.lowagie.text.Rectangle( 700, 500 ) );
  document.setMargins( 10, 10, 10, 10 );
  document.open();

  PdfOutputProcessorMetaData metaData =
      new PdfOutputProcessorMetaData( new ITextFontStorage( BaseFontModule.getFontRegistry() ) );
  metaData.initialize( report.getConfiguration() );
  final Graphics2D graphics = new PdfGraphics2D( writer.getDirectContent(), 700, 500, metaData );

  TestPdfLogicalPageDrawable pdf =
      new TestPdfLogicalPageDrawable( writer, new LFUMap<ResourceKey, Image>( 10 ), '5', graphics );
  pdf.init( logicalPageBox, metaData, report.getResourceManager(), logicalPageBox.getPageGrid().getPage( 0, 0 ) );
  return pdf;
}
 
Example 7
Source File: Prd3820IT.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
protected TestPdfLogicalPageDrawable createDrawableForTest( final MasterReport report,
    final LogicalPageBox logicalPageBox ) throws DocumentException {
  Document document = new Document();
  PdfWriter writer = PdfWriter.getInstance( document, new NullOutputStream() );
  writer.setLinearPageMode();
  writer.open();

  document.setPageSize( new com.lowagie.text.Rectangle( 700, 500 ) );
  document.setMargins( 10, 10, 10, 10 );
  document.open();

  PdfOutputProcessorMetaData metaData =
      new PdfOutputProcessorMetaData( new ITextFontStorage( BaseFontModule.getFontRegistry() ) );
  metaData.initialize( report.getConfiguration() );
  final Graphics2D graphics = new PdfGraphics2D( writer.getDirectContent(), 700, 500, metaData );

  TestPdfLogicalPageDrawable pdf =
      new TestPdfLogicalPageDrawable( writer, new LFUMap<ResourceKey, Image>( 10 ), '5', graphics );
  pdf.init( logicalPageBox, metaData, report.getResourceManager(), logicalPageBox.getPageGrid().getPage( 0, 0 ) );
  return pdf;
}
 
Example 8
Source File: OddEvenTest.java    From itext2 with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Combines 2 tiff-files into 1 PDF (similar to tiffmesh).
 * 
 * @param args
 *            [0] the file with the odd pages [1] the file with the even
 *            pages [2] the resulting file
 */
public void main(String... args) throws Exception {
	if (args.length < 3) {
		System.err.println("OddEven needs 3 Arguments.");
		System.out
				.println("Usage: com.lowagie.examples.objects.images.tiff.OddEven odd_file.tif even_file.tif combined_file.pdf");
		return;
	}
	RandomAccessFileOrArray odd = new RandomAccessFileOrArray(args[0]);
	RandomAccessFileOrArray even = new RandomAccessFileOrArray(args[1]);
	Image img = TiffImage.getTiffImage(odd, 1);
	Document document = new Document(new Rectangle(img.getScaledWidth(), img.getScaledHeight()));
	PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(args[2]));
	document.open();
	PdfContentByte cb = writer.getDirectContent();
	int count = Math.max(TiffImage.getNumberOfPages(odd), TiffImage.getNumberOfPages(even));
	for (int c = 0; c < count; ++c) {

		Image imgOdd = TiffImage.getTiffImage(odd, c + 1);
		Image imgEven = TiffImage.getTiffImage(even, count - c);
		document.setPageSize(new Rectangle(imgOdd.getScaledWidth(), imgOdd.getScaledHeight()));
		document.newPage();
		imgOdd.setAbsolutePosition(0, 0);
		cb.addImage(imgOdd);
		document.setPageSize(new Rectangle(imgEven.getScaledWidth(), imgEven.getScaledHeight()));
		document.newPage();
		imgEven.setAbsolutePosition(0, 0);
		cb.addImage(imgEven);

	}
	odd.close();
	even.close();
	document.close();

}
 
Example 9
Source File: DefaultPdfDataEntryFormService.java    From dhis2-core with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void generatePDFDataEntryForm( Document document, PdfWriter writer, String dataSetUid, int typeId,
    Rectangle pageSize, PdfFormFontSettings pdfFormFontSettings, I18nFormat format )
{
    try
    {
        this.pdfFormFontSettings = pdfFormFontSettings;
        this.format = format;

        document.setPageSize( pageSize );

        document.open();

        if ( typeId == PdfDataEntryFormUtil.DATATYPE_DATASET )
        {
            setDataSet_DocumentContent( document, writer, dataSetUid );
        }
        else if ( typeId == PdfDataEntryFormUtil.DATATYPE_PROGRAMSTAGE )
        {
            setProgramStage_DocumentContent( document, writer, dataSetUid );
        }
    }
    catch ( Exception ex )
    {
        throw new RuntimeException( ex );
    }
    finally
    {
        document.close();
    }
}
 
Example 10
Source File: PDFPage.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
public PDFPage( int pageWidth, int pageHeight, Document document,
		PdfWriter writer, PDFPageDevice pageDevice )
{
	super( pageWidth, pageHeight );
	this.writer = writer;
	this.pageDevice = pageDevice;
	this.containerHeight = this.pageHeight;
	Rectangle pageSize = new Rectangle( this.pageWidth, this.pageHeight );
	document.setPageSize( pageSize );
	if ( !document.isOpen( ) )
		document.open( );
	else
		document.newPage( );
	this.contentByte = writer.getDirectContent( );
}
 
Example 11
Source File: PdfDocumentWriter.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void processPhysicalPage( final PageGrid pageGrid, final LogicalPageBox logicalPage, final int row,
    final int col, final PhysicalPageKey pageKey ) throws DocumentException {
  final PhysicalPageBox page = pageGrid.getPage( row, col );
  if ( page == null ) {
    return;
  }

  final float width = (float) StrictGeomUtility.toExternalValue( page.getWidth() );
  final float height = (float) StrictGeomUtility.toExternalValue( page.getHeight() );

  final Rectangle pageSize = new Rectangle( width, height );

  final float marginLeft = (float) StrictGeomUtility.toExternalValue( page.getImageableX() );
  final float marginRight =
      (float) StrictGeomUtility.toExternalValue( page.getWidth() - page.getImageableWidth() - page.getImageableX() );
  final float marginTop = (float) StrictGeomUtility.toExternalValue( page.getImageableY() );
  final float marginBottom =
      (float) StrictGeomUtility.toExternalValue( page.getHeight() - page.getImageableHeight() - page.getImageableY() );

  final Document document = getDocument();
  document.setPageSize( pageSize );
  document.setMargins( marginLeft, marginRight, marginTop, marginBottom );

  if ( awaitOpenDocument ) {
    document.open();
    awaitOpenDocument = false;
  }

  final PdfContentByte directContent = writer.getDirectContent();
  final Graphics2D graphics = new PdfGraphics2D( directContent, width, height, metaData );
  final PdfLogicalPageDrawable logicalPageDrawable = createLogicalPageDrawable( logicalPage, page );
  final PhysicalPageDrawable drawable = createPhysicalPageDrawable( logicalPageDrawable, page );
  drawable.draw( graphics, new Rectangle2D.Double( 0, 0, width, height ) );

  graphics.dispose();

  document.newPage();
}
 
Example 12
Source File: SplitPdf.java    From itext2 with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * This class can be used to split an existing PDF file.
 * @param args the command line arguments
 */
public static void main(String args[]) {
    if (args.length != 4) {
        System.err.println("arguments: srcfile destfile1 destfile2 pagenumber");
    }
    else {
        try {
int pagenumber = Integer.parseInt(args[3]);
            
// we create a reader for a certain document
PdfReader reader = new PdfReader(args[0]);
// we retrieve the total number of pages
int n = reader.getNumberOfPages();
System.out.println("There are " + n + " pages in the original file.");
            
if (pagenumber < 2 || pagenumber > n) {
	throw new DocumentException("You can't split this document at page " + pagenumber + "; there is no such page.");
}
            
// step 1: creation of a document-object
Document document1 = new Document(reader.getPageSizeWithRotation(1));
Document document2 = new Document(reader.getPageSizeWithRotation(pagenumber));
// step 2: we create a writer that listens to the document
PdfWriter writer1 = PdfWriter.getInstance(document1, new FileOutputStream(args[1]));
PdfWriter writer2 = PdfWriter.getInstance(document2, new FileOutputStream(args[2]));
// step 3: we open the document
document1.open();
PdfContentByte cb1 = writer1.getDirectContent();
document2.open();
PdfContentByte cb2 = writer2.getDirectContent();
PdfImportedPage page;
int rotation;
int i = 0;
// step 4: we add content
while (i < pagenumber - 1) {
	i++;
	document1.setPageSize(reader.getPageSizeWithRotation(i));
	document1.newPage();
	page = writer1.getImportedPage(reader, i);
	rotation = reader.getPageRotation(i);
	if (rotation == 90 || rotation == 270) {
		cb1.addTemplate(page, 0, -1f, 1f, 0, 0, reader.getPageSizeWithRotation(i).getHeight());
	}
	else {
		cb1.addTemplate(page, 1f, 0, 0, 1f, 0, 0);
	}
}
while (i < n) {
	i++;
	document2.setPageSize(reader.getPageSizeWithRotation(i));
	document2.newPage();
	page = writer2.getImportedPage(reader, i);
	rotation = reader.getPageRotation(i);
	if (rotation == 90 || rotation == 270) {
		cb2.addTemplate(page, 0, -1f, 1f, 0, 0, reader.getPageSizeWithRotation(i).getHeight());
	}
	else {
		cb2.addTemplate(page, 1f, 0, 0, 1f, 0, 0);
	}
	System.out.println("Processed page " + i);
}
// step 5: we close the document
document1.close();
document2.close();
        }
        catch(Exception e) {
            e.printStackTrace();
        }
    }
}
 
Example 13
Source File: DefaultPageSizeTest.java    From itext2 with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Creates a PDF document with a certain pagesize
 * 
 * @param args
 *            no arguments needed here
 */
@Test
public void main() throws Exception {

	// step 1: creation of a document-object
	Document document = new Document();

	// step 2:
	// we create a writer that listens to the document
	// and directs a PDF-stream to a file

	PdfWriter.getInstance(document, PdfTestBase.getOutputStream("DefaultPageSize.pdf"));

	// step 3: we open the document
	document.open();

	// step 4: we add some paragraphs to the document
	document.add(new Paragraph("The default PageSize is DIN A4."));
	document.setPageSize(PageSize.A3);
	document.newPage();
	document.add(new Paragraph("This PageSize is DIN A3."));
	document.setPageSize(PageSize.A2);
	document.newPage();
	document.add(new Paragraph("This PageSize is DIN A2."));
	document.setPageSize(PageSize.A1);
	document.newPage();
	document.add(new Paragraph("This PageSize is DIN A1."));
	document.setPageSize(PageSize.A0);
	document.newPage();
	document.add(new Paragraph("This PageSize is DIN A0."));
	document.setPageSize(PageSize.A5);
	document.newPage();
	document.add(new Paragraph("This PageSize is DIN A5."));
	document.setPageSize(PageSize.A6);
	document.newPage();
	document.add(new Paragraph("This PageSize is DIN A6."));
	document.setPageSize(PageSize.A7);
	document.newPage();
	document.add(new Paragraph("This PageSize is DIN A7."));
	document.setPageSize(PageSize.A8);
	document.newPage();
	document.add(new Paragraph("This PageSize is DIN A8."));
	document.setPageSize(PageSize.LETTER);
	document.newPage();
	document.add(new Paragraph("This PageSize is LETTER."));
	document.add(new Paragraph("A lot of other standard PageSizes are available."));

	// step 5: we close the document
	document.close();
}
 
Example 14
Source File: EpubToPdfConverter.java    From website with GNU Affero General Public License v3.0 4 votes vote down vote up
public File convert(String epubPath) throws IOException,DocumentException {
	applyProperties(epub2pdfProps);
       File epubFile = new File(epubPath);
       if (!(epubFile.canRead())) {
           throw new IOException("Could not read " + epubPath);
       } else {
       	logger.debug("Converting " + epubFile.getAbsolutePath());
       }
       String epubFilename = epubFile.getName();
       String epubFilenameBase = epubFilename.substring(0, epubFilename.length()-5);
       String pdfFilename = epubFilenameBase + ".pdf";

       File outputFile = new File(outputDir.getAbsolutePath() + File.separator + pdfFilename);

       epubIn = Epub.fromFile(epubPath);
       XhtmlHandler.setSourceEpub(epubIn);

       Opf opf = epubIn.getOpf();
       List<String> contentPaths = opf.spineHrefs();
       List<File> contentFiles = new ArrayList<File>();
       for (String path : contentPaths) {
           contentFiles.add(new File(epubIn.getContentRoot(),path));
       }
       Ncx ncx = epubIn.getNcx();
       
       List<NavPoint> ncxToc = new ArrayList<NavPoint>();
       if(ncx != null) {
       	ncxToc.addAll(ncx.getNavPointsFlat());
       }
       
       Tree<TocTreeNode> tocTree = TocTreeNode.buildTocTree(ncx);
       XhtmlHandler.setTocTree(tocTree);
       
       Document doc = new Document();
       boolean pageSizeOK = doc.setPageSize(pageSize);
       boolean marginsOK = doc.setMargins(marginLeftPt, marginRightPt, marginTopPt, marginBottomPt);

       logger.debug("Writing PDF to " + outputFile.getAbsolutePath());
       PdfWriter writer = PdfWriter.getInstance(doc, new FileOutputStream(outputFile));
       writer.setStrictImageSequence(true);
       PdfOutline bookmarkRoot = null;

       if (!(pageSizeOK && marginsOK)) {
           throw new RuntimeException("Failed to set PDF page size a/o margins");
       }
       
       int fileCount = contentFiles.size();
       logger.debug("Processing " + fileCount + " HTML file(s): ");
       int currentFile = 0;

       for (File file : contentFiles) {
       	currentFile++;
       	
       	String progressChar;
       	
       	int mod10 = currentFile % 10;
       	if(mod10 == 5)
       		progressChar = "5";
       	else if(mod10 == 0) 
       		progressChar = "0";
       	else
       		progressChar = ".";
       	
       	logger.debug(progressChar);
           if (!(doc.isOpen())) {
               doc.open();
               doc.newPage();
               bookmarkRoot = writer.getRootOutline();
               XhtmlHandler.setBookmarkRoot(bookmarkRoot);
           }
           NavPoint fileLevelNP = Ncx.findNavPoint(ncxToc, file.getName());
           TreeNode<TocTreeNode> npNode = TocTreeNode.findInTreeByNavPoint(tocTree, fileLevelNP);
           
           if(fileLevelNP != null) {
           	doc.newPage();
           	PdfOutline pdfOutlineParent = bookmarkRoot;
           	if(npNode != null) {
           		TreeNode<TocTreeNode> parent = npNode.getParent();
           		if(parent != null) {
           			TocTreeNode parentTTN = parent.getValue();
           			if(parentTTN != null && parentTTN.getPdfOutline() != null) {
           				pdfOutlineParent = parentTTN.getPdfOutline();
           			}
           		}
           	}
           	
           	PdfDestination here = new PdfDestination(PdfDestination.FIT);
           	PdfOutline pdfTocEntry = new PdfOutline(pdfOutlineParent, here, fileLevelNP.getNavLabelText());
           	if(npNode != null) {
           		npNode.getValue().setPdfDestination(here);
           		npNode.getValue().setPdfOutline(pdfTocEntry);
           	}
           }
           XhtmlHandler.process(file.getCanonicalPath(), doc);
       }
       doc.close();
       logger.debug("PDF written to " + outputFile.getAbsolutePath());
       epubIn.cleanup();
       return outputFile;
}
 
Example 15
Source File: TableBorderExTest.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
protected void setUp( ) throws Exception
{
	super.setUp( );

	cells[0] = new CellArea( 10, 10, 40, 40 );
	cells[0].defineBorder( BorderInfo.TOP_BORDER, 2 );
	cells[0].defineBorder( BorderInfo.TOP_BORDER, Color.blue );
	cells[0].defineBorder( BorderInfo.LEFT_BORDER, 6 );
	cells[0].defineBorder( BorderInfo.LEFT_BORDER, Color.orange );
	cells[1] = new CellArea( 50, 10, 40, 40 );
	cells[1].defineBorder( BorderInfo.TOP_BORDER, 4 );
	cells[1].defineBorder( BorderInfo.TOP_BORDER, Color.blue );
	cells[2] = new CellArea( 90, 10, 40, 40 );
	cells[2].defineBorder( BorderInfo.TOP_BORDER, 6 );
	cells[2].defineBorder( BorderInfo.TOP_BORDER, Color.blue );
	cells[2].defineBorder( BorderInfo.RIGHT_BORDER, 6 );
	cells[2].defineBorder( BorderInfo.RIGHT_BORDER, Color.orange );
	cells[3] = new CellArea( 10, 50, 40, 80 );
	cells[3].defineBorder( BorderInfo.LEFT_BORDER, 6 );
	cells[3].defineBorder( BorderInfo.LEFT_BORDER, Color.orange );
	cells[3].defineBorder( BorderInfo.BOTTOM_BORDER, 6 );
	cells[3].defineBorder( BorderInfo.BOTTOM_BORDER, Color.blue );
	cells[4] = new CellArea( 50, 50, 40, 40 );
	cells[4].defineBorder( BorderInfo.TOP_BORDER, 2 );
	cells[4].defineBorder( BorderInfo.TOP_BORDER, Color.green );
	cells[5] = new CellArea( 90, 50, 40, 40 );
	cells[5].defineBorder( BorderInfo.LEFT_BORDER, 0 );
	cells[5].defineBorder( BorderInfo.TOP_BORDER, 0 );
	cells[5].defineBorder( BorderInfo.RIGHT_BORDER, 6 );
	cells[5].defineBorder( BorderInfo.RIGHT_BORDER, Color.orange );
	cells[6] = null;//new CellArea( 10, 90, 40, 40 );
	cells[7] = new CellArea( 50, 90, 40, 40 );
	cells[7].defineBorder( BorderInfo.BOTTOM_BORDER, 4 );
	cells[7].defineBorder( BorderInfo.BOTTOM_BORDER, Color.blue );
	cells[8] = new CellArea( 90, 90, 40, 40 );
	cells[8].defineBorder( BorderInfo.TOP_BORDER, 0 );
	cells[8].defineBorder( BorderInfo.LEFT_BORDER, 2 );
	cells[8].defineBorder( BorderInfo.LEFT_BORDER, Color.red );
	cells[8].defineBorder( BorderInfo.BOTTOM_BORDER, 2 );
	cells[8].defineBorder( BorderInfo.BOTTOM_BORDER, Color.blue );
	cells[8].defineBorder( BorderInfo.RIGHT_BORDER, 6 );
	cells[8].defineBorder( BorderInfo.RIGHT_BORDER, Color.orange );
	Document document = new Document( );
	try
	{
		// step 2: creation of the writer
		PdfWriter writer = PdfWriter.getInstance( document,
				new FileOutputStream( "TableBorderTestEx.pdf" ) );
		// step 3: we open the document
		Rectangle pageSize = new Rectangle( pageWidth, pageHeight );
		document.setPageSize( pageSize );
		document.open( );
		// step 4: we grab the ContentByte and do some stuff with it
		cb = writer.getDirectContent( );
		testBorderDraw( );
	}
	catch ( DocumentException de )
	{
		System.err.println( de.getMessage( ) );
	}
	catch ( IOException ioe )
	{
		System.err.println( ioe.getMessage( ) );
	}

	// step 5: we close the document
	document.close( );
}
 
Example 16
Source File: TableBorderPDFTest.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
protected void setUp( ) throws Exception
{
	super.setUp( );

	cells[0] = new CellArea( 10, 10, 40, 40 );
	cells[0].defineBorder( BorderInfo.TOP_BORDER, 2 );
	cells[0].defineBorder( BorderInfo.TOP_BORDER, Color.blue );
	cells[0].defineBorder( BorderInfo.LEFT_BORDER, 6 );
	cells[0].defineBorder( BorderInfo.LEFT_BORDER, Color.orange );
	cells[1] = new CellArea( 50, 10, 40, 40 );
	cells[1].defineBorder( BorderInfo.TOP_BORDER, 4 );
	cells[1].defineBorder( BorderInfo.TOP_BORDER, Color.blue );
	cells[2] = new CellArea( 90, 10, 40, 40 );
	cells[2].defineBorder( BorderInfo.TOP_BORDER, 6 );
	cells[2].defineBorder( BorderInfo.TOP_BORDER, Color.blue );
	cells[2].defineBorder( BorderInfo.RIGHT_BORDER, 6 );
	cells[2].defineBorder( BorderInfo.RIGHT_BORDER, Color.orange );
	cells[3] = new CellArea( 10, 50, 40, 80 );
	cells[3].defineBorder( BorderInfo.LEFT_BORDER, 6 );
	cells[3].defineBorder( BorderInfo.LEFT_BORDER, Color.orange );
	cells[3].defineBorder( BorderInfo.BOTTOM_BORDER, 6 );
	cells[3].defineBorder( BorderInfo.BOTTOM_BORDER, Color.blue );
	cells[4] = new CellArea( 50, 50, 40, 40 );
	cells[4].defineBorder( BorderInfo.TOP_BORDER, 2 );
	cells[5] = new CellArea( 90, 50, 40, 40 );
	cells[5].defineBorder( BorderInfo.LEFT_BORDER, 0 );
	cells[5].defineBorder( BorderInfo.TOP_BORDER, 0 );
	cells[5].defineBorder( BorderInfo.RIGHT_BORDER, 6 );
	cells[5].defineBorder( BorderInfo.RIGHT_BORDER, Color.orange );
	cells[6] = null;//new CellArea( 10, 90, 40, 40 );
	cells[7] = new CellArea( 50, 90, 40, 40 );
	cells[7].defineBorder( BorderInfo.BOTTOM_BORDER, 4 );
	cells[7].defineBorder( BorderInfo.BOTTOM_BORDER, Color.blue );
	cells[8] = new CellArea( 90, 90, 40, 40 );
	cells[8].defineBorder( BorderInfo.BOTTOM_BORDER, 2 );
	cells[8].defineBorder( BorderInfo.BOTTOM_BORDER, Color.blue );
	cells[8].defineBorder( BorderInfo.RIGHT_BORDER, 6 );
	cells[8].defineBorder( BorderInfo.RIGHT_BORDER, Color.orange );
	Document document = new Document( );
	try
	{
		// step 2: creation of the writer
		PdfWriter writer = PdfWriter.getInstance( document,
				new FileOutputStream( "TableBorderPDFTest.pdf" ) );
		// step 3: we open the document
		Rectangle pageSize = new Rectangle( pageWidth, pageHeight );
		document.setPageSize( pageSize );
		document.open( );
		// step 4: we grab the ContentByte and do some stuff with it
		cb = writer.getDirectContent( );
		testBorderDraw( );
	}
	catch ( DocumentException de )
	{
		System.err.println( de.getMessage( ) );
	}
	catch ( IOException ioe )
	{
		System.err.println( ioe.getMessage( ) );
	}

	// step 5: we close the document
	document.close( );
}