Save file in PDF format

Asked by gcclinux

The software is great and with the Brother drivers I downloaded a long time ago it works perfectly with the DCP-770CW model. My only request in properties if possible it to add format field so we can select jpg or pdf

I would like to be able to save all my files in pdf format.

Many Thanks

Question information

Language:
English Edit question
Status:
Answered
For:
Simple Scan Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
Michael Nagel (nailor) said :
#1

if you specify a file name ending in .pdf you will get a PDF file already (works with various other file extensions as well).
what you currently cannot do is that you cannot permanently change the default file type used for saving.

Revision history for this message
Stefan Wagner (wagner-stefan) said :
#2

I nearly never want to save files as PDF but as jpg or PNG. I would like to have a permanent setting in a config file, or a settings dialog to save it, or a connection Image<=>JPG, Text<=>PDF. But it is always PDF.

Revision history for this message
fred.thomas (fred-thomas-5of9au84) said :
#3

This annoys me also. I had a look at the source. The file to change is "ui.vala", in this section (code below).
The line that sets the default file name is:
        save_dialog.set_current_name (_("Scanned Document.pdf"));
I tried changing that string in the binary to "Scanned Document.jpg". The save as box shows the jpg filename but at the bottom, PDF is still the format. So that trick failed. The logic at some other stage must still decide to saved it as a PDF. Changing the source code logic and recompiling would be needed and I don't know how to do that.... yet. :-)

---- code below ----

    private string choose_file_location ()
    {
        /* Get directory to save to */
        string? directory = null;
        directory = settings.get_string ("save-directory");

        if (directory == null || directory == "")
            directory = Environment.get_user_special_dir (UserDirectory.DOCUMENTS);

        save_dialog = new Gtk.FileChooserDialog (/* Save dialog: Dialog title */
                                                 _("Save As..."),
                                                 this,
                                                 Gtk.FileChooserAction.SAVE,
                                                 _("_Cancel"), Gtk.ResponseType.CANCEL,
                                                 _("_Save"), Gtk.ResponseType.ACCEPT,
                                                 null);
        save_dialog.do_overwrite_confirmation = true;
        save_dialog.local_only = false;
        save_dialog.set_current_folder (directory);
        /* Default filename to use when saving document */
        save_dialog.set_current_name (_("Scanned Document.pdf"));

        /* Filter to only show images by default */
        var filter = new Gtk.FileFilter ();
        filter.set_filter_name (/* Save dialog: Filter name to show only image files */
                                _("Image Files"));
        filter.add_pixbuf_formats ();
        filter.add_mime_type ("application/pdf");
        save_dialog.add_filter (filter);
        filter = new Gtk.FileFilter ();
        filter.set_filter_name (/* Save dialog: Filter name to show all files */
                                _("All Files"));
        filter.add_pattern ("*");
        save_dialog.add_filter (filter);

        var file_type_store = new Gtk.ListStore (2, typeof (string), typeof (string));
        Gtk.TreeIter iter;
        file_type_store.append (out iter);
        file_type_store.set (iter,
                             /* Save dialog: Label for saving in PDF format */
                             0, _("PDF (multi-page document)"),
                             1, ".pdf",
                             -1);
        file_type_store.append (out iter);
        file_type_store.set (iter,
                             /* Save dialog: Label for saving in JPEG format */
                             0, _("JPEG (compressed)"),
                             1, ".jpg",
                             -1);
        file_type_store.append (out iter);
        file_type_store.set (iter,
                             /* Save dialog: Label for saving in PNG format */
                             0, _("PNG (lossless)"),
                             1, ".png",
                             -1);

        var box = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 6);
        box.visible = true;
        save_dialog.set_extra_widget (box);

        /* Label in save dialog beside combo box to choose file format (PDF, JPEG, PNG) */
        var label = new Gtk.Label (_("File format:"));
        label.visible = true;
        box.pack_start (label, false, false, 0);

        var file_type_combo = new Gtk.ComboBox.with_model (file_type_store);
        file_type_combo.visible = true;
        var renderer = new Gtk.CellRendererText ();
        file_type_combo.pack_start (renderer, true);
        file_type_combo.add_attribute (renderer, "text", 0);

        file_type_combo.set_active (0);
        file_type_combo.changed.connect (() =>
        {
            var extension = "";
            Gtk.TreeIter i;
            if (file_type_combo.get_active_iter (out i))
                file_type_store.get (i, 1, out extension, -1);

            var path = save_dialog.get_filename ();
            var filename = Path.get_basename (path);

            /* Replace extension */
            var extension_index = filename.last_index_of_char ('.');
            if (extension_index >= 0)
                filename = filename.slice (0, extension_index);
            filename = filename + extension;
            save_dialog.set_current_name (filename);
        });
        box.pack_start (file_type_combo, false, false, 0);

        var response = save_dialog.run ();

        string? uri = null;
        if (response == Gtk.ResponseType.ACCEPT)
        {
            var extension = "";
            Gtk.TreeIter i;
            if (file_type_combo.get_active_iter (out i))
                file_type_store.get (i, 1, out extension, -1);

            var path = save_dialog.get_filename ();
            var filename = Path.get_basename (path);

            var extension_index = filename.last_index_of_char ('.');
            if (extension_index < 0)
                path += extension;

            uri = File.new_for_path (path).get_uri ();
        }

        settings.set_string ("save-directory", save_dialog.get_current_folder ());

        save_dialog.destroy ();
        save_dialog = null;

        return uri;
    }

