Skip to content
Snippets Groups Projects
Commit e2a1acb1 authored by Kevin Kaland's avatar Kevin Kaland
Browse files

Issue #1417398: Port image support.

parent 53cb268d
No related branches found
No related tags found
No related merge requests found
......@@ -546,7 +546,11 @@ function fillpdf_field_edit($form, &$form_state, $pdf_form, $field) {
'#type' => 'textarea',
'#title' => t('Value'),
'#default_value' => $field->value,
'#description' => t('The content that will populate this field when the PDF is printed/saved. This content pulls data via tokens, see below for available tokens.'),
'#description' => t('<p>The content that will populate this field when the PDF is printed/saved.
This content pulls data via tokens, see below for available tokens.</p>
<p>To fill this field with an image, use the special pseudo-token <strong>[stamp:field_name]</strong>.
If your <em>Image</em> field is named <em>field_image</em>, then you would use
<strong>[stamp:field_image]</strong>.</p>'),
'#weight' => 4,
);
$form['tokens_fieldset'] = array(
......
......@@ -304,15 +304,20 @@ function fillpdf_merge_pdf($fid, $nids = NULL, $webform_arr = NULL, $sample = NU
}
}
$transform_string = TRUE;
// TODO: Fix *everything* here.
// if they're populating with an imagefield
//@@TODO: check if an image (not another pdf or some-such)_
if (strstr($obj->value, 'filefield-fid]')) {
module_load_include('inc', 'filefield', 'field_file');
$filefield = field_file_load($token);
$file_bytes = _fillpdf_get_file_contents($filefield['filepath']);
$str = base64_encode($file_bytes);
//TODO: check if an image (not another pdf or some-such)_
if (strstr($obj->value, '[stamp:')) {
// HACK: Use a pseudo-token to stamp images.
// Find the two sides of the square bracket contents.
// 7 is the length of [stamp:. We don't want the brackets themselves.
$left_side = strpos($obj->value, '[stamp:') + 7;
$right_side = strpos($obj->value, ']');
$field_name = substr($obj->value, $left_side, $right_side - $left_side);
$image_path = $node->{$field_name}[$node->language][0]['uri'];
$transform_string = FALSE;
$fields[$obj->pdf_key] = '{image}' . $str;
$fields[$obj->pdf_key] = '{image}' . drupal_realpath($image_path);
}
else {
}
......@@ -367,7 +372,14 @@ function fillpdf_merge_pdf($fid, $nids = NULL, $webform_arr = NULL, $sample = NU
try {
$fillpdf = new java('com.ocdevel.FillpdfService', base64_encode($pdf_data), 'bytes');
foreach ($fields as $key => $field) {
$fillpdf->text($key, $field);
if (substr($field, 0, 7) == '{image}') {
// Remove {image} marker.
$image_filepath = substr($field, 7);
$fillpdf->image($key, $image_filepath, "file");
}
else {
$fillpdf->text($key, $field);
}
}
}
catch (JavaException $e) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment