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

Force addPage() to start on odd or even page number #1763

Open
xErik opened this issue Oct 13, 2024 · 2 comments
Open

Force addPage() to start on odd or even page number #1763

xErik opened this issue Oct 13, 2024 · 2 comments
Labels
enhancement New feature or request needs triage

Comments

@xErik
Copy link

xErik commented Oct 13, 2024

Is your feature request related to a problem? Please describe.

Consider a book where:

  1. A chapter title page is on an odd page (right hand side)
  2. Followed by a blank page (left hand side)
  3. Followed by text on an odd page (right hand side)

addPage() does not allow to force the start of the chapter page to the next odd page number.

Describe the solution you'd like

enum PageNumber { odd, even }

addPage(  startNext: PageNumber.odd )

Here, addPage injects blank pages as needed to achieve the desired effect.

Describe alternatives you've considered

I tried to get the current page count before inserting a new page. But the document hasn't been rendered yet. Thus, the actual page count is not accessible. And whether an additionally injected blank page is needed cannot be determined at coding time.

I may have overlooked an obvious solution to this problem, or an already existing API parameter.

@xErik xErik added enhancement New feature or request needs triage labels Oct 13, 2024
@xErik
Copy link
Author

xErik commented Oct 14, 2024

I found out how to get the current page count.

I'll leave this feature request open, as I am not sure if this new feature is still a good idea or not.

This code will inject an empty page and push the next page with content to an odd page (right hand):

final pageCount = doc.document.pdfPageList.pages.length;
final isNextEven = (pageCount + 1) % 2 == 0;

if (isNextEven) {
  doc.addPage(
    pw.Page(
      pageFormat: format.copyWith(marginBottom: 1.5 * PdfPageFormat.cm),
      orientation: pw.PageOrientation.portrait,
      build: (context) => pw.NewPage(),
    ),
  );

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request needs triage
Projects
None yet
Development

No branches or pull requests

2 participants
@xErik and others