Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

PDF export with both portrait and landscape format pages

Jerry Yen
Contributor
November 8, 2023

Hello Everyone,

I was able to set my PDF export to landscape format by adding the following to PDF stylesheet:

@page
{
/*A4-sized pages in landscape orientation are 297 mm wide by 210 mm long*/
size: 297mm 210mm;
}

 

However, the first couple pages are better presented in portrait format.  So my question, is it possible to specify first x number of pages in portrait then everything else in landscape after?

1 answer

0 votes
Kseniia Trushnikova
Community Champion
November 9, 2023

Hi @Jerry Yen,

For @page, there is only a pseudo-class defined for the title page. You can use @page :first for the first page and @page for the second page and beyond:

@page 
{
size: A4 landscape;
}

@page :first
{
size: A4 portrait;
}

Looks like :nth-child(n) doesn't work with @page.

Jerry Yen
Contributor
November 9, 2023

Thank you.  If I need the first 2 pages to be in portrait mode then page 3+ to be in landscape, is there a way to do this?

Kseniia Trushnikova
Community Champion
November 9, 2023

@Jerry Yen, I don't think it's possible. You can only define different style for the first title page.

Jerry Yen
Contributor
November 9, 2023

Is there no option to use page breaks then "named pages" in Confluence?

https://drafts.csswg.org/css-page-3/#using-named-pages

Kseniia Trushnikova
Community Champion
November 9, 2023

@Jerry Yen, you can add a custom class to your page and define styles for it. Try this:

  1. Open the page in the Confluence Source Editor, please refer to https://confluence.atlassian.com/doc/confluence-storage-format-790796544.html 
  2. Wrap the content you want to be in the portrait layout with the tag <div class="customPortraitLayout">...</div> and update the page.
  3. Add this on the PDF Stylesheet tab:
@page Portrait 
{
size: A4 portrait;
}

.customPortraitLayout
{
page: Portrait;
}

I tested this and it worked for me, but please be aware that it has not been thoroughly tested and you use it at your own risk. This solution only applies to pages where you add the class manually.

Like Jerry Yen likes this

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events