How do you create numbered sections for PDF and Word exports from Confluence?
Asked by Debbi Sedlak:

We are using Confluence as our documents with a space template to create numbered sections, but that formatting does not export to Word or PDF. How do I get the section numbers to export?

To further clarify:

I use a space stylesheet (CSS) to create numbered headings. However, while the effects of those styles show on the page in Confluence, when you export, the numbering does not display in the exports. I tried cutting and pasting that stylesheet into the PDF stylesheet but it does not work. Headings are like this:

1. Heading 1

1.1 Heading 2

1.1.1 Heading 3

1.1.1.1 Heading 4

etc.

I know the TOC macro shows the heading numbers, but I need the heading numbers shown in the body of the document, not just in the table of contents. We are using Confluence pages as documents. We need the exports to share with people outside of Confluence to comment on the documents.


Answers:
author: Ferdinand F?rstenau
body: For everyone looking, Chatgpt gave the correct answer.

<br />

body { counter-reset: heading1_counter; }

h1 { counter-reset: heading2_counter; }

h2 { counter-reset: heading3_counter; }

h1:before { content: counter(heading1_counter) ". ";

counter-increment: heading1_counter; }

h2:before { content: counter(heading1_counter) "." counter(heading2_counter) ". ";

counter-increment: heading2_counter; }

h3:before { content: counter(heading1_counter) "." counter(heading2_counter) "." counter(heading3_counter) ". ";

counter-increment: heading3_counter; }


author: Chee T
body: Hi Debbi,

Based on your code, I put my code as below and it works for chapter. I did same way in h2/h3 but it doesn't work as expected.

----------------------------------------

body {  
counter-reset: heading1_counter;  
}

h1:before {  
content: counter(heading1_counter) ". ";  
counter-increment: heading1_counter;  
}


author: Nils Bier _K15t_
body: Hi Debbi,

