public ByteArrayOutputStream getFilledPdf(Person person) throws IOException, DocumentException {
      InputStream istream = getClass().getResourceAsStream(BPI_PERSONAL_INFORMATION_PDF_PATH);
      PdfReader reader = new PdfReader(istream);
      reader.getAcroForm().remove(PdfName.SIGFLAGS);
      reader.selectPages("1,2");
      ByteArrayOutputStream output = new ByteArrayOutputStream();
      PdfStamper stamper = new PdfStamper(reader, output);
      form = stamper.getAcroFields();

      setField("Nome completo_1", person.getName());
      setField("NIF", person.getSocialSecurityNumber());
      setField("Nº", person.getDocumentIdNumber());

      setField("Nacionalidade", person.getCountryOfBirth().getCountryNationality().toString());
      setField("Naturalidade", person.getCountryOfBirth().getName());

      setField("Distrito", person.getDistrictOfBirth());
      setField("Concelho", person.getDistrictSubdivisionOfBirth());
      setField("Freguesia", person.getParishOfBirth());
      setField("Nome do Pai", person.getNameOfFather());
      setField("Nome da Mãe", person.getNameOfMother());
      setField("Morada de Residencia_1", person.getAddress());
      setField("Localidade", person.getAreaOfAreaCode());
      setField("Designação Postal", person.getAreaOfAreaCode());
      setField("País", person.getCountryOfResidence().getName());

      String postalCode = person.getPostalCode();
      int dashIndex = postalCode.indexOf('-');
      setField("Código Postal4", postalCode.substring(0, 4));
      String last3Numbers = postalCode.substring(dashIndex + 1, dashIndex + 4);
      setField("Código Postal_5", last3Numbers);
      setField("Móvel", person.getDefaultMobilePhoneNumber());
      setField("E-mail", getMail(person));

      YearMonthDay emissionDate = person.getEmissionDateOfDocumentIdYearMonthDay();
      if (emissionDate != null) {
        setField("Dia_1", String.valueOf(emissionDate.getDayOfMonth()));
        setField("Mês_1", String.valueOf(emissionDate.getMonthOfYear()));
        setField("Ano_1", String.valueOf(emissionDate.getYear()));
      }

      YearMonthDay expirationDate = person.getExpirationDateOfDocumentIdYearMonthDay();
      setField("Dia_2", String.valueOf(expirationDate.getDayOfMonth()));
      setField("Mês_2", String.valueOf(expirationDate.getMonthOfYear()));
      setField("Ano_2", String.valueOf(expirationDate.getYear()));

      YearMonthDay birthdayDate = person.getDateOfBirthYearMonthDay();
      setField("Dia3", String.valueOf(birthdayDate.getDayOfMonth()));
      setField("Mês3", String.valueOf(birthdayDate.getMonthOfYear()));
      setField("Ano_3", String.valueOf(birthdayDate.getYear()));

      stamper.setFormFlattening(true);
      stamper.close();
      return output;
    }
예제 #2
0
  private static void drawPersonalInformation(
      final Page page, final PhdProgramPublicCandidacyHashCode hashCode, final String folderName)
      throws IOException {

    final Person person = hashCode.getPerson();

    page.h(3, "Personal Information", "mtop2");
    page.tableStart("tstyle2 thwhite thnowrap thlight thleft thtop ulnomargin ");

    page.rowStart("tdbold")
        .headerStartWithStyle("width: 125px;")
        .write("Name:")
        .headerEnd()
        .column(person.getName())
        .rowEnd();
    page.rowStart()
        .header("Gender:")
        .column(person.getGender().toLocalizedString(Locale.ENGLISH))
        .rowEnd();
    page.rowStart()
        .header("Identity card type:")
        .column(person.getIdDocumentType().getLocalizedName())
        .rowEnd();
    page.rowStart().header("Identity card #:").column(person.getDocumentIdNumber()).rowEnd();
    page.rowStart().header("Issued by:").column(person.getEmissionLocationOfDocumentId()).rowEnd();
    page.rowStart()
        .header("Fiscal number:")
        .column(string(person.getSocialSecurityNumber()))
        .rowEnd();
    page.rowStart()
        .header("Date of birth:")
        .column(person.getDateOfBirthYearMonthDay().toString("dd/MM/yyyy"))
        .rowEnd();
    page.rowStart().header("Birthplace:").column(person.getDistrictSubdivisionOfBirth()).rowEnd();
    page.rowStart()
        .header("Nationality:")
        .column(person.getCountry().getCountryNationality().getContent())
        .rowEnd();
    page.rowStart().header("Address:").column(person.getAddress()).rowEnd();
    page.rowStart().header("City:").column(person.getArea()).rowEnd();
    page.rowStart().header("Zip code:").column(person.getAreaCode()).rowEnd();
    page.rowStart()
        .header("Country:")
        .column(
            (person.getCountryOfResidence() != null
                ? person.getCountryOfResidence().getName()
                : "-"))
        .rowEnd();
    page.rowStart().header("Phone:").column(person.getDefaultPhoneNumber()).rowEnd();
    page.rowStart().header("Mobile:").column(person.getDefaultMobilePhoneNumber()).rowEnd();
    page.rowStart().header("Email:").column(person.getDefaultEmailAddressValue()).rowEnd();

    page.tableEnd();

    page.h(3, "Photo");
    String photoUrl = APPLICATION_PREFIX_LINK + "/phd/epfl/applications/photo";
    final Photograph photo = person.getPersonalPhotoEvenIfPending();
    if (photo != null) {
      photoUrl += "?photoOid=" + photo.getExternalId();
    }
    page.photo(photoUrl);
  }