2009-12-30 48 views
6

我創建了一個基於HTML的報告,它可以是C#中可變長度和段數(這是爲什麼不使用Crystal Reports),我無法使用精彩http://www.printfriendly.com/由於報告是基於內聯網的(boooo,嘶嘶聲)。基於HTML的報告被分頁撕成片段

我已經創建了一個media =打印CSS文件,用於儘可能使紙張和墨水的格式化,但我有一個問題。報告中有一張很長的表格,大約有50個表格行,每個表格的高度約爲200px。不幸的是,一些錶行由於自動分頁而被切片,其中一部分錶行在一頁上,其餘部分在下一頁上。無論如何(希望通過CSS),將分頁選項設置爲不分離表格元素(或類似元素)?

謝謝, 亞歷克斯

+0

我希望CSS能夠更好地處理打印表格,但它似乎不能很好地處理CSS分頁符選項。我也想看看這個解決方案。 –

+0

對於答覆的遲到表示抱歉,已經過了短暫的假期。在仔細考慮之後,我決定給Brian一個答案,因爲他通過他的測試發現了一些有趣的結果,並提出了與Prince合作的解決方案。我還標記markjgrant的答案,因爲這是一個可能的解決方案,通過黑客,我沒有想到。 – Alex

回答

1

page-break-inside: avoid財產應該控制這一點,但它看起來像大多數的瀏覽器不支持對trtd元素。在我的測試,Opera是既尊重這個屬性,如下面的測試中使用的只有一個:

<!DOCTYPE html> 
<title>Page Break Test</title> 
<style>tr, td { page-break-inside: avoid }</style> 
<table border=1> 
    <tr height=200><td>This is a test. This should be tall.<td>Another column. 
    <tr height=200><td>This is a test. This should be tall.<td>Another column. 
    <tr height=200><td>This is a test. This should be tall.<td>Another column. 
    <tr height=200><td>This is a test. This should be tall.<td>Another column. 
    <tr height=200><td>This is a test. This should be tall.<td>Another column. 
    <tr height=200><td>This is a test. This should be tall.<td>Another column. 
    <tr height=200><td>This is a test. This should be tall.<td>Another column. 
    <tr height=200><td>This is a test. This should be tall.<td>Another column. 
    <tr height=200><td>This is a test. This should be tall.<td>Another column. 
    <tr height=200><td>This is a test. This should be tall.<td>Another column. 
    <tr height=200><td>This is a test. This should be tall.<td>Another column. 
    <tr height=200><td>This is a test. This should be tall.<td>Another column. 
    <tr height=200><td>This is a test. This should be tall.<td>Another column. 
    <tr height=200><td>This is a test. This should be tall.<td>Another column. 
    <tr height=200><td>This is a test. This should be tall.<td>Another column. 
    <tr height=200><td>This is a test. This should be tall.<td>Another column. 
</table> 

如果你可以使用Opera,這可能是不夠好。另一種方法是查看Prince是否打印報告,因爲它比瀏覽器更容易支持打印樣式表功能(儘管我沒有特別測試過這個功能)。

1

如果您的行高恰好是固定的,那麼您可以計算出頁面上有多少行,然後在每一行中使用page-break-after: always以在適當的位置強制分頁。這有點破解,但它可能是你最好的選擇。

+1

但他永遠不會知道有多少人會適合,因爲不同的瀏覽器打印不同,用戶可以增加/減少字體大小,用戶可以更改打印邊距和頁面大小。 –

+0

media = print CSS可以儘量減少這些因素,但不能完全消除這些因素。 – keithjgrant

1

不幸的是,用HTML可靠地完成你想要的是不可能的。

如果您想對打印內容進行高級控制,我建議您將報告生成器輸出爲PDF或XPS而不是HTML(或者像Brian Campbell所建議的那樣,使用諸如Prince之類的工具,可以將HTML和將其轉換爲PDF)。