나는 pdf를 생성해야하는 다음과 같은 상태에 처해있다.ITextRenderer를 사용하여 각 페이지에 머리말과 꼬리말을 추가하는 방법
내가 뭘하고 있는가하면 PDF를 생성하기 위해 ITextRenderer를 사용하여 내 컨트롤러에서
String A="<html><head></head><body>Some start html content"
String B="here the string is create **dynamic** where this can be of any length"
String C=here its end section of html..... </body></html>"
String finalHtml=A+B+C;
입니다. 내 컨트롤러의 내용은 다음과 같습니다.
@RequestMapping(value="/genratePdf",method=RequestMethod.GET)
public void getPdfGenration(HttpServletRequest request,HttpServletResponse response){
response.setContentType("application/pdf");
StringBuffer buf = new StringBuffer();
buf.append(finalHtml);
try{
DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document doc = builder.parse(new StringBufferInputStream(buf.toString()));
ITextRenderer renderer = new ITextRenderer()
renderer.layout();
java.io.OutputStream os = response.getOutputStream();
renderer.createPDF(os);
os.flush();
os.close();
}catch (Exception ex) {
ex.printStackTrace();
}
이 잘 작동하고 나에게 PDF를 반환하지만 난이 직면하고있는 문제는 모든 페이지 .ANY의 도움이나 제안에 헤더에게 컨텐츠를 배치하는 것입니다. 나는 스프링 3.1.and 항아리를 사용하고 있는데 사용 된 iText-paulo-155.jar, itext-2.1.0.jar 미리 감사드립니다.
덕분에 내가 하나의 작업 두번째 시도했지만 유는 여기에 HTML 태그를 수락 여부를 알 수있다