Пример #1
0
gboolean
import_pdf(const gchar *filename, DiagramData *dia, DiaContext *ctx, void* user_data)
{
  PDFDoc *doc;
  GooString *fileName = new GooString(filename);
  // no passwords yet
  GooString *ownerPW = NULL;
  GooString *userPW = NULL;
  gboolean ret = FALSE;

  // without this we will get strange crashes (at least with /O2 build)
  globalParams = new GlobalParams();

  doc = PDFDocFactory().createPDFDoc(*fileName, ownerPW, userPW);
  if (!doc->isOk()) {
    dia_context_add_message (ctx, _("PDF document not OK.\n%s"),
			     dia_context_get_filename (ctx));
  } else {
    DiaOutputDev *diaOut = new DiaOutputDev(dia, doc->getNumPages());

    for (int pg = 1; pg <= doc->getNumPages(); ++pg) {
      Page *page = doc->getPage (pg);
      if (!page || !page->isOk())
        continue;
      doc->displayPage(diaOut, pg,
		       72.0, 72.0, /* DPI, scaling elsewhere */
		       0, /* rotate */
		       gTrue, /* useMediaBox */
		       gTrue, /* Crop */
		       gFalse /* printing */
		       );
    }
    delete diaOut;
    ret = TRUE;
  }
  delete doc;
  delete globalParams;
  delete fileName;

  return ret;
}