Example usage for com.lowagie.text.pdf.codec Base64 encodeFromFile

List of usage examples for com.lowagie.text.pdf.codec Base64 encodeFromFile

Introduction

In this page you can find the example usage for com.lowagie.text.pdf.codec Base64 encodeFromFile.

Prototype

public static String encodeFromFile(String filename) 

Source Link

Document

Convenience method for reading a binary file and base64-encoding it.

Usage

From source file:org.mgenterprises.openbooks.saving.server.setup.ServerSetup.java

License:Open Source License

private void createCompanyFile() {
    //Lets make our company profile
    companyProfile = new CompanyProfile();
    if (logoPathField.getText().length() > 0)
        companyProfile.setLogoBase64(Base64.encodeFromFile(logoPathField.getText()));
    companyProfile.setCompanyName(companyNameField.getText());
    companyProfile.setMotto(mottoField.getText());
    companyProfile.setEmailAddress(emailField.getText());
    companyProfile.setPhoneNumber(phoneField.getText());
    companyProfile.setFaxNumber(faxField.getText());
    companyProfile.setStreetAddress(streetAddressField.getText());
    companyProfile.setCityName(cityField.getText());
    companyProfile.setState(stateComboBox.getSelectedItem().toString());
    companyProfile.setWebsite(websiteField.getText());

    //Put our profile into a company file
    companyFile = new CompanyFile();
    companyFile.updateCompanyProfile(companyProfile);
}

From source file:org.mifosplatform.portfolio.client.api.ClientImagesApiResource.java

License:Mozilla Public License

/**
 * Returns a base 64 encoded client image Data URI
 *//*www .  j  a  va 2 s . c  o  m*/
@GET
@Consumes({ MediaType.TEXT_PLAIN, MediaType.TEXT_HTML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.TEXT_PLAIN })
public String retrieveClientImage(@PathParam("clientId") final Long clientId) {

    context.authenticatedUser().validateHasReadPermission("CLIENTIMAGE");

    final ClientData clientData = this.clientReadPlatformService.retrieveOne(clientId);

    if (clientData.imageKeyDoesNotExist()) {
        throw new ImageNotFoundException("clients", clientId);
    }

    // TODO: Need a better way of determining image type
    String imageDataURISuffix = IMAGE_DATA_URI_SUFFIX.JPEG.getValue();
    if (StringUtils.endsWith(clientData.imageKey(), IMAGE_FILE_EXTENSION.GIF.getValue())) {
        imageDataURISuffix = IMAGE_DATA_URI_SUFFIX.GIF.getValue();
    } else if (StringUtils.endsWith(clientData.imageKey(), IMAGE_FILE_EXTENSION.PNG.getValue())) {
        imageDataURISuffix = IMAGE_DATA_URI_SUFFIX.PNG.getValue();
    }

    String clientImageAsBase64Text = imageDataURISuffix + Base64.encodeFromFile(clientData.imageKey());

    return clientImageAsBase64Text;
}