+/* EvFileExporterIface */
+static gboolean
+djvu_document_file_exporter_format_supported (EvFileExporter *exporter,
+ EvFileExporterFormat format)
+{
+ return (format == EV_FILE_FORMAT_PS); // only exporting to PS is implemented.
+}
+
+static void
+djvu_document_file_exporter_begin (EvFileExporter *exporter,
+ EvFileExporterFormat format,
+ const char *filename, /* for storing the temp ps file */
+ int first_page,
+ int last_page,
+ double width,
+ double height,
+ gboolean duplex)
+{
+ DjvuDocument *djvu_document = DJVU_DOCUMENT (exporter);
+
+ if (djvu_document->ps_filename)
+ g_free (djvu_document->ps_filename);
+ djvu_document->ps_filename = g_strdup(filename);
+
+ g_string_assign(djvu_document->opts, "-page=");
+}
+
+static void
+djvu_document_file_exporter_do_page (EvFileExporter *exporter,
+ EvRenderContext *rc)
+{
+ DjvuDocument *djvu_document = DJVU_DOCUMENT (exporter);
+
+ g_string_append_printf(djvu_document->opts, "%d,", (rc->page) + 1);
+}
+
+static void
+djvu_document_file_exporter_end (EvFileExporter *exporter)
+{
+ int d_optc = 1;
+ const char *d_optv[d_optc];
+
+ DjvuDocument *djvu_document = DJVU_DOCUMENT (exporter);
+
+ FILE *fn = fopen(djvu_document->ps_filename, "w");
+ if (fn == NULL) {
+ g_warning(_("Cannot open file ā%sā."), djvu_document->ps_filename);
+ return;
+ }
+
+ d_optv[0] = djvu_document->opts->str;
+
+ ddjvu_job_t * job = ddjvu_document_print(djvu_document->d_document, fn, d_optc, d_optv);
+ while (!ddjvu_job_done(job) ) {
+ djvu_handle_events (djvu_document, TRUE);
+ }
+
+ fclose(fn);
+}
+
+static void
+djvu_document_file_exporter_iface_init (EvFileExporterIface *iface)
+{
+ iface->format_supported = djvu_document_file_exporter_format_supported;
+ iface->begin = djvu_document_file_exporter_begin;
+ iface->do_page = djvu_document_file_exporter_do_page;
+ iface->end = djvu_document_file_exporter_end;
+}
+