Revision history for this message
Rolf (thats-unpossible) said :
#4

I was able to modify the code to make the default .jpg. Here's the patch against the most recent master.

$ git diff
diff --git a/src/app-window.vala b/src/app-window.vala
index 94aacd8..551f71c 100644
--- a/src/app-window.vala
+++ b/src/app-window.vala
@@ -307,7 +307,7 @@ public class AppWindow : Gtk.ApplicationWindow
         else {
             save_dialog.set_current_folder (directory);
             /* Default filename to use when saving document */
- save_dialog.set_current_name (_("Scanned Document.pdf"));
+ save_dialog.set_current_name (_("Scanned Document.jpg"));
         }

         /* Filter to only show images by default */
@@ -331,12 +331,6 @@ public class AppWindow : Gtk.ApplicationWindow
         Gtk.TreeIter iter;
         file_type_store.append (out iter);
         file_type_store.set (iter,
- /* Save dialog: Label for saving in PDF format */
- 0, _("PDF (multi-page document)"),
- 1, ".pdf",
- -1);
- file_type_store.append (out iter);
- file_type_store.set (iter,
                              /* Save dialog: Label for saving in JPEG format */
                              0, _("JPEG (compressed)"),
                              1, ".jpg",
@@ -347,6 +341,12 @@ public class AppWindow : Gtk.ApplicationWindow
                              0, _("PNG (lossless)"),
                              1, ".png",
                              -1);
+ file_type_store.append (out iter);
+ file_type_store.set (iter,
+ /* Save dialog: Label for saving in PDF format */
+ 0, _("PDF (multi-page document)"),
+ 1, ".pdf",
+ -1);
 #if HAVE_WEBP
         file_type_store.append (out iter);
         file_type_store.set (iter,

Revision history for this message
Stefan Wagner (wagner-stefan) said :
#5

@Rolf (thats-unpossible)

That's a nice idea, but of course not a solution for the underlying problem. I think it should be configurable, at least via a config file per user.

But thanks for the effort. I meanwhile switched to the xsane program, where there are other issues. For instance, the size to scan - I mostly choose A5 wide, but it is ordered from - I think A0 - and always starts in default state, not in the last state left.

I found a file, where I could change the ordering, except for the first entry - then it crashed. :) But now my favorite is at position 2 and I don't need to scroll that wide all the time.

Can you help with this problem?

Provide an answer of your own, or ask gcclinux for more information if necessary.

To post a message you must log in.