public function __toString()
{
// Format the content objects.
$content_objs = implode(" 0 R ", $this->content);
$content_objs .= " 0 R";
// Format the annotations.
if (count($this->annots) > 0) {
$annots = '/Annots[';
$annots .= implode(" 0 R ", $this->annots);
$annots .= " 0 R]";
} else {
$annots = '';
}
// Format the xobjects.
if (count($this->xobjs) > 0) {
$xobjects = '/XObject<<';
$xobjects .= implode('', $this->xobjs);
$xobjects .= '>>';
} else {
$xobjects = '';
}
// Format the fonts.
if (count($this->fonts) > 0) {
$fonts = '/Font<<';
$fonts .= implode('', $this->fonts);
$fonts .= '>>';
} else {
$fonts = '';
}
// Swap out the placeholders.
$obj = str_replace('[{page_index}]', $this->index, $this->data);
$obj = str_replace('[{parent}]', $this->parent, $obj);
if ($annots != '' && strpos($obj, '[{annotations}]') === false) {
$obj = str_replace('/MediaBox', $annots . '/MediaBox', $obj);
} else {
$obj = str_replace('[{annotations}]', $annots, $obj);
}
if ($xobjects != '' && strpos($obj, '[{xobjects}]') === false) {
$obj = str_replace('/ProcSet', $xobjects . '/ProcSet', $obj);
} else {
$obj = str_replace('[{xobjects}]', $xobjects, $obj);
}
if ($fonts != '' && strpos($obj, '[{fonts}]') === false) {
$obj = str_replace('/ProcSet', $fonts . '/ProcSet', $obj);
} else {
$obj = str_replace('[{fonts}]', $fonts, $obj);
}
$obj = str_replace('[{content_objects}]', $content_objs, $obj);
return $obj;
}