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

Header and Footer phrase is no longer being rendered #781

Closed
vstokesjr opened this issue Jul 12, 2022 · 6 comments · Fixed by #813
Closed

Header and Footer phrase is no longer being rendered #781

vstokesjr opened this issue Jul 12, 2022 · 6 comments · Fixed by #813
Labels
Milestone

Comments

@vstokesjr
Copy link

vstokesjr commented Jul 12, 2022

Describe the bug
The document header and footer are no longer being rendered in version 1.3.29 when solely set with Phrase(). However, if you change the "numbered" option to TRUE then the header and footer are rendered but only with the page number. The supplied Phrase() is not being rendered.

To Reproduce
Document document = new Document( PageSize.Letter );
PdfWriter.getInstance( document, new FileOutputStream( "/tmp/output.pdf" ) );

/* Set document properties */
document.addAuthor( "Author" );
document.addCreator( this.getClass().getSimpleName() );
document.addCreationDate();
document.addKeywords( "some,key,words" );
document.addSubject( "Subject" );
document.addTitle( "Title" );
document.setDocumentLanguage( "ENG" );

/* Header */
Font headerFont = FontFactory.getFont( FontFactory.COURIER );
headerFont.setSize( 16.0f );
headerFont.setStyle( Font.BOLD );
HeaderFooter header = new HeaderFooter(new Phrase( "This is a header.", headerFont ), false );
header.setAlignment( Element.ALIGN_CENTER );
header.setBorder( Rectangle.NO_BORDER );
document.setHeader( header );

/* Footer */
Font footerFont = FontFactory.getFont( FontFactory.COURIER );
footerFont.setSize( 8.0f );
HeaderFooter footer = new HeaderFooter( new Phrase( "This is a footer.", footerFont ), false ); // does not render anything
// HeaderFooter footer = new HeaderFooter( new Phrase( "This is a footer.", footerFont ), true ); // only page# rendered
footer.setAlignment( Element.ALIGN_CENTER );
footer.setBorder( Rectangle.NO_BORDER );
document.setFooter( footer );

document.open();

/* Body */
Font bodyFont = FontFactory.getFont( FontFactory.COURIER );
bodyFont.setSize( 12.0f );

document.add( new Paragraph( "Hello World", bodyFont ) );
document.add( Chunk.NEXTPAGE );
document.add( new Paragraph("Hello new page.", bodyFont ) );

/* Close */
document.close();

Expected behavior
Header and footer phrase should also render.

Screenshots

System (please complete the following information):

  • OS: Linux Ubuntu 20.04.4 LTS
  • Used Font: COURIER (and also tried HELVETICA)
  • OpenPDF Version: 1.3.29 (via Maven)
  • Java Version: openjdk 17.0.3 2022-04-19 (amd64)
  • IDE: IntelliJ IDEA 2022.1.3 Ultimate

Additional context

@vstokesjr vstokesjr added the bug label Jul 12, 2022
@vstokesjr
Copy link
Author

vstokesjr commented Jul 12, 2022

I forgot to mention that if I revert back to OpenPDF Version: 1.3.28 (via Maven) then the header/footer work properly.

@gnahraf
Copy link

gnahraf commented Aug 19, 2022

can confirm same behavior on macOS (12.1) with openjdk 17.0.1; also works here w/ version 1.3.28

@renoth
Copy link

renoth commented Sep 9, 2022

this is most likely due to this commit ea9e5c6
it removes the only content from header and footer
I have the same problem as the original reporter.

@renoth
Copy link

renoth commented Sep 9, 2022

Workaround: wrap the Phrase of the Header/Footer in a Paragraph
image

@renoth
Copy link

renoth commented Sep 9, 2022

The reason seems to be that this was tested with a Paragraph as header content, when adding a paragraph to the header a newline Chunk is created that needs to be removed afterwards.
This code will not work with a naked Phrase though, although the API does suggest otherwise.
image

@asturio
Copy link
Member

asturio commented Sep 13, 2022

Pull requests are welcome.

renoth pushed a commit to renoth/OpenPDF that referenced this issue Sep 14, 2022
- fis wrong deletion of Chunk in Phrase in HeaderFooter
- added Test for HeaderFooter#paragraph
renoth pushed a commit to renoth/OpenPDF that referenced this issue Sep 14, 2022
- formatting
@asturio asturio linked a pull request Sep 14, 2022 that will close this issue
1 task
@asturio asturio added this to the 1.3.30 milestone Sep 14, 2022
asturio pushed a commit that referenced this issue Sep 14, 2022
- fis wrong deletion of Chunk in Phrase in HeaderFooter
- added Test for HeaderFooter#paragraph
asturio pushed a commit that referenced this issue Sep 14, 2022
- formatting
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants