List of usage examples for com.lowagie.text.pdf PdfSignatureAppearance CERTIFIED_FORM_FILLING_AND_ANNOTATIONS
int CERTIFIED_FORM_FILLING_AND_ANNOTATIONS
To view the source code for com.lowagie.text.pdf PdfSignatureAppearance CERTIFIED_FORM_FILLING_AND_ANNOTATIONS.
Click Source Link
From source file:org.signserver.module.pdfsigner.PDFSignerParameters.java
License:Open Source License
private void extractAndProcessConfigurationProperties() throws IllegalRequestException, SignServerException { // The reason shown in the PDF signature if (config.getProperties().getProperty(PDFSigner.REASON) != null) { reason = config.getProperties().getProperty(PDFSigner.REASON); }// w w w. j a va 2 s. co m LOG.debug("Using reason: " + reason); // The location shown in the PDF signature if (config.getProperties().getProperty(PDFSigner.LOCATION) != null) { location = config.getProperties().getProperty(PDFSigner.LOCATION); } LOG.debug("Using location: " + location); // are we adding visible or invisible signature // note : ParseBoolean returns false for everything but "True" if (config.getProperties().getProperty(PDFSigner.ADD_VISIBLE_SIGNATURE) != null) { add_visible_signature = Boolean .parseBoolean(config.getProperties().getProperty(PDFSigner.ADD_VISIBLE_SIGNATURE).trim()); } LOG.debug("Using visible signature: " + add_visible_signature); // timestamp url if (config.getProperties().getProperty(PDFSigner.TSA_URL) != null) { tsa_url = config.getProperties().getProperty(PDFSigner.TSA_URL); use_timestamp = true; LOG.debug("Using tsa url : " + tsa_url); } else if (config.getProperties().getProperty(PDFSigner.TSA_WORKER) != null) { tsa_worker = config.getProperties().getProperty(PDFSigner.TSA_WORKER); use_timestamp = true; } if (use_timestamp && config.getProperties().getProperty(PDFSigner.TSA_USERNAME) != null && config.getProperties().getProperty(PDFSigner.TSA_PASSWORD) != null) { tsa_username = config.getProperties().getProperty(PDFSigner.TSA_USERNAME); tsa_password = config.getProperties().getProperty(PDFSigner.TSA_PASSWORD); use_timestamp_authorization = true; } // should we embed crl inside the cms package if (config.getProperties().getProperty(PDFSigner.EMBED_CRL) != null) { embed_crl = Boolean.parseBoolean(config.getProperties().getProperty(PDFSigner.EMBED_CRL).trim()); } LOG.debug("Using embed crl inside cms package : " + isEmbed_crl()); // should we embed ocsp response inside the cms package if (config.getProperties().getProperty(PDFSigner.EMBED_OCSP_RESPONSE) != null) { embed_ocsp_response = Boolean .parseBoolean(config.getProperties().getProperty(PDFSigner.EMBED_OCSP_RESPONSE).trim()); } LOG.debug("Using embed ocsp inside cms package : " + isEmbed_ocsp_response()); // should we refuse PDF documents that contains multiple // indirect objects with the same name if (config.getProperties().getProperty(PDFSigner.REFUSE_DOUBLE_INDIRECT_OBJECTS) != null) { refuseDoubleIndirectObjects = Boolean .parseBoolean(config.getProperties().getProperty(PDFSigner.REFUSE_DOUBLE_INDIRECT_OBJECTS)); } // Reject permissions String rejectPermissionsValue = config.getProperties().getProperty(PDFSigner.REJECT_PERMISSIONS); if (rejectPermissionsValue != null) { String[] array = rejectPermissionsValue.split(","); rejectPermissions.addAll(Arrays.asList(array)); } // Set permissions String setPermissionsValue = config.getProperties().getProperty(PDFSigner.SET_PERMISSIONS); if (setPermissionsValue != null) { String[] array = setPermissionsValue.split(","); try { setPermissions = Permissions.fromSet(Arrays.asList(array), true); } catch (UnknownPermissionException ex) { throw new SignServerException("Signer " + workerId + " missconfigured: " + ex.getMessage()); } } // Remove permissions String removePermissionsValue = config.getProperties().getProperty(PDFSigner.REMOVE_PERMISSIONS); if (removePermissionsValue != null) { String[] array = removePermissionsValue.split(","); removePermissions = new HashSet<String>(); removePermissions.addAll(Arrays.asList(array)); } // Set ownerpassword setOwnerPassword = config.getProperties().getProperty(PDFSigner.SET_OWNERPASSWORD); // if signature is chosen to be visible proceed with setting visibility // properties if (add_visible_signature) { // page to draw visible signature at if (config.getProperties().getProperty(PDFSigner.VISIBLE_SIGNATURE_PAGE) != null) { visible_sig_page = config.getProperties().getProperty(PDFSigner.VISIBLE_SIGNATURE_PAGE); } LOG.debug("Using visible signature page: " + visible_sig_page); // The location of the visible signature rectangle(llx, lly, urx, // ury) // llx = lower left x coordinate, lly = lower left y coordinate, urx // = upper right x coordinate, ury = upper right y coordinate if (config.getProperties().getProperty(PDFSigner.VISIBLE_SIGNATURE_RECTANGLE) != null) { visible_sig_rectangle = config.getProperties().getProperty(PDFSigner.VISIBLE_SIGNATURE_RECTANGLE); } LOG.debug("Using rectangle: " + visible_sig_rectangle); String[] rect = visible_sig_rectangle.split(","); if (rect.length < 4) { throw new IllegalRequestException( "RECTANGLE property must contain 4 comma separated values with no spaces."); } visible_sig_rectangle_llx = Integer.valueOf(rect[0]); visible_sig_rectangle_lly = Integer.valueOf(rect[1]); visible_sig_rectangle_urx = Integer.valueOf(rect[2]); visible_sig_rectangle_ury = Integer.valueOf(rect[3]); // custom image to use with signature // base64 encoded byte[] if (config.getProperties().getProperty(PDFSigner.VISIBLE_SIGNATURE_CUSTOM_IMAGE_BASE64) != null) { visible_sig_custom_image_base64 = config.getProperties() .getProperty(PDFSigner.VISIBLE_SIGNATURE_CUSTOM_IMAGE_BASE64); LOG.debug("base64 encoded custom image is set"); } // custom image path. Do not set if base64 encoded image is // specified if (visible_sig_custom_image_base64 == null || visible_sig_custom_image_base64.isEmpty()) { if (config.getProperties().getProperty(PDFSigner.VISIBLE_SIGNATURE_CUSTOM_IMAGE_PATH) != null) { visible_sig_custom_image_path = config.getProperties() .getProperty(PDFSigner.VISIBLE_SIGNATURE_CUSTOM_IMAGE_PATH); LOG.debug("using custom image path : " + visible_sig_custom_image_path); } } boolean use_image_from_base64_string = visible_sig_custom_image_base64 != null && !visible_sig_custom_image_base64.isEmpty(); boolean use_image_from_path = visible_sig_custom_image_path != null && !visible_sig_custom_image_path.isEmpty(); use_custom_image = use_image_from_base64_string || use_image_from_path; // custom image resizing (if we are using custom image) if (use_custom_image) { // retrieve custom image byte[] imageByteArray; if (use_image_from_base64_string) { imageByteArray = Base64.decode(visible_sig_custom_image_base64.getBytes()); } else { try { imageByteArray = readFile(visible_sig_custom_image_path); } catch (IOException e) { throw new SignServerException("Error reading custom image data from path specified", e); } } try { custom_image = Image.getInstance(imageByteArray); } catch (BadElementException e) { throw new SignServerException("Problem constructing image from custom image data", e); } catch (MalformedURLException e) { throw new SignServerException("Problem constructing image from custom image data", e); } catch (IOException e) { throw new SignServerException("Problem constructing image from custom image data", e); } if (config.getProperties() .getProperty(PDFSigner.VISIBLE_SIGNATURE_CUSTOM_IMAGE_SCALE_TO_RECTANGLE) != null) { visible_sig_custom_image_scale_to_rectangle = Boolean.parseBoolean(config.getProperties() .getProperty(PDFSigner.VISIBLE_SIGNATURE_CUSTOM_IMAGE_SCALE_TO_RECTANGLE).trim()); LOG.debug("resize custom image to rectangle : " + visible_sig_custom_image_scale_to_rectangle); } // if we are using custom image and the // VISIBLE_SIGNATURE_CUSTOM_IMAGE_SCALE_TO_RECTANGLE is set to // true resize image to fit to rectangle specified // If set to false calculate urx and ury coordinates from image if (visible_sig_custom_image_scale_to_rectangle) { resizeImageToFitToRectangle(); } else { calculateUpperRightRectangleCoordinatesFromImage(); } } } // Certification level final String level = config.getProperty(PDFSigner.CERTIFICATION_LEVEL); if (level != null) { if (level.equalsIgnoreCase("NO_CHANGES_ALLOWED")) { certification_level = PdfSignatureAppearance.CERTIFIED_NO_CHANGES_ALLOWED; } else if (level.equalsIgnoreCase("FORM_FILLING_AND_ANNOTATIONS")) { certification_level = PdfSignatureAppearance.CERTIFIED_FORM_FILLING_AND_ANNOTATIONS; } else if (level.equalsIgnoreCase("FORM_FILLING")) { certification_level = PdfSignatureAppearance.CERTIFIED_FORM_FILLING; } else if (level.equalsIgnoreCase("NOT_CERTIFIED")) { certification_level = PdfSignatureAppearance.NOT_CERTIFIED; } else { throw new SignServerException("Unknown value for CERTIFICATION_LEVEL"); } } if (LOG.isDebugEnabled()) { LOG.debug("using certification level: " + certification_level); } }