Knowledge Base – Qoppa Java PDF Library SDK / Server Products

Add a header image logo to an existing PDF

/Java PDF Library [Deriving from jPDFProcess] / jPDFProcess: Create/Manipulate PDFs / Add a header image logo to an existing PDF
  • November 14, 2017
  • jPDFProcess: Create/Manipulate PDFs

Here is a sample java program showing how to open a PDF, add a company logo image at the top of each page, then save the document using Qoppa’s PDF library jPDFProcess.

 // Load document
PDFDocument pdfDoc = new PDFDocument ("C:\\myfolder\\input.pdf", null);
 
// Load foreground image
BufferedImage logoImage = ImageIO.read(new File("C:\\myfolder\\logo.jpg"));
 
for (int i=0; i< pdfDoc.getPageCount(); i++)
{
   // get current page
   PDFPage currentPage = pdfDoc.getPage(i);
   // add image logo on top
   currentPage.drawImage(logoImage, 0, 0, null, null, new ImageCompression(ImageCompression.COMPRESSION_DEFLATE, 1.0f));
}
 
// Save the PDF
pdfDoc.saveDocument ("C:\\myfolder\\output.pdf");

// Load document PDFDocument pdfDoc = new PDFDocument ("C:\\myfolder\\input.pdf", null); // Load foreground image BufferedImage logoImage = ImageIO.read(new File("C:\\myfolder\\logo.jpg")); for (int i=0; i< pdfDoc.getPageCount(); i++) { // get current page PDFPage currentPage = pdfDoc.getPage(i); // add image logo on top currentPage.drawImage(logoImage, 0, 0, null, null, new ImageCompression(ImageCompression.COMPRESSION_DEFLATE, 1.0f)); } // Save the PDF pdfDoc.saveDocument ("C:\\myfolder\\output.pdf");

Download Full Java Sample Code

You may need to first resize pages of the PDF and shift their content down before adding a new logo.

Suggested Articles

  • Adding a background or foreground image to a PDF page

  • How to resize pages in a PDF document with Java library jPDFProcess

Tagged: add imagelogo

Related Articles

  • Setting Highlight Mode for Link Annotations on a PDF Page

  • Change Text Content Color in a PDF Document

  • Create a Link in a PDF with Launch Action and Window Open Preference

  • Add a multi-line text rubber stamp to a PDF with dynamic date

  • Sign a PDF document with Java & Azure

  • Sign a PDF document with 2 digital signatures

Recent Articles

  • v2020R2 jPDFPreflight Build Notes
  • v2021R1 jPDFWriter Build Notes
  • v2020R3 PDF Automation Server Release Notes
  • v2020R2 jPDFWeb Build Notes
  • How can I add Qoppa Java PDF API as a Maven dependency?
  • How to check that a PDF document is linearized or formatted for fast web view

Popular Articles

  • Free Java PDF library alternative to iText
  • Apply Digital Signature on a PDF document using USB hardware token PKCS 11
  • Java PDF OCR library sdk
  • How to resize pages in a PDF document with Java library jPDFProcess
  • Sample Java code to convert Excel to PDF using jOfficeConvert
  • Code Sample: Convert PDF to Tiff in Java
  • Code Sample: Extract form field data programmatically from a PDF form in Java
  • Java library to verify PDF/A compliance and convert PDFs to PDF/A
  • Sample Signed PDF with Digital Signature from a Java Recognized Certificate Authority
  • Understanding how a zero footprint HTML5 PDF viewer works

Categories

  • FAQ
  • Java PDF Library [Deriving from jPDFProcess]
    • jPDF Library Release History
    • jPDFAssemble: Merge PDFs, Split PDFs
    • jPDFFields: Import, Export Form Fields
    • jPDFImages: Convert PDF To From Images
    • jPDFPrint: Print PDFs
    • jPDFProcess: Create/Manipulate PDFs
    • jPDFSecure: Secure / Sign PDFs
    • jPDFText: Extract Text From PDFs
  • Java PDF Library [Other]
    • jPDFOptimizer: Optimize PDFs, Reduce PDF Files Size
      • jPDFOptimizer Release History
    • jPDFPreflight: Validate Convert PDF/A, PDF/X
      • jPDFPreflight Release History
    • jOfficeConvert: Convert MS Word To PDF, Convert Excel to PDF
      • jOfficeConvert Release History
    • jPDFWeb: Convert PDF To HTML5
      • jPDFWeb Release History
    • FREE jPDFWriter: Write / Create PDFs
  • Java PDF Visual Component
    • jPDF Component Release History
    • jPDFNotes: PDF Annotating Component
    • jPDFEditor: PDF Editing Component
    • jPDFViewer: PDF Viewing Component
  • PDF Automation Server
    • PAS Release History
    • Web PDF Viewer & Markup
    • Mule ESB
    • Custom PDF Jobs
    • Rest API
  • Android PDF Toolkit – qPDF
    • qPDF Toolkit Release History
  • Evaluation
  • Fonts
  • Integration
  • Licensing
  • General
  • Webstart Applications / Applets – Render, Print, Manipulate PDFs
  • Videos
  • Java
  • Developer Newsletter
  • Command Line Tools
  • Qoppa News
  • Archive
  • Uncategorized

See our PDF technology in action!

By trying our end-user tools below:
Try PDF Studio
Try Android qPDF Notes

Links to Qoppa’s Main Website

Java PDF SDK / API
PDF Viewing Component
PDF Studio for Mac, Windows, Linux
Android PDF Tools
PDF Automation Server

Contact Support

Click to email If you do not find the answer to your question, email us .

Follow Us

Blog   Twitter   Twitter   LinkedIn
© Copyright, Qoppa Software - Reliable PDF Software for End-Users and Developers