We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Issue if header cell has rowspan

If table header cell has rowspan and then the cell is not rendering properly in PDF. The row span works fine for non-header row, but if we put rowspan for a header cell then it is not rendering properly (cell border and vertical alignment), spans_in_header.pdf (2.8 KB)

Below is the code I am trying -
private static void exportTable() throws IOException {
Page page =document.getPages().add();
PageInfo pageInfo = page.getPageInfo();
MarginInfo marginInfo = new MarginInfo();
marginInfo.setBottom( 15 );
marginInfo.setTop( 15 );
marginInfo.setLeft( 15 );
marginInfo.setRight( 15 );
pageInfo.setMargin( marginInfo );

	Table table = new Table();
	table.setHorizontalAlignment(1);
	table.setBordersIncluded(true);
	table.setRepeatingRowsCount(1);
	//table.setColumnAdjustment(ColumnAdjustment.AutoFitToContent);
	table.setColumnWidths( "20% 20% 20% 20% 20%" );
	
	BorderInfo info = new BorderInfo( BorderSide.All, 1 );		
	info = new BorderInfo( BorderSide.All, Color.getBlack() );
	TextFragment textFragment;
	
	//Header rows 
	Row pdfRow = table.getRows().add();
	//pdfRow.setMinRowHeight(50);
	
	Cell cell00 = new Cell();
	cell00.setBorder( info );
	cell00.setBackgroundColor(Color.getGray());
	textFragment = new TextFragment("Cell00");
	cell00.getParagraphs().add(textFragment);
	pdfRow.getCells().add(cell00);
	
	Cell cell01 = new Cell();
	cell01.setBorder( info );
	cell01.setBackgroundColor(Color.getGray());
	textFragment = new TextFragment("cell01");
	cell01.getParagraphs().add(textFragment);
	pdfRow.getCells().add(cell01);
	
	Cell cell02 = new Cell();
	cell02.setBorder( info );
	cell02.setRowSpan(2);
	cell02.setBackgroundColor(Color.getGray());
	textFragment = new TextFragment("cell02");
	cell02.getParagraphs().add(textFragment);
	cell02.setVerticalAlignment(VerticalAlignment.Center);
	pdfRow.getCells().add(cell02);
	
	Cell cell03 = new Cell();
	cell03.setBorder( info );
	cell03.setBackgroundColor(Color.getGray());
	textFragment = new TextFragment("cell03");
	cell03.getParagraphs().add(textFragment);
	pdfRow.getCells().add(cell03);
	
	Cell cell04 = new Cell();
	cell04.setBorder( info );
	cell04.setBackgroundColor(Color.getGray());
	textFragment = new TextFragment("cell04");
	cell04.getParagraphs().add(textFragment);
	pdfRow.getCells().add(cell04);
	
	//Header rows 
	pdfRow = table.getRows().add();
	//pdfRow.setBackgroundColor(Color.getGray());
	//pdfRow.setMinRowHeight(50);
	
	Cell cell10 = new Cell();
	cell10.setBorder( info );
	cell10.setBackgroundColor(Color.getGray());
	textFragment = new TextFragment("cell10");
	cell10.getParagraphs().add(textFragment);
	pdfRow.getCells().add(cell10);
	
	Cell cell12 = new Cell();
	cell12.setBorder( info );
	cell12.setBackgroundColor(Color.getGray());
	textFragment = new TextFragment("cell12");
	cell12.getParagraphs().add(textFragment);
	pdfRow.getCells().add(cell12);
	
	Cell cell13 = new Cell();
	cell13.setBorder( info );
	cell13.setColSpan(2);
	cell13.setBackgroundColor(Color.getGray());
	textFragment = new TextFragment("cell13");
	cell13.getParagraphs().add(textFragment);
	pdfRow.getCells().add(cell13);
	
	/*Cell cell14 = new Cell();
	cell14.setBorder( info );
	cell14.setBackgroundColor(Color.getGray());
	textFragment = new TextFragment("cell14");
	cell14.getParagraphs().add(textFragment);
	pdfRow.getCells().add(cell14);*/

	// non-header rows
	
	pdfRow = table.getRows().add();
	//pdfRow.setMinRowHeight(50);
	
	Cell cell20 = new Cell();
	cell20.setBorder( info );
	textFragment = new TextFragment("cell20");
	cell20.getParagraphs().add(textFragment);
	pdfRow.getCells().add(cell20);
	
	Cell cell21 = new Cell();
	cell21.setBorder( info );
	textFragment = new TextFragment("cell21");
	cell21.getParagraphs().add(textFragment);
	pdfRow.getCells().add(cell21);
	
	Cell cell22 = new Cell();
	cell22.setBorder( info );
	cell22.setRowSpan(2);
	textFragment = new TextFragment("cell22");
	cell22.getParagraphs().add(textFragment);
	cell22.setVerticalAlignment(VerticalAlignment.Center);
	pdfRow.getCells().add(cell22);
	
	Cell cell23 = new Cell();
	cell23.setBorder( info );
	textFragment = new TextFragment("cell23");
	cell23.getParagraphs().add(textFragment);
	pdfRow.getCells().add(cell23);
	
	Cell cell24 = new Cell();
	cell24.setBorder( info );
	textFragment = new TextFragment("cell24");
	cell24.getParagraphs().add(textFragment);
	pdfRow.getCells().add(cell24);
	
	pdfRow = table.getRows().add();
	
	Cell cell30 = new Cell();
	cell30.setBorder( info );
	textFragment = new TextFragment("cell30");
	cell30.getParagraphs().add(textFragment);
	pdfRow.getCells().add(cell30);
	
	Cell cell31 = new Cell();
	cell31.setBorder( info );
	textFragment = new TextFragment("cell31");
	cell31.getParagraphs().add(textFragment);
	pdfRow.getCells().add(cell31);
	
	Cell cell32 = new Cell();
	cell32.setBorder( info );
	textFragment = new TextFragment("cell32");
	cell32.getParagraphs().add(textFragment);
	pdfRow.getCells().add(cell32);
	
	Cell cell33 = new Cell();
	cell33.setBorder( info );
	textFragment = new TextFragment("cell33");
	cell33.getParagraphs().add(textFragment);
	pdfRow.getCells().add(cell33);
	for(int i=0;i<10;i++ ) {
		
		pdfRow = table.getRows().add();
		for (int j=0;j<5;j++) {
			Cell cell = new Cell();
			info = new BorderInfo( BorderSide.All, 1 );
			cell.setBorder( info );
			
			info = new BorderInfo( BorderSide.All, Color.getBlack() );
			cell.setBorder( info );
			textFragment = new TextFragment("cell" + (i+4)+""+(j));
			cell.getParagraphs().add(textFragment);
			pdfRow.getCells().add(cell);
		}
	}
	
	page.getParagraphs().add( table );
	document.save( "E:\\pdfs\\AsposeTests\\spans_in_header.pdf" );
	document.close();
}

@BALKRUSHNA015478

The issue has already been observed in our environment during testing the scenario. Therefore, it is logged as PDFJAVA-40572 in our issue tracking system. We will further look into its details and keep you posted with the status of its correction. Please be patient and spare us some time.

We are sorry for the inconvenience.