2012-09-26 3 views
1

에 결과 PDF는 원본 HTML 페이지와 같은 스타일이 아닙니다. 처음에는 기본 제공 CSS 파서가 직접 태그 스타일 및 클래스 (thead th { background-color:#999; }과 같은 체인이 없음)에서만 작동하는 것처럼 보입니다.iTextSharp XMLWorkerHelper HTML PDF 표 맞춤를 PDF로 HTML 파일의 내용을 분석하고 응답 스트림으로 덤프 다음 ASP.net/iTextSharp 코드를 사용하여

둘째, 경계는 모두 또는 전혀 거래되지 않는 것으로 보입니다. border-top, border-bottom 등의 개념이 없으며 경계 붕괴는 인접한 셀의 경계를 붕괴시키지 않으므로 국경이 원하는만큼 두껍게됩니다.

마지막으로 테이블을 문서의 왼쪽 또는 오른쪽에 정렬하는 방법을 알 수 없습니다. 항상 중심에 위치합니다. 내가 텍스트 정렬로 div에 배치를 시도했다. 정렬 속성을 설정하려고 시도했다. 텍스트 정렬을 테이블에 직접 설정했다. 그걸 알아낼 수 없습니까?

<!DOCTYPE html> 
<html> 
<head> 
    <title>This is the title</title> 
    <meta name="description" content="This is the description" /> 
    <meta name="keywords" content="abc, 123, xyz" /> 
    <style type="text/css"> 
     body { font-family:Arial, Verdana, Sans-Serif; font-size:9pt; } 
     .dataGrid { font-family:Arial, Verdana, Sans-Serif; font-size:9pt; border-collapse: collapse; border:1px solid #000; width:80%; margin:0; text-align:left; } 
     th { padding:3px 4px; font-weight:bold; border:1px solid #000; } 
     td { padding:3px 4px; border:1px solid #000; } 
     .head { border-bottom:2px solid #000; background-color:#9BBA1F; font-weight:bold; } 
     .odd { background-color:#fff; } 
     .even { background-color:#D6EB87; } 
     .foot { border-top:2px solid #000; background-color:#BAB0C4; font-weight:bold; } 
     h1 { font-size:14pt; color:#FFA200; text-align:center; } 
     .right { text-align:right; } 
     .center { text-align:center; } 
     .left { text-align:left; } 
    </style> 
</head> 
<body> 
    <h1>Sample Document</h1> 

    <div style="text-align:left;"> 
    <table class="dataGrid" align="left"> 
     <thead> 
      <tr class="head"> 
       <th width="70%">Name</th> 
       <th width="15%" class="center">Qty</th> 
       <th width="15%" class="center">Price</th> 
      </tr> 
     </thead> 
     <tbody> 
      <tr class="odd"> 
       <td>ABC</td> 
       <td class="center">2</td> 
       <td class="right">$5.00</td> 
      </tr> 
      <tr class="even"> 
       <td>XYZ</td> 
       <td class="center">1</td> 
       <td class="right">$10.00</td> 
      </tr> 
      <tr class="odd"> 
       <td>123</td> 
       <td class="center">3</td> 
       <td class="right">$2.00</td> 
      </tr> 
      <tr class="even"> 
       <td>789</td> 
       <td class="center">1</td> 
       <td class="right">$4.00</td> 
      </tr> 
     </tbody> 
     <tfoot> 
      <tr class="foot"> 
       <td class="right">Totals</td> 
       <td class="center">7</td> 
       <td class="right">$30.00</td> 
      </tr> 
     </tfoot> 
    </table> 
    </div> 
</body> 
</html> 

답변

1

이에 시간의 무리를 지출 한 후 나는 그것이 제대로 작동 가져올 수 없습니다 :

는 여기에 내가 개념 증명으로 사용하기 위해 노력하고있어 내 데모 문서입니다. 따라서 wkHtmlToPdf라는 다른 도구로 전환했습니다. Nuget에서 제공되는 Codaxy 래퍼 클래스를 사용하여 호출을 작성하고 iTextSharp에서 본 것보다 훨씬 나은 결과를 얻었습니다. 대부분 CSS 선택기를 이해하고 이미지와 링크 같은 것을 자동으로 처리합니다.