function new_page()
 {
     $this->_pdf->close_object();
     // Add the object to the current page
     $this->_pdf->add_object($this->_current_page_id, "add");
     $this->_pdf->new_page();
     Page_Cache::store_page($this->_cache_id, $this->_pdf->get_page_number() - 1, $this->_pdf->serialize_object($this->_current_page_id));
     $this->_current_page_id = $this->_pdf->open_object();
     return $this->_current_page_id;
 }
 static function insert_cached_document(CPDF_Adapter $pdf, $id, $new_page = true)
 {
     $res = self::__query("SELECT font_name FROM page_fonts WHERE id='" . pg_escape_string($id) . "'");
     while ($row = pg_fetch_assoc($res)) {
         $pdf->get_cpdf()->selectFont($row["font_name"]);
     }
     $res = self::__query("SELECT data FROM page_cache WHERE id='" . pg_escape_string($id) . "'");
     if ($new_page) {
         $pdf->new_page();
     }
     $first = true;
     while ($row = pg_fetch_assoc($res)) {
         if (!$first) {
             $pdf->new_page();
         } else {
             $first = false;
         }
         $page = $pdf->reopen_serialized_object($row["data"]);
         $pdf->add_object($page, "add");
     }
 }
  static function insert_cached_document(CPDF_Adapter $pdf, $id, $new_page = true) {
    $res = self::__query("SELECT font_name FROM page_fonts WHERE id='" . pg_escape_string($id) . "'");

    // Ensure that the fonts needed by the cached document are loaded into
    // the pdf
    while ($row = pg_fetch_assoc($res))
      $pdf->get_cpdf()->selectFont($row["font_name"]);

    $res = self::__query("SELECT data FROM page_cache WHERE id='" . pg_escape_string($id) . "'");

    if ( $new_page )
      $pdf->new_page();

    $first = true;
    while ($row = pg_fetch_assoc($res)) {

      if ( !$first )
        $pdf->new_page();
      else
        $first = false;

      $page = $pdf->reopen_serialized_object($row["data"]);
      //$pdf->close_object();
      $pdf->add_object($page, "add");

    }

  }