2012-11-14 2 views
2

HTML 콘텐츠가 포함 된 문자열이 있고이를 JeditorPane으로 설정하고 있습니다. 캐릭터 라인에는 이미지 소스가 포함되어 있습니다. 나는 그것을 렌더링하는 많은 문제에 직면하고있다.Jeditorpane의 html 텍스트 내부에 이미지를 렌더링하는 데 문제가 있습니다.

이미지를 프린터로 보내야합니다. 모든 것이 좋지만 로고는 항상 깨진 이미지입니다.

이 HTML 코드

<td style="width:20%; height: auto" colspan="1"> 
<img src = "images/client-logo1.png" /> 
</td> 

이며,이 내가 문자열 이름 HTML

protected byte[] createImage(String html, String imageName) { 
    final String methodName = "createImage"; 
    if (LOG.isTraceEnabled()) { 
     LOG.trace("enter\n\t{}", new Object[] {html, imageName}); 
    } 
    StringReader reader = new StringReader(""); 
    JEditorPane pane = new JEditorPane(); 
    // pane.setEditable(false); 
    pane.setEditorKit(new HTMLEditorKit()); 
    pane.setContentType("text/html"); 
    pane.setText(html); 
    pane.setSize(IMAGE_WIDTH, IMAGE_HEIGHT); 
    pane.setBackground(Color.white); 

    // Create a BufferedImage 
    BufferedImage image = new BufferedImage(pane.getWidth(), pane 
      .getHeight(), BufferedImage.TYPE_INT_ARGB); 
    Graphics2D g = image.createGraphics(); 

    // Have the image painted by SwingUtilities 
    JPanel container = new JPanel(); 
    SwingUtilities.paintComponent(g, pane, container, 0, 0, image 
      .getWidth(), image.getHeight()); 
    g.dispose(); 
    byte[] imageInByte = null; 
    try { 
    ByteArrayOutputStream baos = new ByteArrayOutputStream(); 
    ImageIO.write(image, "PNG", baos); 
    baos.flush(); 
    imageInByte = baos.toByteArray(); 
    } catch (IOException e1) { 
     e1.printStackTrace(); 
     throw new CVProxyApplicationException(
       "Not able to create image due to: " 
         + e1.getLocalizedMessage()); 
    } 
    if (LOG.isTraceEnabled()) { 
     LOG.trace("exit\n\t{}"); 
    } 
    /* 
    * // If printer supports bytes, no need to create an image. 
    * ByteArrayOutputStream os = new ByteArrayOutputStream(); 
    * image.flush(); try { ImageIO.write(image, "png", os); os.flush(); } 
    * catch (IOException e1) { e1.printStackTrace(); } return 
    * os.toByteArray(); 
    */ 
    return imageInByte; 
} 

도움으로 HTML을 읽은 후 그것을 활용하고 어떻게 ???

+0

그래서에 표시된 이미지를 않습니다 창은 바르게? 틀린 인쇄 부분일까요? –

+0

많은 텍스트를 표시하는 큰 html ..... 모든 것이 잘 인쇄되지만 태그 ...로 정의 된 이미지는 이미지가 렌더링되지 않습니다. –

+0

표시해야하는 컨테이너 이미지가 깨진 이미지를 보여줍니다 ... –

답변

1

문제가 SRC 속성에있는 것으로 의심됩니다. images/client-logo1.png이 이미지의 실제 경로인지 확인하십시오. 로컬에 저장된 경우 접두어 file:을 사용하십시오. 이미지가 경로에서 Windows에 C 저장되어있는 경우

예를 들어, : \ 이미지 \ 클라이언트 logo1.png을, img 태그는 다음과 같습니다

<img src="file:C:\images\client-logo1.png" />