 +namespace poppler {
 +SimpleDocument::SimpleDocument(const char* buf, size_t length)
 +    : buf_copy_(new char[length]),
-+      stream_(NULL), doc_(NULL), out_dev_(NULL), initer_(NULL) {
++      doc_(NULL), out_dev_(NULL), initer_(NULL) {
 +  initer_ = new initer();
 +  printf("about to do memcpy\n");
 +  memcpy(buf_copy_, buf, length);
 +  printf("memcpy done\n");
 +  Object obj;
 +  printf("about to do memstream\n");
-+  stream_ = new MemStream(buf_copy_, 0, length, obj.initNull());
++  MemStream* stream = new MemStream(buf_copy_, 0, length, obj.initNull());
 +  printf("about to do pdfdoc\n");
-+  doc_ = new PDFDoc(stream_);
++  doc_ = new PDFDoc(stream);  // takes ownership of stream
 +  printf("about to do cairo out dev\n");
 +  out_dev_ = new CairoOutputDev();
 +  printf("about to do start doc on cairo\n");

 namespace poppler
 {
 
@@ -99,6 +105,19 @@ private:
     friend class document_private;
 };
 

+  cairo_restore(cairo);
+  out_dev_->setCairo(NULL);
+}
+
+int SimpleDocument::GetNumPages() {
+  return doc_->getNumPages();
+}
+
+double SimpleDocument::GetPageWidth(int page) {
+  return doc_->getPageCropWidth(page);
+}
+
+double SimpleDocument::GetPageHeight(int page) {
+  return doc_->getPageCropHeight(page);
+}
+
+}  // namespace poppler
diff --git a/cpp/poppler-document.h b/cpp/poppler-document.h
index dfae398..17ca1fc 100644
--- a/cpp/poppler-document.h
+++ b/cpp/poppler-document.h
@@ -19,9 +19,15 @@
