Class OpenPdfRenderer

java.lang.Object
org.europa.together.application.OpenPdfRenderer
All Implemented Interfaces:
PdfRenderer

@Repository public class OpenPdfRenderer extends Object implements PdfRenderer
Implementation of a simple PDF Renderer.
https://knpcode.com/java-programs/generating-pdf-java-using-openpdf-tutorial/#HelloWorldOpenPDF
  • Constructor Details

    • OpenPdfRenderer

      public OpenPdfRenderer()
  • Method Details

    • loadDocument

      public PdfDocument loadDocument(File pdfDocument) throws IOException
      Description copied from interface: PdfRenderer
      Read a PDF from FILE as PdfReader.
      Specified by:
      loadDocument in interface PdfRenderer
      Parameters:
      pdfDocument - as File
      Returns:
      pdf as PdfReader
      Throws:
      IOException - case of error
    • writeDocument

      public void writeDocument(PdfDocument pdf, String destination) throws IOException, FileNotFoundException
      Description copied from interface: PdfRenderer
      Writes a PDF document (PdfReader) to the given destination.
      Specified by:
      writeDocument in interface PdfRenderer
      Parameters:
      pdf - as PdfReader
      destination - as String
      Throws:
      IOException - case of error
      FileNotFoundException - case of error
    • removePage

      public PdfDocument removePage(PdfDocument pdf, int... pages) throws IOException
      Description copied from interface: PdfRenderer
      Remove from a given PDF pages. Usage:
      PdfReader pdf = readDocument(new File(document.pdf)); File newPdf = removePages(pdf, 2, 4, 12);
      Removes from the PDF document the pages: 2,4 and 12.
      Specified by:
      removePage in interface PdfRenderer
      Parameters:
      pdf - as PdfReader
      pages - as int
      Returns:
      pdf as PdfReader
      Throws:
      IOException - case of error
    • renderDocumentFromHtml

      public void renderDocumentFromHtml(String file, String template) throws FileNotFoundException, IOException
      Description copied from interface: PdfRenderer
      Generate a PDF document in the size A4 from a HTML String. The file parameter define the path were the PDF will sored an how the document is named.
      Specified by:
      renderDocumentFromHtml in interface PdfRenderer
      Parameters:
      file - as String
      template - as String
      Throws:
      FileNotFoundException - case of error
      IOException
    • setAuthor

      public void setAuthor(String author)
      Description copied from interface: PdfRenderer
      Set the author for the document.
      Specified by:
      setAuthor in interface PdfRenderer
      Parameters:
      author - as String
    • setKeywords

      public void setKeywords(String keywords)
      Description copied from interface: PdfRenderer
      Set hte keywords for the document.
      Specified by:
      setKeywords in interface PdfRenderer
      Parameters:
      keywords - as String
    • setSubject

      public void setSubject(String subject)
      Description copied from interface: PdfRenderer
      Set the document subject.
      Specified by:
      setSubject in interface PdfRenderer
      Parameters:
      subject - as String
    • setTitle

      public void setTitle(String title)
      Description copied from interface: PdfRenderer
      Set the document title.
      Specified by:
      setTitle in interface PdfRenderer
      Parameters:
      title - as String
    • setFormat

      public void setFormat(String format)
      Description copied from interface: PdfRenderer
      Change the default papersize format fom A4 to a cutom value.
      (width / height) size: 21cm 29.7cm; margin: 20mm 20mm;
      Specified by:
      setFormat in interface PdfRenderer
      Parameters:
      format - as String
    • getAuthor

      public String getAuthor()
      Description copied from interface: PdfRenderer
      Get the author of the document.
      Specified by:
      getAuthor in interface PdfRenderer
      Returns:
      author as String
    • getKeywords

      public String getKeywords()
      Description copied from interface: PdfRenderer
      Get the document related keywords.
      Specified by:
      getKeywords in interface PdfRenderer
      Returns:
      keywords as String
    • getSubject

      public String getSubject()
      Description copied from interface: PdfRenderer
      Get the document subject.
      Specified by:
      getSubject in interface PdfRenderer
      Returns:
      subject as String
    • getTitle

      public String getTitle()
      Description copied from interface: PdfRenderer
      Get the document title.
      Specified by:
      getTitle in interface PdfRenderer
      Returns:
      title as String
    • getFormat

      public String getFormat()
      Description copied from interface: PdfRenderer
      Return the used paper fromat dimension. the default size is A4 with a margin of 20 millimeter.
      Specified by:
      getFormat in interface PdfRenderer
      Returns:
      format as String