2017-03-29 6 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(); 
... 

저는 Aspose의 개발자 전도사 인 Tilal Ahmad입니다.