PDFBox

From MidrangeWiki
Jump to: navigation, search

Apache PDFBox is an open source Java PDF library for working with PDF documents.

Installing PDFBox on the System i

  • Download PDFBox and dependencies from http://pdfbox.apache.org/
  • Extract the archive(s) under /qibm/userdata/Java400/ext on the System i
  • Ensure that the java environment is configured to run headless

Using PDFBox in ILE RPG

The following is a demo program that creates a simple one page pdf document from RPG.

      *=====================================================================
      *
      * Demo program implementing Apache's PDFBox
      * Compatible with PDFBox 1.1.0
      *
      * Full documentation of PDFBox is available at
      * http://pdfbox.apache.org/index.html
      *
      * Incomplete, but usable
      *
      *=====================================================================

     H DftActGrp(*No)
     H Thread(*Serialize)

      /Copy QSYSINC/QRPGLESRC,JNI

      *=====================================================================
      * Prototypes for java.util.*, java.lang.*, java.io.* and java.awt.*
      *
      * java.util.Calendar

     D jCalendarClass...
     D                 C                   'java.util.Calendar'

     D jCalendar       S               O   CLASS(*JAVA:
     D                                     jCalendarClass)

      * Calendar()
     D jCalendar_new...
     D                 PR                  like(jCalendar)
     D                                     EXTPROC(*JAVA:
     D                                     jCalendarClass:
     D                                     *CONSTRUCTOR)

      * Calendar.getInstance()
     D jCalendar_getInstance...
     D                 PR                  like(jCalendar)
     D                                     EXTPROC(*JAVA:
     D                                     jCalendarClass:
     D                                     'getInstance')
     D                                     Static

      *-----------------------------------------------------------------
      * java.lang.String

     D jStringClass...
     D                 C                   'java.lang.String'

      * Following class already defined in QSYSINC/QRPGLESRC.JNI
     D*jString         S               O   CLASS(*JAVA:
     D*                                    jStringClass)

     D jstring_new     PR                  like(jString)
     D                                     EXTPROC(*JAVA
     D                                     :jStringClass
     D                                     :*CONSTRUCTOR)
     D create_from                 1024A   Varying const

     D jstring_new_varying...
     D                 PR                  like(jString)
     D                                     EXTPROC(*JAVA
     D                                     :jStringClass
     D                                     :*CONSTRUCTOR)
     D create_from                 1024A   Varying const
     D offset                              like(jint) value
     D length                              like(jint) value

     D jtoRPGStr       PR         32767A   Varying
     D                                     EXTPROC(*JAVA:
     D                                             jStringClass:
     D                                             'getBytes')

      *-----------------------------------------------------------------
      * Classes

     D jOutputStreamClass...
     D                 C                   'java.io.OutputStream'

     D jInputStreamClass...
     D                 C                   'java.io.InputStream'

     D jInputStream    S               O   CLASS(*JAVA:
     D                                     jInputStreamClass)

     D jOutputStream   S               O   CLASS(*JAVA:
     D                                     jOutputStreamClass)

      *-----------------------------------------------------------------
      * java.io.FileInputStream

     D jFileInputStreamClass...
     D                 C                   'java.io.FileInputStream'

     D jFileInputStream...
     D                 S               O   CLASS(*JAVA:
     D                                     jFileInputStreamClass)

      *  new FileInputStream(String filename)
     D FileInputStream_new...
     D                 PR                  like(jFileInputStream)
     D                                     EXTPROC(*JAVA:
     D                                     jFileInputStreamClass:
     D                                     *CONSTRUCTOR)
     D filename                            like(jString)

      *-----------------------------------------------------------------
      * java.io.FileOutputStream

     D jFileOutputStreamClass...
     D                 C                   'java.io.FileOutputStream'

     D jFileOutputStream...
     D                 S               O   CLASS(*JAVA:
     D                                     jFileOutputStreamClass)

     D FileOutputStream_new...
     D                 PR                  like(jFileOutputStream)
     D                                     EXTPROC(*JAVA:
     D                                     jFileOutputStreamClass:
     D                                     *CONSTRUCTOR)
     D filename                            like(jString)

     D FileOutputStream_close...
     D                 pr                  EXTPROC(*JAVA:
     D                                     jFileOutputStreamClass:
     D                                     'close')

      *-----------------------------------------------------------------
      * Global Constants to for Java's static fields

      * Colors based on 1.5
     D jWhite          C                   x'FFFFFF'
     D jLight_Grey     C                   x'C0C0C0'
     D jGrey           C                   x'808080'
     D jDark_Grey      C                   x'404040'
     D jBlack          C                   x'000000'
     D jRed            C                   x'FF0000'
     D jPink           C                   x'AFAFAF'
     D jOrange         C                   x'FFC800'
     D jYellow         C                   x'FFFF00'
     D jGreen          C                   x'00FF00'
     D jMagenta        C                   x'FF00FF'
     D jCyan           C                   x'00FFFF'
     D jBlue           C                   x'0000FF'


      *-----------------------------------------------------------------
      * java.awt.Color

     D jColorClass...
     D                 C                   'java.awt.Color'

     D jColor          S               O   CLASS(*JAVA:
     D                                     jColorClass)

      // new Color(int, int, int)
     D jColor_new_fromIntRGB...
     D                 PR                  like(jColor)
     D                                     EXTPROC(*JAVA
     D                                     :jColorClass
     D                                     :*CONSTRUCTOR)
     D R                                   like(jint) value
     D G                                   like(jint) value
     D B                                   like(jint) value

      // new Color(int)
     D jColor_new_fromInt...
     D                 PR                  like(jColor)
     D                                     EXTPROC(*JAVA
     D                                     :jColorClass
     D                                     :*CONSTRUCTOR)
     D RGB_combined                        like(jint) value

      // new Color(float, float, float)
     D jColor_new_fromFloatRGB...
     D                 PR                  like(jColor)
     D                                     EXTPROC(*JAVA
     D                                     :jColorClass
     D                                     :*CONSTRUCTOR)
     D R                                   like(jfloat) value
     D G                                   like(jfloat) value
     D B                                   like(jfloat) value

      *=====================================================================
      * PDFBox

      *-----------------------------------------------------------------
      * Global Constants

     D DEFAULT_USERSPACE_UNIT_DPI...
     D                 C                   72

      * Page sizes in mm
     D PAGE_SIZE_A0    S                   Like(PDRectangle)
     D PAGE_SIZE_A1    S                   Like(PDRectangle)
     D PAGE_SIZE_A2    S                   Like(PDRectangle)
     D PAGE_SIZE_A3    S                   Like(PDRectangle)
     D PAGE_SIZE_A4    S                   Like(PDRectangle)
     D PAGE_SIZE_A5    S                   Like(PDRectangle)
     D PAGE_SIZE_A6    S                   Like(PDRectangle)
     D PAGE_SIZE_A0_LANDSCAPE...
     D                 S                   Like(PDRectangle)
     D PAGE_SIZE_A1_LANDSCAPE...
     D                 S                   Like(PDRectangle)
     D PAGE_SIZE_A2_LANDSCAPE...
     D                 S                   Like(PDRectangle)
     D PAGE_SIZE_A3_LANDSCAPE...
     D                 S                   Like(PDRectangle)
     D PAGE_SIZE_A4_LANDSCAPE...
     D                 S                   Like(PDRectangle)
     D PAGE_SIZE_A5_LANDSCAPE...
     D                 S                   Like(PDRectangle)
     D PAGE_SIZE_A6_LANDSCAPE...
     D                 S                   Like(PDRectangle)
     D PAGE_WIDTH_A0   C                   841
     D PAGE_HEIGHT_A0  C                   1189
     D PAGE_WIDTH_A1   C                   594
     D PAGE_HEIGHT_A1  C                   841
     D PAGE_WIDTH_A2   C                   420
     D PAGE_HEIGHT_A2  C                   594
     D PAGE_WIDTH_A3   C                   297
     D PAGE_HEIGHT_A3  C                   420
     D PAGE_WIDTH_A4   C                   210
     D PAGE_HEIGHT_A4  C                   297
     D PAGE_WIDTH_A5   C                   148
     D PAGE_HEIGHT_A5  C                   210
     D PAGE_WIDTH_A6   C                   105
     D PAGE_HEIGHT_A6  C                   148


      *-----------------------------------------------------------------
      * Font Classes
     D PDFontClass     C                   'org.apache.pdfbox.pdmodel.font.PDFo-
     D                                     nt'
     D PDFont          S               O   CLASS(*JAVA:PDFontClass)

     D PDType3FontClass...
     D                 C                   'org.apache.pdfbox.pdmodel.font.PDTy-
     D                                     pe3Font'
     D PDType3Font     S               O   CLASS(*JAVA:PDType3FontClass)

     D PDType1CFontClass...
     D                 C                   'org.apache.pdfbox.pdmodel.font.PDTy-
     D                                     pe1CFont'
     D PDType1CFont    S               O   CLASS(*JAVA:PDType1CFontClass)

     D PDType1AfmPfbFontClass...
     D                 C                   'org.apache.pdfbox.pdmodel.font.PDTy-
     D                                     pe1AfmPfbFontClass'
     D PDType1AfmPfbFont...
     D                 S               O   CLASS(*JAVA:
     D                                     PDType1AfmPfbFontClass)

     D PDType1FontClass...
     D                 C                   'org.apache.pdfbox.pdmodel.font.PDTy-
     D                                     pe1Font'
     D PDType1Font     S               O   CLASS(*JAVA:PDType1FontClass)

     D PDType0FontClass...
     D                 C                   'org.apache.pdfbox.pdmodel.font.PDTy-
     D                                     pe0Font'
     D PDType0Font     S               O   CLASS(*JAVA:PDType0FontClass)

     D PDTrueTypeFontClass...
     D                 C                   'org.apache.pdfbox.pdmodel.font.PDTr-
     D                                     ueTypeFont'
     D PDTrueTypeFont  S               O   CLASS(*JAVA:PDTrueTypeFontClass)

      *-----------------------------------------------------------------
      * PDFont

      * PDFont()
     D PDFont_new...
     D                 PR                  like(PDFont)
     D                                     EXTPROC(*JAVA:
     D                                     PDFontClass:
     D                                     *CONSTRUCTOR)

      * PDFont.setBaseFont
     D PDFont_setBaseFont...
     D                 PR                  like(PDFont)
     D                                     EXTPROC(*JAVA:
     D                                     PDFontClass:
     D                                     'setBaseFont')
     D fontname                            like(jString)

      * PDFont.getStringWidth(java.lang.String string)
     D PDFont_getStringWidth...
     D                 PR                  like(jfloat)
     D                                     EXTPROC(*JAVA:
     D                                     PDFontClass:
     D                                     'getStringWidth')
     D string                              like(jString)

      *-----------------------------------------------------------------
      * PDTrueTypeFont

      * PDTrueTypeFont
     D PDTrueTypeFont_new...
     D                 PR                  like(PDTrueTypeFont)
     D                                     EXTPROC(*JAVA:
     D                                     PDTrueTypeFontClass:
     D                                     *CONSTRUCTOR)

      * PDTrueTypeFont.loadTTF()
     D PDTrueTypeFont_loadTTF...
     D                 PR                  like(PDTrueTypeFont)
     D                                     EXTPROC(*JAVA:
     D                                     PDTrueTypeFontClass:
     D                                     'loadTTF')
     D                                     Static
     D document                            like(PDDocument)
     D fontfilename                        like(jString)

      *-----------------------------------------------------------------
      * PDType1Font

      * PDType1Font()
     D PDType1Font_new...
     D                 PR                  like(PDType1Font)
     D                                     EXTPROC(*JAVA:
     D                                     PDType1FontClass:
     D                                     *CONSTRUCTOR)
     D fontname                            like(jString) Options(*Omit)

      * PDType1Font.getStandardFont
     D PDType1Font_getStandardFont...
     D                 PR                  like(PDType1Font)
     D                                     EXTPROC(*JAVA:
     D                                     PDType1FontClass:
     D                                     'getStandardFont')
     D fontname                            like(jString)

      *-----------------------------------------------------------------
      * PDDocumentCatalog

     D PDDocumentCatalogClass...
     D                 C                   'org.apache.pdfbox.pdmodel.PDDocumen-
     D                                     tCatalog'
     D PDDocumentCatalog...
     D                 S               O   CLASS(*JAVA:PDDocumentCatalogClass)

     D PDDocumentCatalog_new...
     D                 PR                  like(PDDocumentCatalog)
     D                                     EXTPROC(*JAVA:
     D                                     PDDocumentCatalogClass:
     D                                     *CONSTRUCTOR)
     D document                            like(PDDocument)

     D PDDocumentCatalog_getAllPages...
     D                 PR
     D                                     EXTPROC(*JAVA:
     D                                     PDDocumentCatalogClass:
     D                                     'getAllPages')

      *-----------------------------------------------------------------
      * PDDocument

     D PDDocumentClass...
     D                 C                   'org.apache.pdfbox.pdmodel.PDDocumen-
     D                                     t'
     D PDDocument      S               O   CLASS(*JAVA:PDDocumentClass)

      * PDDocument()
     D PDDocument_new...
     D                 PR                  like(PDDocument)
     D                                     EXTPROC(*JAVA:
     D                                     PDDocumentClass:
     D                                     *CONSTRUCTOR)

      * PDDocument.addPage()
     D PDDocument_addPage...
     D                 PR
     D                                     EXTPROC(*JAVA:
     D                                     PDDocumentClass:
     D                                     'addPage')
     D ppage                               like(PDPage)

      * PDDocument.save()
     D PDDocument_save...
     D                 PR
     D                                     EXTPROC(*JAVA:
     D                                     PDDocumentClass:
     D                                     'save')
     D filename                            like(jString)

      * PDDocument.close()
     D PDDocument_close...
     D                 PR
     D                                     EXTPROC(*JAVA:
     D                                     PDDocumentClass:
     D                                     'close')

      * PDDocument.getNumberOfPages()
     D PDDocument_getNumberOfPages...
     D                 PR                  like(jint)
     D                                     EXTPROC(*JAVA:
     D                                     PDDocumentClass:
     D                                     'getNumberOfPages')

      * PDDocument.removePage()
     D PDDocument_removePage...
     D                 PR              N
     D                                     EXTPROC(*JAVA:
     D                                     PDDocumentClass:
     D                                     'removePage')
     D pdpage                              like(PDPage)

      * PDDocument.removePage()
     D PDDocument_removePage_byNumber...
     D                 PR              N
     D                                     EXTPROC(*JAVA:
     D                                     PDDocumentClass:
     D                                     'removePage')
     D pageNumber                          like(jint) value

      * PDDocument.getDocumentCatalog()
     D PDDocument_getDocumentCatalog...
     D                 PR                  like(PDDocumentCatalog)
     D                                     EXTPROC(*JAVA:
     D                                     PDDocumentClass:
     D                                     'getDocumentCatalog')

      * PDDocument.getDocumentInformation()
     D PDDocument_getDocumentInformation...
     D                 PR                  like(PDDocumentInformation)
     D                                     EXTPROC(*JAVA:
     D                                     PDDocumentClass:
     D                                     'getDocumentInformation')

      * PDDocument.setDocumentInformation()
     D PDDocument_setDocumentInformation...
     D                 PR
     D                                     EXTPROC(*JAVA:
     D                                     PDDocumentClass:
     D                                     'setDocumentInformation')
     D documentInformation...
     D                                     like(PDDocumentInformation)

      *-----------------------------------------------------------------
      * PDDocumentInformation

     D PDDocumentInformationClass...
     D                 C                   'org.apache.pdfbox.pdmodel.PDDocumen-
     D                                     tInformation'
     D PDDocumentInformation...
     D                 S               O   CLASS(*JAVA:
     D                                      PDDocumentInformationClass)

      * PDDocumentInformation()
     D PDDocumentInformation_new...
     D                 PR                  like(PDDocumentInformation)
     D                                     EXTPROC(*JAVA:
     D                                     PDDocumentInformationClass:
     D                                     *CONSTRUCTOR)

      * PDDocumentInformation.getAuthor()
     D PDDocumentInformation_getAuthor...
     D                 PR                  like(jstring)
     D                                     EXTPROC(*JAVA:
     D                                     PDDocumentInformationClass:
     D                                     'getAuthor')

      * PDDocumentInformation.setAuthor()
     D PDDocumentInformation_setAuthor...
     D                 PR
     D                                     EXTPROC(*JAVA:
     D                                     PDDocumentInformationClass:
     D                                     'setAuthor')
     D author                              like(jstring) const

      * PDDocumentInformation.getCreator()
     D PDDocumentInformation_getCreator...
     D                 PR                  like(jstring)
     D                                     EXTPROC(*JAVA:
     D                                     PDDocumentInformationClass:
     D                                     'getCreator')

      * PDDocumentInformation.setCreator()
     D PDDocumentInformation_setCreator...
     D                 PR
     D                                     EXTPROC(*JAVA:
     D                                     PDDocumentInformationClass:
     D                                     'setCreator')
     D creator                             like(jstring) const

      * PDDocumentInformation.getKeyWords()
     D PDDocumentInformation_getKeyWords...
     D                 PR                  like(jstring)
     D                                     EXTPROC(*JAVA:
     D                                     PDDocumentInformationClass:
     D                                     'getKeyWords')

      * PDDocumentInformation.setKeywords()
     D PDDocumentInformation_setKeywords...
     D                 PR
     D                                     EXTPROC(*JAVA:
     D                                     PDDocumentInformationClass:
     D                                     'setKeywords')
     D keywords                            like(jstring) const

      * PDDocumentInformation.getProducer()
     D PDDocumentInformation_getProducer...
     D                 PR                  like(jstring)
     D                                     EXTPROC(*JAVA:
     D                                     PDDocumentInformationClass:
     D                                     'getProducer')

      * PDDocumentInformation.setProducer()
     D PDDocumentInformation_setProducer...
     D                 PR
     D                                     EXTPROC(*JAVA:
     D                                     PDDocumentInformationClass:
     D                                     'setProducer')
     D producer                            like(jstring) const

      * PDDocumentInformation.getSubject()
     D PDDocumentInformation_getSubject...
     D                 PR                  like(jstring)
     D                                     EXTPROC(*JAVA:
     D                                     PDDocumentInformationClass:
     D                                     'getSubject')

      * PDDocumentInformation.setSubject()
     D PDDocumentInformation_setSubject...
     D                 PR
     D                                     EXTPROC(*JAVA:
     D                                     PDDocumentInformationClass:
     D                                     'setSubject')
     D subject                             like(jstring) const

      * PDDocumentInformation.getTitle()
     D PDDocumentInformation_getTitle...
     D                 PR                  like(jstring)
     D                                     EXTPROC(*JAVA:
     D                                     PDDocumentInformationClass:
     D                                     'getTitle')

      * PDDocumentInformation.setTitle()
     D PDDocumentInformation_setTitle...
     D                 PR
     D                                     EXTPROC(*JAVA:
     D                                     PDDocumentInformationClass:
     D                                     'setTitle')
     D doctitle                            like(jstring) const

     D PDDocumentInformation_getCreationDate...
     D                 PR                  like(jCalendar)
     D                                     EXTPROC(*JAVA:
     D                                     PDDocumentInformationClass:
     D                                     'getCreationDate')

      * PDDocumentInformation.setCreationDate(java.util.Calendar date)
     D PDDocumentInformation_setCreationDate...
     D                 PR
     D                                     EXTPROC(*JAVA:
     D                                     PDDocumentInformationClass:
     D                                     'setCreationDate')
     D calendar                            like(jCalendar) const

     D PDDocumentInformation_getModificationDate...
     D                 PR                  like(jCalendar)
     D                                     EXTPROC(*JAVA:
     D                                     PDDocumentInformationClass:
     D                                     'getModuficationDate')

      * PDDocumentInformation.setModificationDate(java.util.Calendar date)
     D PDDocumentInformation_setModificationDate...
     D                 PR
     D                                     EXTPROC(*JAVA:
     D                                     PDDocumentInformationClass:
     D                                     'setModificationDate')
     D calendar                            like(jCalendar) const


      *-----------------------------------------------------------------
      * PDPage

     D PDPageClass     C                   'org.apache.pdfbox.pdmodel.PDPage'
     D PDPage          S               O   CLASS(*JAVA:PDPageClass)

      * PDPage()
     D PDPage_new...
     D                 PR                  like(PDPage)
     D                                     EXTPROC(*JAVA:
     D                                     PDPageClass:
     D                                     *CONSTRUCTOR)

     D PDPage_setContents...
     D                 PR
     D                                     EXTPROC(*JAVA:
     D                                     PDPageClass:
     D                                     'setContents')
     D content                             Like(PDStream)

     D PDPage_getContents...
     D                 PR                  Like(PDStream)
     D                                     EXTPROC(*JAVA:
     D                                     PDPageClass:
     D                                     'getContents')

     D PDPage_setRotation...
     D                 PR
     D                                     EXTPROC(*JAVA:
     D                                     PDPageClass:
     D                                     'setRotation')
     D rotation                            like(jint) value

     D PDPage_getRotation...
     D                 PR                  Like(jint)
     D                                     EXTPROC(*JAVA:
     D                                     PDPageClass:
     D                                     'getRotation')

     D PDPage_findRotation...
     D                 PR                  Like(jint)
     D                                     EXTPROC(*JAVA:
     D                                     PDPageClass:
     D                                     'findRotation')

     D PDPage_setMediaBox...
     D                 PR
     D                                     EXTPROC(*JAVA:
     D                                     PDPageClass:
     D                                     'setMediaBox')
     D rect                                Like(PDRectangle)

     D PDPage_getMediaBox...
     D                 PR                  Like(PDRectangle)
     D                                     EXTPROC(*JAVA:
     D                                     PDPageClass:
     D                                     'getMediaBox')

     D PDPage_findMediaBox...
     D                 PR                  Like(PDRectangle)
     D                                     EXTPROC(*JAVA:
     D                                     PDPageClass:
     D                                     'findMediaBox')

     D PDPage_setCropBox...
     D                 PR
     D                                     EXTPROC(*JAVA:
     D                                     PDPageClass:
     D                                     'setCropBox')
     D rect                                Like(PDRectangle)

     D PDPage_getCropBox...
     D                 PR                  Like(PDRectangle)
     D                                     EXTPROC(*JAVA:
     D                                     PDPageClass:
     D                                     'getCropBox')

     D PDPage_findCropBox...
     D                 PR                  Like(PDRectangle)
     D                                     EXTPROC(*JAVA:
     D                                     PDPageClass:
     D                                     'findCropBox')

     D PDPage_setArtBox...
     D                 PR
     D                                     EXTPROC(*JAVA:
     D                                     PDPageClass:
     D                                     'setArtBox')
     D rect                                Like(PDRectangle)

     D PDPage_getArtBox...
     D                 PR                  Like(PDRectangle)
     D                                     EXTPROC(*JAVA:
     D                                     PDPageClass:
     D                                     'getArtBox')

     D PDPage_setBleedBox...
     D                 PR
     D                                     EXTPROC(*JAVA:
     D                                     PDPageClass:
     D                                     'setBleedBox')
     D rect                                Like(PDRectangle)

     D PDPage_getBleedBox...
     D                 PR                  Like(PDRectangle)
     D                                     EXTPROC(*JAVA:
     D                                     PDPageClass:
     D                                     'getBleedBox')

     D PDPage_setTrimBox...
     D                 PR
     D                                     EXTPROC(*JAVA:
     D                                     PDPageClass:
     D                                     'setTrimBox')
     D rect                                Like(PDRectangle)

     D PDPage_getTrimBox...
     D                 PR                  Like(PDRectangle)
     D                                     EXTPROC(*JAVA:
     D                                     PDPageClass:
     D                                     'getTrimBox')

      *-----------------------------------------------------------------
      * PDPageContentStream

     D PDPageContentStreamClass...
     D                 C                   'org.apache.pdfbox.pdmodel.edit.PDPa-
     D                                     geContentStream'
     D PDPageContentStream...
     D                 S               O   CLASS(*JAVA:
     D                                     PDPageContentStreamClass)

      * PDPageContentStream()
     D PDPageContentStream_new...
     D                 PR                  like(PDPageContentStream)
     D                                     EXTPROC(*JAVA:
     D                                     PDPageContentStreamClass:
     D                                     *CONSTRUCTOR)
     D pdocument                           like(PDDocument)
     D ppage                               like(PDPage)
     D appendcontent                   N   value
     D compress                        N   value

      * PDPageContentStream.beginText()
     D PDPageContentStream_beginText...
     D                 PR
     D                                     EXTPROC(*JAVA:
     D                                     PDPageContentStreamClass:
     D                                     'beginText')

      * PDPageContentStream.setFont()
     D PDPageContentStream_setFont...
     D                 PR
     D                                     EXTPROC(*JAVA:
     D                                     PDPageContentStreamClass:
     D                                     'setFont')
     D font                                like(PDFont)
     D fontSize                            like(jfloat) Value

      * PDPageContentStream.moveTextPositionByAmount()
     D PDPageContentStream_moveTextPositionByAmount...
     D                 PR
     D                                     EXTPROC(*JAVA:
     D                                     PDPageContentStreamClass:
     D                                     'moveTextPositionByAmount')
     D x                                   like(jfloat) Value
     D y                                   like(jfloat) Value

      * PDPageContentStream.drawString()
     D PDPageContentStream_drawString...
     D                 PR
     D                                     EXTPROC(*JAVA:
     D                                     PDPageContentStreamClass:
     D                                     'drawString')
     D text                                like(jstring)

      * PDPageContentStream.endText()
     D PDPageContentStream_endText...
     D                 PR
     D                                     EXTPROC(*JAVA:
     D                                     PDPageContentStreamClass:
     D                                     'endText')

      * PDPageContentStream.drawLine()
     D PDPageContentStream_drawLine...
     D                 PR
     D                                     EXTPROC(*JAVA:
     D                                     PDPageContentStreamClass:
     D                                     'drawLine')
     D startx                              like(jfloat) value
     D starty                              like(jfloat) value
     D endx                                like(jfloat) value
     D endy                                like(jfloat) value

      * PDPageContentStream.drawImage()
     D PDPageContentStream_drawImage...
     D                 PR
     D                                     EXTPROC(*JAVA:
     D                                     PDPageContentStreamClass:
     D                                     'drawImage')
     D img                                 like(PDXObjectImage)
     D x                                   like(jfloat) value
     D y                                   like(jfloat) value

      * PDPageContentStream.drawXObject()
     D PDPageContentStream_drawXObject...
     D                 PR
     D                                     EXTPROC(*JAVA:
     D                                     PDPageContentStreamClass:
     D                                     'drawXObject')
     D img                                 like(PDXObject)
     D x                                   like(jfloat) value
     D y                                   like(jfloat) value
     D width                               like(jfloat) value
     D height                              like(jfloat) value

      * PDPageContentStream.fillRect()
     D PDPageContentStream_fillRect...
     D                 PR
     D                                     EXTPROC(*JAVA:
     D                                     PDPageContentStreamClass:
     D                                     'fillRect')
     D x                                   like(jfloat) value
     D y                                   like(jfloat) value
     D width                               like(jfloat) value
     D height                              like(jfloat) value


      * PDPageContentStream.close()
     D PDPageContentStream_close...
     D                 PR
     D                                     EXTPROC(*JAVA:
     D                                     PDPageContentStreamClass:
     D                                     'close')

      * PDPageContentStream.setLineWidth()
     D PDPageContentStream_setLineWidth...
     D                 PR
     D                                     EXTPROC(*JAVA:
     D                                     PDPageContentStreamClass:
     D                                     'setLineWidth')
     D lineWidth                           like(jfloat) value

      * PDPageContentStream.setNonStrokingColor(java.awt.Color color)
     D PDPageContentStream_setNonStrokingColor...
     D                 PR
     D                                     EXTPROC(*JAVA:
     D                                     PDPageContentStreamClass:
     D                                     'setNonStrokingColor')
     D color                               like(jColor)

      * PDPageContentStream.setStrokingColor(java.awt.Color color)
     D PDPageContentStream_setStrokingColor...
     D                 PR
     D                                     EXTPROC(*JAVA:
     D                                     PDPageContentStreamClass:
     D                                     'setStrokingColor')
     D color                               like(jColor)

      *-----------------------------------------------------------------
      * PDRectangle

     D PDRectangleClass...
     D                 C                   'org.apache.pdfbox.pdmodel.common.PD-
     D                                     Rectangle'
     D PDRectangle     S               O   CLASS(*JAVA:PDRectangleClass)

      * PDRectangle()
     D PDRectangle_new...
     D                 PR                  like(PDRectangle)
     D                                     EXTPROC(*JAVA:
     D                                     PDRectangleClass:
     D                                     *CONSTRUCTOR)
     D width                               like(jfloat) Value
     D height                              like(jfloat) Value

     D PDRectangle_getWidth...
     D                 PR                  like(jfloat)
     D                                     EXTPROC(*JAVA:
     D                                     PDRectangleClass:
     D                                     'getWidth')

     D PDRectangle_getHeight...
     D                 PR                  like(jfloat)
     D                                     EXTPROC(*JAVA:
     D                                     PDRectangleClass:
     D                                     'getHeight')

     D PDRectangle_getLowerLeftX...
     D                 PR                  like(jfloat)
     D                                     EXTPROC(*JAVA:
     D                                     PDRectangleClass:
     D                                     'getLowerLeftX')

     D PDRectangle_getLowerLeftY...
     D                 PR                  like(jfloat)
     D                                     EXTPROC(*JAVA:
     D                                     PDRectangleClass:
     D                                     'getLowerLeftY')

     D PDRectangle_getUpperRightX...
     D                 PR                  like(jfloat)
     D                                     EXTPROC(*JAVA:
     D                                     PDRectangleClass:
     D                                     'getUpperRightX')

     D PDRectangle_getUpperRightY...
     D                 PR                  like(jfloat)
     D                                     EXTPROC(*JAVA:
     D                                     PDRectangleClass:
     D                                     'getUpperRightY')

      *-----------------------------------------------------------------
      * PDXObjectImage

     D PDXObjectImageClass...
     D                 C                   'org.apache.pdfbox.pdmodel.graphics.-
     D                                     xobject.PDXObjectImage'
     D PDXObjectImage  S               O   CLASS(*JAVA:PDXObjectImageClass)

      * PDXObjectImage()
     D PDXObjectImage_new...
     D                 PR                  like(PDXObjectImage)
     D                                     EXTPROC(*JAVA:
     D                                     PDXObjectImageClass:
     D                                     *CONSTRUCTOR)
     D imageStream                         like(PDStream)
     D imageSuffix                         like(jstring)

      * PDXObjectImage.getHeight()
     D PDXObjectImage_getHeight...
     D                 PR                  like(jint)
     D                                     EXTPROC(*JAVA:
     D                                     PDXObjectImageClass:
     D                                     'getHeight')

      * PDXObjectImage.getWidth()
     D PDXObjectImage_getWidth...
     D                 PR                  like(jint)
     D                                     EXTPROC(*JAVA:
     D                                     PDXObjectImageClass:
     D                                     'getWidth')

      *-----------------------------------------------------------------
      * PDXObject

     D PDXObjectClass...
     D                 C                   'org.apache.pdfbox.pdmodel.graphics.-
     D                                     xobject.PDXObject'
     D PDXObject       S               O   CLASS(*JAVA:PDXObjectClass)

      * PDXObject()
     D PDXObject_new...
     D                 PR                  like(PDXObject)
     D                                     EXTPROC(*JAVA:
     D                                     PDXObjectClass:
     D                                     *CONSTRUCTOR)
     D document                            like(PDDocument)

      *-----------------------------------------------------------------
      * PDJpeg

     D PDJpegClass...
     D                 C                   'org.apache.pdfbox.pdmodel.graphics.-
     D                                     xobject.PDJpeg'
     D PDJpeg          S               O   CLASS(*JAVA:PDJpegClass)

      * PDJpeg()
     D PDJpeg_new...
     D                 PR                  like(PDJpeg)
     D                                     EXTPROC(*JAVA:
     D                                     PDJpegClass:
     D                                     *CONSTRUCTOR)
     D document                            like(PDDocument)
     D inputstream                         like(jInputStream)

      *-----------------------------------------------------------------
      * PDStream

     D PDStreamClass...
     D                 C                   'org.apache.pdfbox.pdmodel.common.PD-
     D                                     Stream'
     D PDStream        S               O   CLASS(*JAVA:PDStreamClass)

      * PDStream()
     D PDStream_new...
     D                 PR                  like(PDStream)
     D                                     EXTPROC(*JAVA:
     D                                     PDStreamClass:
     D                                     *CONSTRUCTOR)
     D document                            like(PDDocument) Options(*Omit)
     D stream                              like(jInputStream) Options(*Omit)

      *-----------------------------------------------------------------
      * Utilities

     D mmToUnits       PR                  Like(jfloat)
     D  pmm                                Like(jfloat) Value

     D createPageSizes...
     D                 PR

      *======================== Main =======================================

     D myDocument      S                   like(PDDocument)
     D myPage          S                   like(PDPage)
     D myPageContent   S                   like(PDPageContentStream)
     D myFontName      S                   like(jstring)
     D myFont          S                   like(PDType1Font)
     D myString        S                   like(jstring)
     D myFile          S                   like(jstring)

      /free

        // Create a new PDF document in memory
        myDocument = PDDocument_new();

        // Create object for all types of page sizes
        createPageSizes();

        // Add a new page to the PDF document
        myPage = PDPage_new();
        PDDocument_addPage(myDocument:myPage);

        // Set the page size and orientation
        PDPage_setMediaBox(myPage:PAGE_SIZE_A4);
        PDPage_setRotation(myPage:0);

        // Create a content stream so we can add content to the page
        // First content stream, so append is *Off
        // Compression is *Off
        myPageContent = PDPageContentStream_new(myDocument:myPage:
                        *Off:*Off);

        // Set font type
        myFontName = jstring_new('Courier');
        myFont = PDType1Font_new(myFontName);
        PDPageContentStream_setFont(myPageContent:myFont:10);

        // Prepare to write text to the content stream
        PDPageContentStream_beginText(myPageContent);

        // Move the cursor possition, 10mm from the left, 270mm from the bottom
        PDPageContentStream_moveTextPositionByAmount(myPageContent:
        mmtounits(10):mmtounits(200));

        // Create the text string we want to write
        myString = jstring_new('PDFBox on the iSeries Demo');

        // Write the string to the content stream
        PDPageContentStream_drawString(myPageContent:myString);

        // We are done writing text to this content stream
        PDPageContentStream_endText(myPageContent);

        // We are done working with this content stream
        PDPageContentStream_close(myPageContent);

        // Done with this file, so save it
        myFile = jstring_new('/tmp/PDFBox-demo.pdf');
        PDDocument_save(myDocument:myFile);

        // Close the document object im memory to free all allocated space
        PDDocument_close(myDocument);

        // Done
        *INLR = *On;

      /end-free

      *-----------------------------------------------------------------
      * mmToUnits

     P mmToUnits       B
     D                 Pi                  Like(jfloat)
     D pmm                                 value like(jfloat)

     D funits          S                   Like(jfloat)
      /free

        funits = 1 / (25.4) *
                 DEFAULT_USERSPACE_UNIT_DPI *
                 pmm;

        return funits;

      /end-free
     P mmToUnits       E

      *-----------------------------------------------------------------
      * creatPageSizes

     P createPageSizes...
     P                 B
     D                 Pi
      /free

        PAGE_SIZE_A0 = PDRectangle_new(mmToUnits(PAGE_WIDTH_A0):
                                       mmToUnits(PAGE_HEIGHT_A0));

        PAGE_SIZE_A1 = PDRectangle_new(mmToUnits(PAGE_WIDTH_A1):
                                       mmToUnits(PAGE_HEIGHT_A1));

        PAGE_SIZE_A2 = PDRectangle_new(mmToUnits(PAGE_WIDTH_A2):
                                       mmToUnits(PAGE_HEIGHT_A2));

        PAGE_SIZE_A3 = PDRectangle_new(mmToUnits(PAGE_WIDTH_A3):
                                       mmToUnits(PAGE_HEIGHT_A3));

        PAGE_SIZE_A4 = PDRectangle_new(mmToUnits(PAGE_WIDTH_A4):
                                       mmToUnits(PAGE_HEIGHT_A4));

        PAGE_SIZE_A5 = PDRectangle_new(mmToUnits(PAGE_WIDTH_A5):
                                       mmToUnits(PAGE_HEIGHT_A5));

        PAGE_SIZE_A6 = PDRectangle_new(mmToUnits(PAGE_WIDTH_A6):
                                       mmToUnits(PAGE_HEIGHT_A6));

        PAGE_SIZE_A0_LANDSCAPE = PDRectangle_new(mmToUnits(PAGE_HEIGHT_A0):
                                       mmToUnits(PAGE_WIDTH_A0));

        PAGE_SIZE_A1_LANDSCAPE = PDRectangle_new(mmToUnits(PAGE_HEIGHT_A1):
                                       mmToUnits(PAGE_WIDTH_A1));

        PAGE_SIZE_A2_LANDSCAPE = PDRectangle_new(mmToUnits(PAGE_HEIGHT_A2):
                                       mmToUnits(PAGE_WIDTH_A2));

        PAGE_SIZE_A3_LANDSCAPE = PDRectangle_new(mmToUnits(PAGE_HEIGHT_A3):
                                       mmToUnits(PAGE_WIDTH_A3));

        PAGE_SIZE_A4_LANDSCAPE = PDRectangle_new(mmToUnits(PAGE_HEIGHT_A4):
                                       mmToUnits(PAGE_WIDTH_A4));

        PAGE_SIZE_A5_LANDSCAPE = PDRectangle_new(mmToUnits(PAGE_HEIGHT_A5):
                                       mmToUnits(PAGE_WIDTH_A5));

        PAGE_SIZE_A6_LANDSCAPE = PDRectangle_new(mmToUnits(PAGE_HEIGHT_A6):
                                       mmToUnits(PAGE_WIDTH_A6));

        return;

      /end-free
     P                 E


External links