loftylabs / django-hardcopy

Render PDFs from HTML in Python/Django using Headless Chrome
http://hirelofty.com
128 stars 11 forks source link

Hide date, url and page count in pdf #13

Closed ilyachch closed 4 years ago

ilyachch commented 6 years ago

Is there a way to remove headers and footers on pages in rendered pdf? I need margins, but they must be blank. I tried to make it with css:

@page{
    margin: 0;
    size: auto;
}

but so pages are without margin, that I need.

Is there a some key to call chrome?

tried to combine this solution with wrapping page content into div with styles:

.wrapper{
    margin: 15mm 10mm 15mm 15mm; 
}

but this helps only for first and last pages. pages between looks like they have no top and bottom margins.

ilyachch commented 6 years ago

read this there is not such special key for it=( but is there any hack for it?

ckinsey commented 6 years ago

@ilyachch Have you tried using a print media query in your CSS?

https://www.smashingmagazine.com/2011/11/how-to-set-up-a-print-style-sheet/

Chrome's PDF feature is essentially the same as it's print feature, so it has some default styles for print media (mostly around margins / page layout) that are possibly overriding your changes.

ilyachch commented 6 years ago

of course. unfortunately, this does not help - this headers and footers appears after styles applied. the only way - to use margins 0, but so i can't imagine how to make document content positioned. to wrap every content block and set paddings - works only for left and right. content length is random, so some blocks can be 2 or event 3 pages. in this case, with using padding, top padding will be on first page.

alchemyconsulting commented 6 years ago

Apparently as of recent Chrome there are options for this: https://stackoverflow.com/a/49147539

lq0373 commented 5 years ago

I've had the same problem. It's not solved yet.

ilyachch commented 5 years ago

@lq0373 Hi! If it would be helpful for you, i walked this issue around by making style for @print media query and made my page look like a printed. and then with default printing system made print. And if you want, i can try to find for this styles.

lq0373 commented 5 years ago

@ilyachch Thank you very much. I have left a little bit of the height of the header footer at present, otherwise the link address will be exposed. The header footer is covered by div on the front and back pages.

tapionx commented 5 years ago

@ilyachch i'm having this issue as well, could you provide with a CSS snippet?

ilyachch commented 5 years ago

@tapionx this works fine only in chrome based browsers, in firefox there is something going wrong (had no time to research it), but for me it was better, then nothing. Also, it was a little specific, so, there are some strangle classes. You can experiment with it, as you want=)

body {
    font-family: 'PT Serif', serif;
}

/* Signature Elements */
span.signature:after {
    content: '________________';
}

span.small_signature:after {
    content: '________';
}

span.extrasmall_signature:after {
    content: '____';
}

.photo_place {
    display: block;
    width: 3cm;
    height: 4cm;
    /*border: 1px solid black;*/
    margin-right: 10px;
}

span.signature, span.small_signature, span.extrasmall_signature {
    background-color: lightgray !important;
}

/* Page Break Elements */
div.page_break, div.page_break_block, div.page_break_invisible {
    page-break-after: always;
}

.non-breakable {
    page-break-inside: avoid;
}

/* Additional Elements */
.small_text {
    font-size: 12px;
}

.table_wide_border tr, .table_wide_border td, .table_wide_border th {
    border: 3px solid black !important;
}

.table-no-border, .table-no-border * {
    border: none !important;
}

.table_part_without_border, .table_part_without_border tr, .table_part_without_border td, .table_part_without_border th {
    border: none !important;
}

.bck_with_blue_color, .bck_with_blue_color tr, .bck_with_blue_color td, .bck_with_blue_color th {
    background-color: #b9e2ff !important;
}

.table-sm td {
    padding: 3px !important;
}

td.td-bottom {
    vertical-align: bottom !important;
}

.text_order {
    font-size: 12pt;
}

ul {
    list-style-type: disc;
}

hr {
    margin-top: 5px;
    margin-bottom: 5px;
}

@media screen {
    .document_data {
        min-height: 15cm;
    }

    body {
        background: dimgray;
    }

    .smaller-font {
        font-size: 11px;
    }

    .document {
        width: 21cm;
        min-height: 29.7cm;
        margin: 0.5cm auto 3cm;
        padding: 1cm 1cm 2cm 2cm;
        background: white;
        page-break-after: always;
    }

    .document_horizontal {
        width: 90%;
        min-height: 21cm;
        margin: 0.5cm 5% 3cm;
        padding: 1cm 1cm 2cm 2cm;
        background: white;
        page-break-after: always;
    }

    .document_half_height {
        height: auto;
    }

    .pressed_table tr, .pressed_table td, .pressed_table th {
        padding: 2px 4px !important;
    }

    div.page_break_block, div.page_break {
        width: 29cm;
        background: dimgray;
        margin-left: -5cm;
        margin-bottom: 1.5cm;
        margin-top: 1.5cm;
    }

    div.page_break_block {
        height: 1.5cm;
    }

    div.page_break {
        height: 0.5cm;
    }
}

