Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent default Header creation #251

Closed
Mitiryl opened this issue Jan 16, 2019 · 8 comments · Fixed by #829
Closed

Prevent default Header creation #251

Mitiryl opened this issue Jan 16, 2019 · 8 comments · Fixed by #829

Comments

@Mitiryl
Copy link

Mitiryl commented Jan 16, 2019

Hi!
Using your library, we find out that it creates by default a header unless a template with headers array is specified.
Maybe could be possible to create the document without the default header (and also default footer) or add an option to remove it?
Thanks

@dolanmiu
Copy link
Owner

Yes correct, it creates a header and footer by default

What is the use-case for not creating a default header/footer?

Can you explain

@Mitiryl
Copy link
Author

Mitiryl commented Jan 16, 2019

Because the default header has margin, and even if I left the header empty, the printed file has extra margin.
Now, as workaround I overwrite the default header style setting the spacing to 0, but I was wondering if it could be possible to remove it or define an option to prevent its creation.

@dolanmiu
Copy link
Owner

dolanmiu commented Jan 16, 2019

Ah yes, you have a good point there

I will think of a solution for v5

@parweb77
Copy link

parweb77 commented Jan 5, 2020

Can you suggest how to set the header margin to 0 ? I am creating a document with no header or footer and I don't want the extra margin on the document.

@gytisgreitai
Copy link

gytisgreitai commented Feb 26, 2020

@Mitiryl how do you overwrite default header style?

@arthurstelmach
Copy link

arthurstelmach commented Jun 8, 2020

@parweb77 , @gytisgreitai,

Workaround for this issue is set 'headers' and 'footers' in margins to null, in this way:

import * as fs from 'fs'
import { Document, TextRun, Paragraph, Packer } from 'docx'

const doc = new Document()

doc.addSection({
  margins: {
    top: 0,
    right: 0,
    bottom: 0,
    left: 0,
    headers: null,
    footers: null
  },
  children: [
    new Paragraph({
      children: [
        new TextRun('Hello World')
      ]
    })
  ]
})

Packer.toBuffer(doc)
  .then(buffer => {
    fs.writeFileSync('My Document.docx', buffer)
  })

@valentin-papin
Copy link

@arthurstelmach Thanks for your trick. Very usefull.

@dolanmiu
Copy link
Owner

dolanmiu commented Mar 16, 2021

default headers are now undefined by default starting from version 6.0.0, no more hacking around!

Fixed by: #829

dolanmiu added a commit that referenced this issue Mar 16, 2021
#251 Turning off default headers by default
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants