Is there a sensible way to make this module process pdfs, even if there are already imagefield images in the node?

I notice that, if a previous conversion has been done, further pdfs added won't get converted (I guess it checks if an image exists, and if it does it doesn't process).

I wouldn't mind if the whole process was re-done, for all pdfs present. At the moment the only way round this is to delete all imagefield images first before Save.

Comments

dman’s picture

Yes, if an imagefield exists, that means it's done its process and won't do it again.
As we can't tell if the image is still valid - without actually re-rendering it every time ... and not even then - Doing it this way is a simple answer to a hard question.

I think the only reasonable solution (which will also address the 'what if I change the PDF' issue is to add a button or tab the just forces all the images to be discarded and the PDF to be rebuilt on demand.

mikeaja’s picture

Thanks for the answer.

Would there be anyway of forcing it to re-render every time? This would do fine (even it it re-rendered on every edit, regardless of if changed or not).

I'll look at a discard all images button also, in case.

Gr3fweN’s picture

I would like to have it forced also (nice if it could be toggled in settings) for 7.x

devkinetic’s picture

Issue summary: View changes

I've added a toggle to the filefield settings:

function pdf_to_imagefield_widget_settings_form($widget) {
  $form['reprocess'] = array(
    '#type' => 'checkbox',
    '#title' => t('Always reprocess ImageField'),
    '#default_value' => !empty($widget['reprocess']) ? $widget['reprocess'] : 0,
    '#description' => t('Reprocess the ImageField each time the node is saved.'),
  );

And then you add a check to node_presave before the first if().

$reprocess = $source_filefield_def['widget']['reprocess'];

  // Should we always reprocess the PDF file? If so delete the existing image(s).
  if ($reprocess) {
    watchdog('pdf_to_imagefield', 'Deleting all the image fields previously attached to %title as derivatives of the deleted PDF file.', array('%title' => $node->title), WATCHDOG_NOTICE);
    foreach ($node->{$target_imagefield} as $i => $image_file ) {
      $removed_file = field_file_load($image_file['fid']);
      field_file_delete($image_file);
      $node->{$target_imagefield}[$i] = array(
        'fid' => null,
        'list' => null,
        'data' => null,
      );
    }
  }

Finally, add $reprocess to the fieldfield save hook.

 function pdf_to_imagefield_widget_settings_save($widget) {
   $filefield_settings = module_invoke('filefield', 'widget_settings', 'save', $widget);
  return array_merge($filefield_settings, array('target_imagefield', 'reprocess', 'density'));
 }

This isn't an end all solution, but I'm just using this for one pdf on an dated D6 site. This could be extended to the node level, rather than the field definition level quite easily.

hitchshock’s picture

Status: Active » Closed (outdated)

We stopped supporting the D7 version, so the ticket will be closed

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.