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

fix: Make it possible to alternate content of header/footer for even/odd pages #340

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,51 @@ In case if both of them specified 'existing_wi_id' has higher priority.
(Style package, Stylesheets) there's no `Quick Help` section as their content is self-evident.
4. To change configuration of PDF Exporter extension just edit corresponding section and press `Save` button.

### CSS for booklet layout

If you export PDF to be printed as a booklet, then you may need to alternate blocks in header/footer depending on the fact if it's even or odd page.
This can be achieved (since version 8.1.0) by CSS modification. Let us give you an example. Find following definition in standard CSS of the extension:

```
@page :left {
@top-left {
content: element(top-left);
}
@top-right {
content: element(top-right);
}
@bottom-left {
content: element(bottom-left);
}
@bottom-right {
content: element(bottom-right);
}
}
```

...and replace it by this code:

```
@page :left {
@top-left {
content: element(top-right);
}
@top-right {
content: element(top-left);
}
@bottom-left {
content: element(bottom-right);
}
@bottom-right {
content: element(bottom-left);
}
}
```

As a result blocks in header and footer which in normal case are displayed at right side of the header/footer will be displayed at left side and vice versa.
This is only an example to illustrate an idea, if your use case is different feel free to modify this code according to your requirements.


## Usage

1. Open a document in Polarion.
Expand Down
82 changes: 42 additions & 40 deletions src/main/resources/default/dle-pdf-export.css
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,8 @@ th {
border: none;
}

.footer {
margin-top: 10px;
margin-bottom: 50px;
.header .top-center, .footer .bottom-center {
text-align: center;
}

.page-number .number::after {
Expand Down Expand Up @@ -140,29 +139,47 @@ ul.toc li > a.page-number::after {
@page {
margin: 120px 60px 90px 80px;
border-bottom: 1px solid #aaa;
@top-left {
content: element(top-left);
display: none;
}
@top-center {
content: element(top-center);
width: 100%;
width: 50%;
}
@bottom-center {
content: element(bottom-center);
width: 50%;
}
}

@page :left {
@top-left {
content: element(top-left);
}
@top-right {
content: element(top-right);
display: none;
}
@bottom-left {
content: element(bottom-left);
display: none;
}
@bottom-center {
content: element(bottom-center);
width: 100%;
@bottom-right {
content: element(bottom-right);
}
}

@page :right {
@top-left {
content: element(top-left);
text-align: left;
}
@top-right {
content: element(top-right);
text-align: right;
}
@bottom-left {
content: element(bottom-left);
text-align: left;
}
@bottom-right {
content: element(bottom-right);
display: none;
text-align: right;
}
}

Expand Down Expand Up @@ -306,31 +323,34 @@ ul.toc li > a.page-number::after {
}

.header, .footer {
display: inline-block;
display: block;
}

.header.top-left {
.header .top-left {
position: running(top-left);
}

.header.top-center {
.header .top-center {
position: running(top-center);
}

.header.top-right {
.header .top-right {
position: running(top-right);
}

.footer.bottom-left {
.footer .bottom-left {
position: running(bottom-left);
margin-bottom: 40px;
}

.footer.bottom-center {
.footer .bottom-center {
position: running(bottom-center);
margin-bottom: 40px;
}

.footer.bottom-right {
.footer .bottom-right {
position: running(bottom-right);
margin-bottom: 40px;
}

h1 {
Expand Down Expand Up @@ -868,24 +888,6 @@ li span {
line-height: 1em !important;
}

.header-footer-wrapper {
display: flex;
}

.header-footer-left {
flex: 1;
}

.header-footer-center {
max-width: 30%;
text-align: center;
}

.header-footer-right {
flex: 1;
text-align: right;
}

.comment {
background: #eee;
border-left: 5px solid #aaa;
Expand Down Expand Up @@ -971,4 +973,4 @@ table.polarion-rp-column-layout td {
}
.polarion-TestRunOverviewWidget-buttonName {
padding-top: 20px;
}
}
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
<div class='header top-center header-footer-wrapper'>
<div class='header-footer-left'>
<div class='header'>
<div class='top-left'>
%s
</div>
<div class='header-footer-center'>
<div class='top-center'>
%s
</div>
<div class='header-footer-right'>
<div class='top-right'>
%s
</div>
</div>
<div class='footer bottom-center header-footer-wrapper'>
<div class='header-footer-left'>
<div class='footer'>
<div class='bottom-left'>
%s
</div>
<div class='header-footer-center'>
<div class='bottom-center'>
%s
</div>
<div class='header-footer-right'>
<div class='bottom-right'>
%s
</div>
</div>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -195,25 +195,25 @@ void shouldGetAndProcessHeaderFooterContent(String settingName, String settingAr

// Assert
assertThat(TestStringUtils.removeNonsensicalSymbols(headerFooterContent)).isEqualTo(TestStringUtils.removeNonsensicalSymbols("""
<div class='header top-center header-footer-wrapper'>
<div class='header-footer-left'>
<div class='header'>
<div class='top-left'>
-xheader-left-
</div>
<div class='header-footer-center'>
<div class='top-center'>
-xheader-center-
</div>
<div class='header-footer-right'>
<div class='top-right'>
-xheader-right-
</div>
</div>
<div class='footer bottom-center header-footer-wrapper'>
<div class='header-footer-left'>
<div class='footer'>
<div class='bottom-left'>
-xfooter-left-
</div>
<div class='header-footer-center'>
<div class='bottom-center'>
-xfooter-center-
</div>
<div class='header-footer-right'>
<div class='bottom-right'>
-xfooter-right-
</div>
</div>""".indent(0).trim()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ void prepareTestMocks() {

headerFooterSettings = mock(HeaderFooterSettings.class);
//here we will test "testFieldKey" custom field & special "PAGE_NUMBER" placeholder substitution in the header
when(headerFooterSettings.load(any(), any())).thenReturn(new HeaderFooterModel("HL", "HC {{ testFieldKey }}", "HR", "FL", "FC", "FR {{ PAGE_NUMBER }}"));
when(headerFooterSettings.load(any(), any())).thenReturn(new HeaderFooterModel("HL", "HC {{ testFieldKey }}", "HR", "FL", "FC", "FR_{{ PAGE_NUMBER }}"));

String basicCss = readCssResource(CSS_BASIC, FONT_REGULAR);
CssSettings cssSettings = mock(CssSettings.class);
Expand Down Expand Up @@ -275,7 +275,7 @@ void testConverterWiki() {
.revisionPlaceholder("42")
.build();
documentDataFactoryMockedStatic.when(() -> DocumentDataFactory.getDocumentData(eq(params), anyBoolean())).thenReturn(wikiPage);
when(headerFooterSettings.load(any(), any())).thenReturn(new HeaderFooterModel("HL", "HC {{ REVISION }}", "HR", "FL", "FC", "FR {{ PAGE_NUMBER }}"));
when(headerFooterSettings.load(any(), any())).thenReturn(new HeaderFooterModel("HL", "HC {{ REVISION }}", "HR", "FL", "FC", "FR_{{ PAGE_NUMBER }}"));
params.setDocumentType(DocumentType.WIKI_PAGE);
params.setLocationPath("wikiFolder/wikiPage");

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/test/resources/weasyprint/png/testConverterWiki_page_0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading