Retain Header Text in PPT PPTX Files | Convert Word & Image JPEG PNG TIFF Files to PDF using Java | JAI

Hi,

I am trying to insert header footer in ppt and than convert to pdf.

here is my code :-

private static void generatePDFFromPPT(String filename, String extension)  {

    Presentation presentation  = new Presentation(filename + extension);

    presentation.getHeaderFooterManager().setAllHeadersVisibility(true);

    presentation.getHeaderFooterManager().setAllFootersVisibility(true);

    presentation.getHeaderFooterManager().setAllHeadersText("HEADER TEXT");

    presentation.getHeaderFooterManager().setAllFootersText("FOOTER TEXT");

    presentation.save(filename + ".pdf", SaveFormat.Pdf);

}

Footer Text shows but Header Text doesnt show in the converted pdf.

I am evaluating the product, need help to fix this.

Thanks

@mnitin

There are no headers in default presentation view that you are using on your end in PowerPoint. The headers in PowerPoint are only available in NotesView of presentation. Even, if you set the header text using HeaderFooter manager class, it will not appear. I suggest you to please try using following sample code to observe headers in notes view.

private static void generatePDFFromPPT(String filename, String extension)  
{

    filename="C:\\Aspose Data\\TestText";
    Presentation presentation  = new Presentation(filename+".pptx");

    //Add empty slide in the end
    presentation.getSlides().addEmptySlide(presentation.getLayoutSlides().getByType((byte)SlideLayoutType.Blank));

    presentation.getHeaderFooterManager().setAllHeadersVisibility(true);

    presentation.getHeaderFooterManager().setAllFootersVisibility(true);

    presentation.getHeaderFooterManager().setAllHeadersText("HEADER TEXT");

    presentation.getHeaderFooterManager().setAllFootersText("FOOTER TEXT");

    PdfOptions opts=new PdfOptions();
    opts.getNotesCommentsLayouting().setNotesPosition(NotesPositions.BottomFull);

    presentation.save(filename + ".pdf", SaveFormat.Pdf,opts);

}

TestText.zip (47.2 KB)

Thanks Mudassir!!

One more help. I have doc, docx, ppt, pptx , jpeg and png formats to:-

  1. Convert to PDF (I have done using the sample code)
  2. Add header and footer
  3. Add extra page at the end of the page

Your help would be really appriciated

Thanks

@mnitin,

The code sample that has been shared in my last post is applicable to both PPT and PPTX file. I have also added provision to add empty slide (empty page) at the end of generated PDF as well.

Can you please explain your requirement about JPEG and PNG formats too? What type of output you are looking for that. I am right, you want to export a JPEG or PNG image to PDF. If that is so, you can add image to blank presentation object with full slide size and export the presentation to PDF. You can please refer to this documentation link for inserting a JPEG or PNG image in slide and then export that to PDF to serve the purpose.

For your requirements, related to DOC and DOCX, we will share feedback with you shortly.

Thanks for your reply.

I want to convert jpg and png to pdf, add and extra page at the end and add header/footer

Thanks

@mnitin,

To convert a document (DOC, DOCX, RTF, ODT etc) to PDF, simply invoke the Document.Save method and specify a file name with the “.PDF” extension. The following Java code converts a whole document from DOC to PDF using default options:

Document doc = new Document("Template.doc");
doc.save(output.pdf);

You can convert Image files such as JPEG, TIFF, PNG etc to PDF by using Aspose.Words for Java API alone. Please also refer to the ‘Additional Dependencies’ section of System Requirements page. For example:

To add or remove headers footers in Word document, please refer to the following article:

Also, you can simply insert a Page Break to simulate addition of an extra empty page at the end of document.

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.writeln("I am on first page");

// inserting a page break will add an empty page at the end
builder.moveToDocumentEnd();
builder.insertBreak(BreakType.PAGE_BREAK);

doc.save("E:\\Temp\\awjava-20.6.docx");
doc.save("E:\\Temp\\awjava-20.6.pdf");