How are those numbered sections created? Are you using the [numbered heading macro](https://marketplace.atlassian.com/plugins/nl.avisi.confluence.plugins.numberedheadings/server/overview) for that?

Can you share the storage format of an example page?

Best,  
Nils

comments: author: Debbi Sedlak
body: No, cannot use that macro. we cannot buy anything right now, although I wish I knew how to create that. Even free plug-ins that are not from Atlassian have to go through rigorous review. I am using a space style sheet. Is there a way to embed a style sheet in a document that would export, rather than by space? I may want to post that as a separate question.


author: Debbi Sedlak
body: See update to my question above


author: Nils Bier _K15t_
body: Hi Debbi,

Thanks for the update - using stylesheets you're changing the way the content is displayed, but this information is not stored in the storage format which is used for the export.

You'd need to find a way to get the numbers inserted in the storage format (e.g. using a macro), or change the [PDF stylesheet](https://confluence.atlassian.com/doc/customize-exports-to-pdf-190480945.html).

An easier way (allowing you to have multiple templates per space or globally and giving you more enhanced customization options) would be to have a look at our [Scroll PDF Exporter](https://marketplace.atlassian.com/plugins/com.k15t.scroll.scroll-pdf/server/overview) - but if you can't get any apps right now, you might need to check the PDF stylesheet options.


author: Debbi Sedlak
body: I copied the css stylesheet used for Confluence to the PDF stylesheet, but it is not working.

This is what I have:

body {  
counter-reset: h1-counter;  
font-style: normal;  
font-variant: normal;  
font-family: Calibri, Candara, Segoe, "Segoe UI", Optima, Arial, sans-serif;  
}  
#main-content h1:before {  
content: counter(h1-counter) " ";  
counter-increment: h1-counter;  
}  
#main-content h1 {  
font-size: 24px;  
font-weight: 500;  
line-height: 26.4px;  
counter-reset: h2-counter;  
}  
#main-content h2:before {  
content: counter(h1-counter) "." counter(h2-counter) " ";  
counter-increment: h2-counter;  
}  
#main-content h2 {  
font-size: 22px;  
font-weight: 500;  
line-height: 24px;  
counter-reset: h3-counter;  
}  
#main-content h3:before {  
content: counter(h1-counter) "." counter(h2-counter) "." counter(h3-counter) " ";  
counter-increment: h3-counter;  
}  
#main-content h3 {  
font-size: 20px;  
font-weight: 500;  
line-height: 22px;  
counter-reset: h4-counter;  
}  
#main-content h4:before {  
content: counter(h1-counter) "." counter(h2-counter) "." counter(h3-counter) "." counter(h4-counter) " ";  
counter-increment: h4-counter;  
}  
#main-content h4 {  
font-size: 18px;  
font-weight: 500;  
line-height: 20px;  
counter-reset: h5-counter;  
}  
#main-content h5:before {  
content: counter(h1-counter) "." counter(h2-counter) "." counter(h3-counter) "." counter(h4-counter) "." counter(h5-counter) " ";  
counter-increment: h5-counter;  
}  
#main-content h5 {  
font-size: 16px;  
font-weight: 400;  
line-height: 18px;  
counter-reset: h6-counter;  
}  
#main-content h6:before {  
content: counter(h1-counter) "." counter(h2-counter) "." counter(h3-counter) "." counter(h4-counter) "." counter(h5-counter) "." counter(h6-counter) " ";  
counter-increment: h6-counter;  
}  
#main-content h6 {  
font-size: 14px;  
font-weight: 300;  
line-height: 16px;  
}  
#main-content p {  
font-size: 14px;  
font-weight: 400;  
line-height: 20px;  
}  
#main-content blockquote {  
font-size: 21px;  
font-weight: 400;  
line-height: 30px;  
}  
#main-content pre {  
font-size: 13px;  
font-weight: 400;  
line-height: 18.5714px;  
}  
.mceContentBody h1:before {  
content: counter(h1-counter) " ";  
counter-increment: h1-counter;  
}  
.mceContentBody h1 {  
font-size: 24px;  
font-weight: 500;  
line-height: 26.4px;  
counter-reset: h2-counter;  
}  
.mceContentBody h2:before {  
content: counter(h1-counter) "." counter(h2-counter) " ";  
counter-increment: h2-counter;  
}  
.mceContentBody h2 {  
font-size: 20px;  
font-weight: 500;  
line-height: 20px;  
counter-reset: h3-counter;  
}  
.mceContentBody h3:before {  
content: counter(h1-counter) "." counter(h2-counter) "." counter(h3-counter) " ";  
counter-increment: h3-counter;  
}  
.mceContentBody h3 {  
font-size: 14px;  
font-weight: 500;  
line-height: 15.4px;  
counter-reset: h4-counter;  
}  
.mceContentBody h4:before {  
content: counter(h1-counter) "." counter(h2-counter) "." counter(h3-counter) "." counter(h4-counter) " ";  
counter-increment: h4-counter;  
}  
.mceContentBody h4 {  
font-size: 12px;  
font-weight: 500;  
line-height: 12px;  
counter-reset: h5-counter;  
}  
.mceContentBody h5:before {  
content: counter(h1-counter) "." counter(h2-counter) "." counter(h3-counter) "." counter(h4-counter) "." counter(h5-counter) " ";  
counter-increment: h5-counter;  
}  
.mceContentBody h5 {  
font-size: 12px;  
font-weight: 400;  
line-height: 12px;  
counter-reset: h6-counter;  
}  
.mceContentBody h6:before {  
content: counter(h1-counter) "." counter(h2-counter) "." counter(h3-counter) "." counter(h4-counter) "." counter(h5-counter) "." counter(h6-counter) " ";  
counter-increment: h6-counter;  
}  
.mceContentBody h6 {  
font-size: 10px;  
font-weight: 300;  
line-height: 12px;  
}


author: Dave Theodore [Coyote Creek Consulting]
body: Will the [Table of Contents](https://confluence.atlassian.com/confcloud/table-of-contents-macro-724765294.html) macro work for you? It provides clickable links and anchors in exported PDFs.

comments: author: Debbi Sedlak
body: No, need numbered sections


Tags: export

numbered-heading

pdf