-
Notifications
You must be signed in to change notification settings - Fork 148
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
Page numbers header footer #133
base: master
Are you sure you want to change the base?
Page numbers header footer #133
Conversation
This appears as helper methods for paragraphs and table cells. Works really well in the headers and footers of subsequent commits, but not so well in the body of a page. The information needed to calculate the fields is apparently not ready until the pages are completely rendered requiring a user to invoke the update fields command manually after the doc is opened in Word or other Offiiceish product. We could eventually add support for the dirty flag on `w:fldChar`, however, it does cause Word to prompt the user in an alarming fashion when the document loads, doesn't solve the issue for documents meant to be perfect when they are opened, and isn't as likely a use case as headers or footers. We should consider how best to add other fields and their formats http://officeopenxml.com/WPfieldInstructions.php.
2ba5633
to
5895814
Compare
This helper method provides a footer object to its block with functionality similar to a table cell but rendering as a document footer. It is superceded by `.page_numbers`. Also, it writes content to a document level header_content object rendered separately as `word/footer1.xml`. This allows us to write ``` docx.footer do |footer| footer.p 'hello there' end ``` or ``` docx.footer do |footer| footer.table [[a cell]] end ```
Provides a document level `.header` method passing its block a header object having essentially the same functionality as a table cell but rendering as a document header. It writes content to a document level header_content object rendered separately as `word/header.xml`. This means you can write ``` docx.header do |header| header.p 'hello there' end ``` or ``` docx.header do |header| header.table [[one cell]] end ```
5895814
to
f9e44f1
Compare
Hello @benjaminketron, Thanks for this solution, But I found one issue while implementing this change Issue: If I open a file(page number: Page 1 of 5) in the WPS office so it is showing me Page PAGE of NUMPAGES (Instead of actual number). Could you please confirm? |
Hi @benjaminketron, I tried this PR to generate a sample document with header, but MS Word 365 failed to open it. Do you know what the problem might be? Caracal::Document.save 'example.docx' do |docx|
docx.header do |header|
header.p 'hello there'
end
docx.font name: 'Arial'
docx.h1 'Page 1 Header'
docx.hr
docx.p
docx.h2 'Section 1'
docx.p 'Lorem ipsum dolor....'
docx.p
end |
If anyone is interested/still needs this, we have a fork that we're maintaining that has a working implementation of this: |
Hi @jdugan. Hope you are well and enjoying the holiday season!
We are working on a basic page header and footer implementation, and hoped to get your thoughts. We haven't yet planned for the more complicated scenarios with headers / footers on even / odd pages, sections, etc since it is outside the scope of our work, but thought this might be a good foundation to build upon.
The footer implementation is a bit interesting since for backward compatibility it can be superceded by
page_numbers
.We've also added a rudimentary
field
text helper that supports PAGE and NUMPAGES, but not yet formatting or any of the other fields.I am having second thoughts about adding
footer_content
andheader_content
instead of adding them directly to thecontents
array, but it does simplify the rendering logic....Any time you can spend on this would be much appreciated. 😄