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

White page added with @page named #233

Closed
Zefling opened this issue Jun 22, 2018 · 2 comments
Closed

White page added with @page named #233

Zefling opened this issue Jun 22, 2018 · 2 comments

Comments

@Zefling
Copy link

Zefling commented Jun 22, 2018

In this case, a blank page is added before the first styled page:

<html>
<head>
<style>
/* The following fonts are installed on the server: */
.handwriting {
  font-family: 'handwriting', serif;
}
.arabic {
  font-family: 'arabic', serif;
}
.deja {
  /* Contains glyphs for many languages. */
  font-family: 'deja-sans', sans-serif;
}
/*
Also you can use the PDF built-in fonts: 
 - sans-serif
 - serif
 - monospace
*/

@page test {
  size: A4;
  margin: 3.5cm 1.5cm 2.5cm 1.5cm;
}
.pagetest{ 
  page : test 
}

</style>
</head>
<body>
<div class="pagetest">
<div class="handwriting" style="text-align:center;font-size: 90px;color:orange;">
Hello World!
</div>
</div>
</body>
</html>

I tested several cases, the first page is necessarily @page unnamed.For generated content (for example, with mustache) where the first page would be present or not, it really complicated the implementation.

@danfickle
Copy link
Owner

Hi @Zefling,

I hope this is better late than never. After looking at the code, it turns out there is logic to avoid this situation:

            if (page.getTop() == getAbsY()) {
                pageBreakCount--;
                if (pendingPageName && page == c.getRootLayer().getLastPage()) {
                    c.getRootLayer().removeLastPage();
                    c.setPageName(c.getPendingPageName());
                    c.getRootLayer().addPage(c);
                }
            }

Basically, it says that if we are at the top of a page when we encounter a named page, remove the current page and replace it with the named page. Unfortunately, by default, the body has a top margin so we are not at the top of the page when we start the first element. We can fix this with:

body {
  margin-top: 0;
}

This removes the empty first page. I think the workaround is simple enough that we can mark this issue as closed. I'll add a reference to this issue from the wiki.

@Zefling
Copy link
Author

Zefling commented Mar 2, 2019

Thanks for this simple solution, we had found a much more complicated workaround.

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

No branches or pull requests

2 participants