I am trying to grab all of the fields of a node (which I am doing by using array_keys). At this point, I want to feed them all to entity_metadata_wrapper(), and grab their values.

I will then, if they are strings, print them to a PDF document using TCPDF's Text() function.

Everything looks like it will work correctly; however, certain fields give an error as such:

EntityMetadataWrapperException: Unknown data property field_grade. in EntityStructureWrapper->getPropertyInfo()

The field exists in my node, though.

'field_grade' => 
    array (size=13)
      'default_value' => null
      'description' => string '' (length=0)
      'display' => 
        array (size=4)

This is the code I am using.

$wrapper = entity_metadata_wrapper('node', $node);
$trip_fields = field_info_instances('node', 'trip');
$trip_fieldskeys = array_keys($trip_fields);
$margintop = 0;

foreach($trip_fieldskeys as $item) {
  $value = $wrapper->$item->value();
  if (gettype($value) == "string") {
    $pdf->Text(0, $margintop, $value, false, false, true, 0, 0,
       '', false, '', 0, false, 'T', 'M', false);
    $margintop = $margintop + 25;
  • Did you solve this? Commented Oct 3, 2014 at 11:35
  • This was a while ago, but I believe so. I'll look up what was done and reply back here in a bit.
    – Jack Ryan
    Commented Oct 6, 2014 at 14:31
  • Is it possible that there are some nodes that you are running through entity_metadata_wrapper() that are missing a value for field_grade? That happened to me recently.
    – rocket
    Commented Oct 24, 2014 at 4:55

3 Answers 3


If it is a custom field that you have defined in your module (using hook_field_info()) then you need to add a property_type to your field info. See https://www.drupal.org/docs/7/api/entity-api/property-info-for-fields for an example and https://www.drupal.org/node/905580 for a full list of possible types.

If your field is a complex (multiple value) data structure you may also additionally need to include property_callbacks as well. See http://d7.thecarneyeffect.co.uk/describe-field-properties-make-custom-fields-work-entity-metadata-wrappers for a good example of this.


I have used FPDI Library for PDF Creation for Particular Content Type Node

    /* PDf Creationg Start */
    $pdf=new PDF_HTML_Table();  
    $pdf->SetTitle('Your Title',false);
    $title_page = 'Dated : '.date('jS F Y');    
    $rows = array();    

  /* Get Node Content */
$query = new EntityFieldQuery();
$query->entityCondition('entity_type', 'node')
  ->entityCondition('bundle', 'your_content_type_name')               
  ->propertyCondition('status', 1, '=')
  ->fieldCondition('field_name', 'value', $_GET['mname'],'=');
  $results = $query->execute();     

    if (isset($results['node'])) {
      $nodes = node_load_multiple(array_keys($results['node']));
       $counter = 0;          
      foreach($nodes as $row) {
          $data = array();  
        if(sizeof($row->your_field_no1) > 0)
                $your_data_array[] = $row->your_field_no1['und'][0]['value'];

       if(sizeof($row->your_field_no2) > 0)
                $your_data_array[] = $row->your_field_no2['und'][0]['value'];
         // and so on..
         $rows[] = $data;

   $filename = "your_desired_name_plus_".date('jS-F-Y-h-i-s').'.pdf';

and it's working on my site... hope this helps


PHP fatal errors when calling $wrapper->field_foo->value() on an empty $wrapper. You need check that node have this field before call $wrapper->field_foo->value(). That Exception handling, be careful with EntityMetadataWrapper. And you can try with:

$wrapper = entity_metadata_wrapper('node', $node);// you need sure with varibale $node
foreach ($wrapper->getPropertyInfo() as $key => $val) {
    $value = $wrapper->$key->value();
    if (gettype($value) == "string") {
   $pdf->Text(0, $margintop, $value, false, false, true, 0, 0,
       '', false, '', 0, false, 'T', 'M', false);
   $margintop = $margintop + 25;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.