Skip to content

Conversation

@the-officialjosh
Copy link

This pull request enhances the header and footer functionality in the OpenPDF library, focusing on supporting non-text elements (such as images and tables) in footers, and improving layout flexibility. The changes introduce new APIs and internal mechanisms to manage special content in headers/footers, update how padding is handled, and ensure correct rendering and spacing for these elements. Additionally, there are minor code cleanups and refactorings for better readability.

Header/Footer Special Content and Layout Enhancements:

  • Added support for non-text elements (e.g., images and tables) in footers via a new specialContent list and related methods in the HeaderFooter class (addSpecialContent, getSpecialContent). This enables images and tables to be queued and rendered as part of the footer. [1] [2]
  • Introduced padding management for headers/footers, including getter/setter and an addPadding method to accumulate space requirements for special content. [1] [2]
  • Implemented flushSpecial in PdfDocument to render non-text footer content (images and tables) at the correct position, handling alignment and spacing.
  • Added addDelay and delayTableAddition methods in PdfDocument to defer placement of images and tables until the footer is rendered, ensuring correct layout and spacing.
  • Added a ruy (relative upper y-coordinate) property to Rectangle and related getter/setter to help position special content relative to the footer. [1] [2]

Footer Rendering and Document Flow Adjustments:

  • Updated the main document element addition logic to check if the document is in the process of rendering the footer (isDoFooter flag). If so, images and tables are delayed and added to the footer's special content instead of being rendered immediately. [1] [2]
  • Improved the paragraph() method in HeaderFooter to prevent unwanted newlines when adding a Paragraph to another Paragraph, ensuring clean header/footer text rendering.

Internal Refactoring and Code Quality:

  • Extracted table width calculation into a dedicated setTableWidth method for reuse and clarity.
  • Minor variable initialization and cleanup for clarity in PdfDocument (e.g., initialization of hScale and scolor). [1] [2]
  • Improved JavaDoc comments and formatting in HeaderFooter for better code readability and maintainability. [1] [2] [3] [4] [5] [6] [7] [8] [9] [10]

These changes collectively enable more complex and visually rich headers and footers, particularly for use cases that require images or tables in page footers.## Description of the new Feature/Bugfix

Describe here how you fixed the bug, or implemented the new feature.

Related Issue: #

Unit-Tests for the new Feature/Bugfix

  • Unit-Tests added to reproduce the bug
  • Unit-Tests added to the added feature

Compatibilities Issues

Is anything broken because of the new code? Any changes in method signatures?

Your real name

Please specify your full name here, so that we can verify your identity.
If you have a conflict of interest describe this here also.

Testing details

Any other details about how to test the new feature or bugfix?

@sonarqubecloud
Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
C Maintainability Rating on New Code (required ≥ A)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

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

Successfully merging this pull request may close these issues.

1 participant