function pdf_to_image_generate_process in PDF to ImageField 7.2
Same name and namespace in other branches
- 7.3 pdf_to_image.module \pdf_to_image_generate_process()
Processing pdf file creation.
1 call to pdf_to_image_generate_process()
- pdf_to_image_field_presave in ./
pdf_to_image.module - Implements hook_field_presave().
File
- ./
pdf_to_image.module, line 439 - Implement a pdf field, based on the file module's file field.
Code
function pdf_to_image_generate_process($entity_type, $entity, $field, $instance, $langcode, &$items) {
if (!empty($items[0]['fid'])) {
$pdf_file = file_load($items[0]['fid']);
$pdf_realpath = file_stream_wrapper_get_instance_by_uri($pdf_file->uri)
->realpath();
$count = pdf_to_image_count_pages($pdf_realpath);
if (!empty($instance['widget']['settings']['target_field']) && $count) {
$params = array(
'entity' => $entity,
'image' => array(
'field' => field_info_field($instance['widget']['settings']['target_field']),
'instance' => field_info_instance($entity_type, $instance['widget']['settings']['target_field'], $instance['bundle']),
),
'pdf' => array(
'field' => $field,
'instance' => $instance,
'file' => $pdf_file,
),
);
// Prepare count parametr.
if ($params['image']['field']['cardinality'] != -1 && $count > $params['image']['field']['cardinality']) {
$count = $params['image']['field']['cardinality'];
}
$operations = array(
array(
'pdf_to_image_generate_process_page',
array(
$params,
0,
),
),
);
if ($count > 0) {
for ($page = 1; $page < $count; $page++) {
$operations[] = array(
'pdf_to_image_generate_process_page',
array(
$params,
$page,
),
);
}
batch_set(array(
'title' => t('Converting PDF, %count pages', array(
'%count' => $count,
)),
'operations' => $operations,
'finished' => 'pdf_to_image_generate_process_attach',
'progress_message' => t('Processed @current out of @total.'),
));
}
// @TODO: save node with one entity without batch.
// else {
// $file = pdf_to_image_generate_page($params, 0);
// }
}
}
}