WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: [Solved] how to change default filename for gtk3 print dialog's "Print to File"?  (Read 1352 times)

Offline GNUser

  • Wiki Author
  • Hero Member
  • *****
  • Posts: 1530
Hello, friends. Many gtk3 applications (e.g., brave with --disable-print-preview flag, geany) bring up gtk3's print dialog when user presses Ctrl+p.

The gtk3 print dialog uses ~/Documents/output.pdf as a default output filename across all applications I've tried:



Does anyone whether this default can be changed? I'm specifically trying to change the default directory. I know I can click on the filename and change the directory that way, but doing this repeatedly is tiresome.

I found some promising-sounding variables named GTK_PRINT_SETTINGS_OUTPUT_FOO and G_USER_DIRECTORY_DOCUMENTS here but, alas, setting and exporting those variables has no effect.

My hope is that someone knows an easy way to change the default ~/Documents/output.pdf to something else--for example, with an environmental variable or a setting in ~/.config/gtk-3.0/settings.ini. If someone knows for a fact that this default filename is hardwired into gtk3, that would also be helpful to know (so that I stop trying to customize this--recompiling gtk3 for this purpose is not something I want to do).
« Last Edit: March 19, 2024, 09:59:29 PM by Rich »

Offline GNUser

  • Wiki Author
  • Hero Member
  • *****
  • Posts: 1530
Sorry, I forgot to mention I'm on TCL15 x86_64. All relevant extensions are from the official repository (gtk3 v3.24.39, geany v1.37, brave-browser v1.63.174).

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11694
Hi GNUser
I just hit Ctrl-P while in Firefox. The Firefox print dialog opened up.
It had a "Print using the system dialog" Clicking that link brought
up the gtk3 print dialog. When I selected "Print to File", it defaulted
to  "~/mozilla.pdf".  That makes me suspect it might get set by the
application.

Offline GNUser

  • Wiki Author
  • Hero Member
  • *****
  • Posts: 1530
Firefox ... "~/mozilla.pdf".
Interesting. Thank you for sharing this data point.

That makes me suspect it might get set by the application.
Either that or gtk3 provides a mechanism for an application to specify a filename, with "~/Documents/output.pdf" serving as a fallback/default if the application does not specify anything. Given that geany and brave-browser both suggest "~/Documents/output.pdf", I favor my theory that a default exists. But I guess without studying gtk3's source code, it's hard to be sure either way.

EDIT:
I took another look at https://wiki.gnome.org/Initiatives/GnomeGoals/PrintToFile . Part of the document reads: The GTK+-provided fallback, '~/Documents/output.pdf'. So it does seem that, while an application can override it, "~/Documents/output.pdf" is the default filename for "Print to File".
« Last Edit: March 19, 2024, 03:29:28 PM by GNUser »

Offline GNUser

  • Wiki Author
  • Hero Member
  • *****
  • Posts: 1530
Hi, Rich. I found that some applications (e.g., Thunderbird and Firefox) allow the user to specify the desired default filename. See here.

Unfortunately, I don't think the two applications I am interested in (geany and brave-browser) offer such a setting. For me, it seems that I'm going to have to change this in gtk3 if at all.
« Last Edit: March 19, 2024, 03:11:01 PM by GNUser »

Offline GNUser

  • Wiki Author
  • Hero Member
  • *****
  • Posts: 1530
I found an acceptable solution.

gtk3 is hardwired to use $XDG_DOCUMENTS_DIR/output.pdf as default filename for "Print to File".

XDG_DOCUMENTS_DIR can be customized in ~/.config/user-dirs.dirs. With this, for example:

Code: [Select]
$ cat ~/.config/user-dirs.dirs
XDG_DOCUMENTS_DIR="$HOME/my_favorite_directory"
the default filename for "Print to File" (for applications that don't specify a default filename, such as geany and brave-browser) becomes $HOME/my_favorite_directory/output.pdf.

This solution may have some side effects, but it is good enough for me. Topic may be marked as solved.