@media print {
    body {
        margin: 0;
        font-size: 10pt;
    }

    .font_95 {
        font-size: 9.5pt;
    }

    .font_90 {
        font-size: 9pt;
    }

    .font_85 {
        font-size: 8.5pt;
    }

    .font_80 {
        font-size: 8pt;
    }

    h4.pressed_doc {
        margin-top: 4px !important;
        margin-bottom: 4px !important;
    }

    .pressed_doc {
        line-height: 16px !important;
    }

    .pressed_table tr, .pressed_table td, .pressed_table th {
        padding: 2px 4px !important;
    }

    p {
        margin-bottom: 4px !important;
    }

    .document_half_height {
        height: 500px;
    }

    .document {
        padding-left: 0.5cm;
        page-break-after: always;
    }
}
tapionx commented 5 years ago

thanks!

lq0373 commented 4 years ago

I'm so sorry, I don't have time to read the mail I'm very glad to receive your email. I'm very moved

------------------ 原始邮件 ------------------ 发件人: "Ilya Chichak"<notifications@github.com>; 发送时间: 2019年10月10日(星期四) 晚上6:59 收件人: "loftylabs/django-hardcopy"<django-hardcopy@noreply.github.com>; 抄送: "一帆风顺"<1203194080@qq.com>;"Mention"<mention@noreply.github.com>; 主题: Re: [loftylabs/django-hardcopy] Hide date, url and page count in pdf (#13)

@tapionx this works fine only in chrome based browsers, in firefox there is something going wrong (had no time to research it), but for me it was better, then nothing. Also, it was a little specific, so, there are some strangle classes. You can experiment with it, as you want=) body { font-family: 'PT Serif', serif; } / Signature Elements / span.signature:after { content: '____'; } span.small_signature:after { content: '____'; } span.extrasmall_signature:after { content: '____'; } .photo_place { display: block; width: 3cm; height: 4cm; /border: 1px solid black;/ margin-right: 10px; } span.signature, span.small_signature, span.extrasmall_signature { background-color: lightgray !important; } / Page Break Elements / div.page_break, div.page_break_block, div.page_break_invisible { page-break-after: always; } .non-breakable { page-break-inside: avoid; } / Additional Elements / .small_text { font-size: 12px; } .table_wide_border tr, .table_wide_border td, .table_wide_border th { border: 3px solid black !important; } .table-no-border, .table-no-border * { border: none !important; } .table_part_without_border, .table_part_without_border tr, .table_part_without_border td, .table_part_without_border th { border: none !important; } .bck_with_blue_color, .bck_with_blue_color tr, .bck_with_blue_color td, .bck_with_blue_color th { background-color: #b9e2ff !important; } .table-sm td { padding: 3px !important; } td.td-bottom { vertical-align: bottom !important; } .text_order { font-size: 12pt; } ul { list-style-type: disc; } hr { margin-top: 5px; margin-bottom: 5px; } @media screen { .document_data { min-height: 15cm; } body { background: dimgray; } .smaller-font { font-size: 11px; } .document { width: 21cm; min-height: 29.7cm; margin: 0.5cm auto 3cm; padding: 1cm 1cm 2cm 2cm; background: white; page-break-after: always; } .document_horizontal { width: 90%; min-height: 21cm; margin: 0.5cm 5% 3cm; padding: 1cm 1cm 2cm 2cm; background: white; page-break-after: always; } .document_half_height { height: auto; } .pressed_table tr, .pressed_table td, .pressed_table th { padding: 2px 4px !important; } div.page_break_block, div.page_break { width: 29cm; background: dimgray; margin-left: -5cm; margin-bottom: 1.5cm; margin-top: 1.5cm; } div.page_break_block { height: 1.5cm; } div.page_break { height: 0.5cm; } } @media print { body { margin: 0; font-size: 10pt; } .font_95 { font-size: 9.5pt; } .font_90 { font-size: 9pt; } .font_85 { font-size: 8.5pt; } .font_80 { font-size: 8pt; } h4.pressed_doc { margin-top: 4px !important; margin-bottom: 4px !important; } .pressed_doc { line-height: 16px !important; } .pressed_table tr, .pressed_table td, .pressed_table th { padding: 2px 4px !important; } p { margin-bottom: 4px !important; } .document_half_height { height: 500px; } .document { padding-left: 0.5cm; page-break-after: always; } }

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or unsubscribe.