2017-03-29 10 views
1

フッタにテキストと一緒にフッタ番号を挿入したいがフッタにフッタスイッチの場所にテキスト、ページ番号、テキストが含まれている。 私はaspose words java libraryを使用して、文書をhtmlからwordに変換しています。 フッターのテキストがhtmlから送信され、ページ番号を追加したいだけです。フッターに追加ページ番号のフッタにテキスト付きのページ番号を挿入するaspose word java

コード:

log.debug("Add page number"); 
DocumentBuilder builder = new DocumentBuilder(doc); 

// Insert PAGE field into the footer 
builder.moveToHeaderFooter(HeaderFooterType.FOOTER_PRIMARY); 
builder.insertField("PAGE", null); 
builder.write("/"); 
builder.insertField("NUMPAGES", null); 

はまた、フッターにテキスト全体を交換する方法はありますか?

答えて

1

次のような表を使用して、フッターに一緒にページ番号とテキストを追加することができます。

DocumentBuilder builder = new DocumentBuilder(doc); 
// Insert PAGE field into the footer 
builder.moveToHeaderFooter(HeaderFooterType.FOOTER_PRIMARY); 
builder.startTable(); 
// Clear table borders 
builder.getCellFormat().clearFormatting(); 
builder.insertCell(); 
// Set first cell to 1/3 of the page width. 
builder.getCellFormat().setPreferredWidth(
PreferredWidth.fromPercent(100/3)); 
// Insert page numbering text here. 
// It uses PAGE and NUMPAGES fields to auto calculate current page 
// number and total number of pages. 
builder.insertField("PAGE", null); 
builder.write("/"); 
builder.insertField("NUMPAGES", null); 
// Align this text to the left. 
builder.getCurrentParagraph().getParagraphFormat() 
.setAlignment(ParagraphAlignment.LEFT); 
builder.insertCell(); 
// Set the second cell to 2/3 of the page width. 
builder.getCellFormat().setPreferredWidth(
PreferredWidth.fromPercent(100 * 2/3)); 
builder.write("(C) 2017 Aspose Pty Ltd. All rights reserved."); 
// Align this text to the right. 
builder.getCurrentParagraph().getParagraphFormat() 
.setAlignment(ParagraphAlignment.RIGHT); 
builder.endRow(); 
builder.endTable(); 

はフッターにアクセスすることができフッターのテキスト全体、明確なすべてのテキストを置き換えて、次のように新しい内容を追加するには:

DocumentBuilder builder = new DocumentBuilder(doc); 
Section currentSection = builder.getCurrentSection(); 
com.aspose.words.HeaderFooter primaryHeader = currentSection.getHeadersFooters().getByHeaderFooterType(HeaderFooterType.FOOTER_PRIMARY); 
primaryHeader.getParagraphs().clear(); 
... 

私はTilal Ahmad、Asposeの開発者エバンジェリストです。

関連する問題