function pdf_to_imagefield_convert_pages in PDF to ImageField 6.2
Same name and namespace in other branches
- 6 pdf_to_imagefield.module \pdf_to_imagefield_convert_pages()
- 7 pdf_to_imagefield.module \pdf_to_imagefield_convert_pages()
Convert pages from pdf file to individual jpeg files
Parameters
$job job definition object, defining the pdf file fid, the field name,: and some processing parameters.
$path folder that the files go into.:
Return value
an array of files, already added to the Drupal files table, that can be added to the node.
1 call to pdf_to_imagefield_convert_pages()
- pdf_to_imagefield_process_pdf in ./
pdf_to_imagefield.module - Given an node and a PDF file to process, do so.
File
- ./
pdf_to_imagefield.module, line 41 - PDF to ImageField core hooks and menu callbacks.
Code
function pdf_to_imagefield_convert_pages($job, $path, $pdf_file) {
$source = $pdf_file['filepath'];
$filepath = $path . '/' . $pdf_file['fid'] . '.jpg';
$extra = array(
'-density ' . $job->density_x . 'x' . $job->density_y,
);
if (!empty($job->extra_args)) {
$extra[] = escapeshellcmd($job->extra_args);
}
watchdog('pdf_to_imagefield', 'Converting PDF [%source] now.', array(
'%source' => $source,
), WATCHDOG_INFO);
pdf_to_imagefield_convert_pdf($source, $filepath, array(), $extra);
// Scan for resulting files.
$converted = array();
// Single page pdfs will have been created with just a filename.
// Multipage results are numbered.
if (file_exists($filepath)) {
$converted[] = pdf_to_imagefield_save_file($filepath);
}
$count = 0;
while (file_exists($path . '/' . $pdf_file['fid'] . '-' . $count . '.jpg')) {
$filepath = $path . '/' . $pdf_file['fid'] . '-' . $count . '.jpg';
$converted[] = pdf_to_imagefield_save_file($filepath);
$count++;
}
return $converted;
}