I use a Table to fill information in the header of my document.
But I want the tabel wider so that more information can be shown.
But when I save the document as pdf their's a difference in location and size off the pdf.
(I also miss al line off my header in the example.)
Should I move the table on a other way or is this a bug.
PS I'm using: Aspose.Words (Java) version 16.2.0.0
{code}
try {
String userprofile = System.getenv("USERPROFILE");
Document lDocument = new Document( userprofile + "\\Desktop\\A test word document.docx" );
File lNewFileDocument = new File( userprofile + "\\Desktop\\A test word document-edit.docx" );
File lNewFilePdf = new File( userprofile + "\\Desktop\\A test word document-edit.pdf" );
DocumentBuilder lDocumentBuilder = new DocumentBuilder( lDocument );
Section lCurrentSection = lDocumentBuilder.getCurrentSection();
com.aspose.words.PageSetup lPageSetup = lCurrentSection.getPageSetup();
lPageSetup.setHeaderDistance( 20d );
// lDocumentBuilder.moveToHeaderFooter( HeaderFooterType.HEADER_PRIMARY );
Table lTable = lDocumentBuilder.startTable();
for ( int lRowIndex = 0; lRowIndex < 5; lRowIndex++ ) {
for ( int lColIndex = 0; lColIndex < 3; lColIndex++ ) {
Cell lCell = lDocumentBuilder.insertCell();
//Reset de Font en Aligment naar standaard. (De wijzigingen gaan door naar nieuwe cellen)
lDocumentBuilder.getCellFormat().clearFormatting();
lDocumentBuilder.getCellFormat().getBorders().clearFormatting();
lDocumentBuilder.getCellFormat().getBorders().setLineWidth( 1.0 );
lDocumentBuilder.getCellFormat().getBorders().setLineStyle( LineStyle.SINGLE );
lDocumentBuilder.getParagraphFormat().setAlignment( ParagraphAlignment.LEFT );
lDocumentBuilder.getParagraphFormat().setSpaceBefore( 0d );
lDocumentBuilder.getParagraphFormat().setSpaceAfter( 0d );
lDocumentBuilder.getFont().clearFormatting();
lDocumentBuilder.getFont().setName( "Verdana" );
lDocumentBuilder.getFont().setSize( 8.5d );
lDocumentBuilder.getFont().setBold( false );
lDocumentBuilder.getCellFormat().getShading().clearFormatting();
switch ( lColIndex ) {
case 0:
lCell.getCellFormat().setPreferredWidth( PreferredWidth.fromPercent( 15d ) );
break;
case 1:
lCell.getCellFormat().setPreferredWidth( PreferredWidth.fromPercent( 43d ) );
break;
case 2:
lCell.getCellFormat().setPreferredWidth( PreferredWidth.fromPercent( 20d ) );
break;
}
//First row, left and middle Merge First
if ( lRowIndex == 0 && lColIndex < 2 ) {
lCell.getCellFormat().setVerticalMerge( CellMerge.FIRST );
} else if ( lRowIndex > 0 && lColIndex < 2 ) { // Second row and further, left and middle merge previous.
lCell.getCellFormat().setVerticalMerge( CellMerge.PREVIOUS );
} else { // else dont merge
lCell.getCellFormat().setVerticalMerge( CellMerge.NONE );
}
/*
| left | middle | right-0 |
| | | right-1 |
| | | {page} |
| | | right-3 |
| | | right-4 |
*/
if ( lColIndex == 2 ) {
lDocumentBuilder.write( "right" );
Cell lCellValue = lDocumentBuilder.insertCell();
//Reset de Font en Aligment naar standaard. (De wijzigingen gaan door naar nieuwe cellen)
lDocumentBuilder.getParagraphFormat().setAlignment( ParagraphAlignment.LEFT );
lDocumentBuilder.getFont().setName( "Verdana" );
lDocumentBuilder.getFont().setSize( 8.5d );
lDocumentBuilder.getFont().setBold( false );
lCellValue.getCellFormat().setVerticalMerge( lCell.getCellFormat().getVerticalMerge() );
lDocumentBuilder.getCellFormat().getShading().clearFormatting();
lCellValue.getCellFormat().setPreferredWidth( PreferredWidth.fromPercent( 22d ) );
if ( lRowIndex == 3 ) {
lDocumentBuilder.insertField( "PAGE \\* MERGEFORMAT" );
// lDocumentBuilder.insertField( "DOCPROPERTY LastSavedTime \\* MERGEFORMAT" );
} else {
lDocumentBuilder.write( lRowIndex + "" );
}
} else {
if ( lRowIndex == 1 ) {
if ( lColIndex == 0 ) {
lDocumentBuilder.write( "left" );
} else {
lDocumentBuilder.write( "middle" );
}
}
}//if
} // for col
lDocumentBuilder.endRow();
}
lDocumentBuilder.endTable();
//De tabel in de header hetzelfde formaat geven als die van de html.
//BUG Aspose de header/footer heeft niet dezelfde breedte in Word als bij pdf.
// Section lCurrentSection = lDocumentBuilder.getCurrentSection();
// com.aspose.words.PageSetup lPageSetup = lCurrentSection.getPageSetup();
lTable.setLeftIndent( -lPageSetup.getLeftMargin() + 15 ); //
lTable.setPreferredWidth( PreferredWidth.fromPercent( 120.5d ) ); //Voor Word documenten
// lTable.setPreferredWidth( PreferredWidth.fromPercent( 110.0d ) ); //Voor PDF gegenereerde
lDocument.save( lNewFileDocument.getAbsolutePath() );
lDocument.save( lNewFilePdf.getAbsolutePath() );
} catch(Exception ex){
LOG.error("AsposeTest ", ex);
}
{code}