5

こんにちは、CSS3 ページ メディア モジュールを使用して、ブラウザーから直接 HTML コンテンツを PDF に出力しましたが、ブラウザーで動作させることができません。私の仕事は以下です。

<!DOCTYPE html>
<html lang="en">
<head>
<style>
@media print {

body {
        margin: 0;
        padding: 0;
        background-color: #FAFAFA;
        font: 12pt "sans-serif";
        position: relative;
    }
    * {
        box-sizing: border-box;
        -moz-box-sizing: border-box;
    }


        @page {
            size: letter;
            margin: 20mm 25mm;
        }
        @page {
            @top-center {
                content: element(pageHeader);
            }
        }

        @page  {
            @bottom-center {
                content: element(pageFooter);
            }
        }
        #pageHeader {
          position: running(pageHeader);
        }
        #pageFooter{
          position: running(pageFooter);
        }

    }
</style>
</head>
<body>
<div id="pageHeader">
    <p>This is the Header shown on first page.</p>
</div>
<div id="pageFooter">
    <p>This is the footer shown on last page.</p>
</div>
<section class="page"> 

<h1>Introduction</h1>
<p>The margins can be set as displayed in the examples above, or can be set for each side individually, as shown in the code snippet below, where the top and bottom margins are set to 2cm, and the left and right margins are set to 3cm:
The margins can be set as displayed in the examples above, or can be set for each side individually, as shown in the code snippet below, where the top and bottom margins are set to 2cm, and the left and right margins are set to 3cm:
The margins can be set as displayed in the examples above, or can be set for each side individually, as shown in the code snippet below, where the top and bottom margins are set to 2cm, and the left and right margins are set to 3cm:
The margins can be set as displayed in the examples above, or can be set for each side individually, as shown in the code snippet below, where the top and bottom margins are set to 2cm, and the left and right margins are set to 3cm:</p>

<p>
The margins can be set as displayed in the examples above, or can be set for each side individually, as shown in the code snippet below, where the top and bottom margins are set to 2cm, and the left and right margins are set to 3cm:
The margins can be set as displayed in the examples above, or can be set for each side individually, as shown in the code snippet below, where the top and bottom margins are set to 2cm, and the left and right margins are set to 3cm:
The margins can be set as displayed in the examples above, or can be set for each side individually, as shown in the code snippet below, where the top and bottom margins are set to 2cm, and the left and right margins are set to 3cm:
The margins can be set as displayed in the examples above, or can be set for each side individually, as shown in the code snippet below, where the top and bottom margins are set to 2cm, and the left and right margins are set to 3cm:

</p>
<p>The margins can be set as displayed in the examples above, or can be set for each side individually, as shown in the code snippet below, where the top and bottom margins are set to 2cm, and the left and right margins are set to 3cm:
The margins can be set as displayed in the examples above, or can be set for each side individually, as shown in the code snippet below, where the top and bottom margins are set to 2cm, and the left and right margins are set to 3cm:
The margins can be set as displayed in the examples above, or can be set for each side individually, as shown in the code snippet below, where the top and bottom margins are set to 2cm, and the left and right margins are set to 3cm:
The margins can be set as displayed in the examples above, or can be set for each side individually, as shown in the code snippet below, where the top and bottom margins are set to 2cm, and the left and right margins are set to 3cm:</p>


 </section>


 </body>
</html>

私にとっては、どのブラウザでも機能しません。最新の Chrome、FF、Opera、Safari でテストしました。すべてのページにヘッダーとフッターを表示する必要があります。ヘッダーはすべてのページの上部に表示され、フッターはすべてのページの下部に表示されます。実際に機能するCSS3ページのメディアモジュール要素の実際の例を持っている人はいますか? また、ヘッダーとフッターの位置絶対または固定ソリューションを探していません。試してみましたが、単一ページ以外は機能しません。この質問のテキスト コンテンツを短縮しましたが、ヘッダーとフッターなしで複数のページを表示するために、複数ページのドキュメントを作成するためにコピー アンド ペーストすることができます。ヘッダーとフッターの div は一番上にとどまります。

4

2 に答える 2

3

現在、エンドユーザーのブラウザーではサポートされていませんが、PDF を生成するための専用エンジンである PrinceXML ではサポートされています。マージン ボックスの CSS3 サポートを参照してください。

PrinceXML は商用製品ですが、HTML ソースから小説の印刷版を作成するために使用しています。印刷関連機能の包括的なリストをサポートしています。(私は彼らとは何の関係もありません。)

于 2014-08-22T23:29:26.697 に答える