2013-01-11 3 views
0

html 페이지를 pdf로 변환. pdf로 페이지를 변환하면 html 페이지 내용이 A4 페이지에 맞지 않습니다. 나는 전체 HTML 페이지가 누락 된 내용없이 PDF로 변환되기를 원한다.HTML 페이지 축소 및 A4 크기로 변환 pdf

은 이미 PDF

  String tempOutFileNameXHTML = "/Users/Common/index" + i + DOT + "xhtml"; 
      String tempOutFileNamePDF = "/Users/Common/index" + i + DOT + PDF; 
      File targetFile = targetFiles.get(i); // gets all the specified html files 
      CleanerProperties props = new CleanerProperties(); 
      props.setTranslateSpecialEntities(true); 
      props.setTransResCharsToNCR(true); 
      props.setOmitComments(true); 

      //checking of starting and ending tags are in proper 
      HtmlCleaner htmlCleaner = new HtmlCleaner(props); 
      TagNode tagNode = htmlCleaner.clean(targetFile); 
      PrettyXmlSerializer prettyXmlSerializer = new PrettyXmlSerializer(props); 

      prettyXmlSerializer.writeToFile(tagNode, tempOutFileNameXHTML, "utf-8"); 

      File xhtmlpath = new File(tempOutFileNameXHTML); 
      File pdfPath = new File(tempOutFileNamePDF); 
      com.itextpdf.text.Document pdfDocument = null; 
      PdfWriter pdfWriter = null; 
      pdfDocument = new com.itextpdf.text.Document(com.itextpdf.text.PageSize.A4); // TODO handle this 

      pdfWriter = PdfWriter.getInstance(pdfDocument, new FileOutputStream(pdfPath)); 
      pdfDocument.open(); 
      Font catFont = new Font(Font.FontFamily.TIMES_ROMAN, 25, Font.BOLD); 
      pdfDocument.add(new Paragraph("Target : " + targetFile.getParentFile().getName(), catFont)); 

      XMLWorkerHelper.getInstance().parseXHtml(pdfWriter, (com.itextpdf.text.Document) pdfDocument, 
        new FileInputStream(xhtmlpath), null); 

      pdfDocument.close(); 

여기에서의 문제 HTML 페이지 폭이 너무 긴 경우, 그것은 A4 크기의 PDF에 맞지입니다으로 HTML로 변환 코드를 데. 어쨌든 축소하거나 pdf로 만들거나 콘텐츠를 잃어 버리지 마십시오. ? 어떻게 할 수 있습니까? HTML 페이지 축소 및 PDF로 변환 할 수 있습니까? 이 작업을 수행하는 방법에 대한 아이디어가 있습니까?

+0

이 게시물을 살펴보십시오. 도움이 될 수 있습니다. http://stackoverflow.com/questions/14089883/how-to-create-several-pages-with-dompdf/14089936#14089936 –

답변

0

"Flying Saucer XHTML 렌더러 프로젝트는 XHTML을 PDF로 출력하는 기능을 지원합니다. 예제는 here입니다."

>SOURCE <

0

는 iText를 아마 CSS 스타일을 지원합니다. 스타일 시트를 사용하여 한 페이지에 맞도록 HTML 페이지의 서식을 지정할 수 있습니다. 스타일 시트 및 iText에 대한 정보 : http://itextpdf.com/examples/iia.php?id=56

앞서 언급했듯이, 또 다른 HTML to PDF 변환기 인 Flying Saucer를 사용해 볼 수도 있습니다. 적어도 Flying Saucer를 사용하면 실제 스타일 시트를 제공 할 수 있으며 CSS 지원은 꽤 좋습니다.

관련 문제