Class PdfAcroFormServiceImpl

java.lang.Object
ch.tocco.nice2.conversion.impl.PdfAcroFormServiceImpl
All Implemented Interfaces:
PdfAcroFormService

@Component public class PdfAcroFormServiceImpl extends Object implements PdfAcroFormService
  • Constructor Summary

    Constructors
    Constructor
    Description
    PdfAcroFormServiceImpl(org.slf4j.Logger log, ModuleManager moduleManager)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    fillAcroForm(File pdfFile, Map<String, Tuple2<String,String>> fieldValues, List<String> fontsToReplace)
    Reads a pdf containing a AcroForm from the given input stream, sets all field values and returns the resulting PDF in the given OutputStream Fields are handled as follows: - if null is passed as value, the field is skipped - if the field is a PDCheckbox, the value is parsed as boolean, pass "true" to check it - if the field is a PDRadiobutton, the value is parsed as int (the index of the option to be selected) - else the string value is set as is For TextFields a formatting string may be passed which is set as "DefaultAppearance".
    void
    This is a helper function that can be used to find the FullyQualified field names of an AcroForm - logs all fieldnames with some type information - prints the fieldname of all textfields into the field itself This method should probably not be used in production code, but it is very handy when implementing an automatic AcroForm field mapping
    void
    overlayImage(File pdfFile, String fieldname, byte[] image, float scaling)
    Overlays an image over a PDF AcroForm Field The image is scaled as follows: - The maximal target with is calculated as follows: form field width * scaling - If the image is wider than the maximal target width, the image is scaled down accordingly - If the shrinked image is higher than the form field, it is centered vertically over the form field and might overlap
    void
    removePage(File pdfFile, int pageNumber)
    Removes a page from a pdf document

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • PdfAcroFormServiceImpl

      public PdfAcroFormServiceImpl(org.slf4j.Logger log, ModuleManager moduleManager)
  • Method Details

    • fillAcroForm

      public void fillAcroForm(File pdfFile, Map<String, Tuple2<String,String>> fieldValues, List<String> fontsToReplace) throws IOException
      Description copied from interface: PdfAcroFormService
      Reads a pdf containing a AcroForm from the given input stream, sets all field values and returns the resulting PDF in the given OutputStream Fields are handled as follows: - if null is passed as value, the field is skipped - if the field is a PDCheckbox, the value is parsed as boolean, pass "true" to check it - if the field is a PDRadiobutton, the value is parsed as int (the index of the option to be selected) - else the string value is set as is For TextFields a formatting string may be passed which is set as "DefaultAppearance". e.g. "/ArialMT 12 Tf 0 g" If a font is used in the pdf that does not support Unicode (e.g. type1 fonts), it must be passed as in the fonts to replace parameter. All fonts in this list are replaced by LiberationSans-Regular while generating. The styling descriptor of the field remains as it was before and pdf readers usually render the originally intended font.
      Specified by:
      fillAcroForm in interface PdfAcroFormService
      Parameters:
      pdfFile - The file used to read the pdf and to save the result
      fieldValues - a map of all field values to be replaced, use the FullyQualifiedName as key, the value is a tuple where the first value is the value itself and the second value is an optional formatting string
      fontsToReplace - a list of all used font names that do not support Unicode (e.g. type1 fonts)
      Throws:
      IOException
    • removePage

      public void removePage(File pdfFile, int pageNumber) throws IOException
      Description copied from interface: PdfAcroFormService
      Removes a page from a pdf document
      Specified by:
      removePage in interface PdfAcroFormService
      Parameters:
      pdfFile - The file used to read the pdf and to save the result
      pageNumber - 0 based index of page to remove
      Throws:
      IOException
    • overlayImage

      public void overlayImage(File pdfFile, String fieldname, byte[] image, float scaling) throws IOException
      Description copied from interface: PdfAcroFormService
      Overlays an image over a PDF AcroForm Field The image is scaled as follows: - The maximal target with is calculated as follows: form field width * scaling - If the image is wider than the maximal target width, the image is scaled down accordingly - If the shrinked image is higher than the form field, it is centered vertically over the form field and might overlap
      Specified by:
      overlayImage in interface PdfAcroFormService
      Parameters:
      pdfFile - The file used to read the pdf and to save the result
      fieldname - Fully qualified name of field where the image should be placed
      image - The image (byte array)
      scaling - The scaling factor (e.g. 0.8)
      Throws:
      IOException
    • findAcroFieldnames

      public void findAcroFieldnames(File pdfFile) throws IOException
      Description copied from interface: PdfAcroFormService
      This is a helper function that can be used to find the FullyQualified field names of an AcroForm - logs all fieldnames with some type information - prints the fieldname of all textfields into the field itself This method should probably not be used in production code, but it is very handy when implementing an automatic AcroForm field mapping
      Specified by:
      findAcroFieldnames in interface PdfAcroFormService
      Parameters:
      pdfFile - The file used to read the pdf and to save the result
      Throws:
      IOException