WeasyPrint icon indicating copy to clipboard operation
WeasyPrint copied to clipboard

allow no output filename

Open vpoulailleau opened this issue 9 months ago • 5 comments

Allow to call weasyprint CLI without output filename. The default output filename is input filename followed by .pdf.

(Everytime I use weasyprint, I forget to provide output filename…)

vpoulailleau avatar Mar 20 '25 12:03 vpoulailleau

Hi,

Thanks for this pull request! 🙏🏽

That’s a good idea, but I have some concerns about the current implementation:

  • When document.html is given, I think I’d prefer to get document.pdf, not document.html.pdf.
  • When a URL is given (for example weasyprint https://weasyprint.org/), we currently get a crash.

We can first decide which "good" filename we want to get for these common cases (and maybe look at what other widely used tools do):

  • document
  • document.html
  • ../../folder/document.html
  • https://example.org/
  • https://example.org/index
  • https://example.org/index.php
  • https://example.org/index.php?a=b&c=d
  • … (you’ll for sure find other ones!)

And then, we’ll find a simple, clean and reliable way to get this! 😄

liZe avatar Mar 27 '25 17:03 liZe

Hello, who was that question for? Here is my unrequested opinion:

source target
document.html ./document.pdf
document ./document.pdf
document.foo ./document.pdf
document.foo.bar ./document.foo.pdf
../../folder/document.html ./document.pdf (*)
https://example.org/ ./output.pdf (or some other default)
https://example.org/path/index ./index.pdf
https://example.org/path/index.php ./index.pdf
https://example.org/path/index.php?a=b&c=d ./index.pdf
https://example.org/path/index#a=b;c=d ./index.pdf

(*) not sure of this, but I think that's a good choice about write permissions on filesystem

luca-vercelli avatar Jun 12 '25 15:06 luca-vercelli

@liZe I don't have the time right now, maybe in july. The suggestions of @luca-vercelli look good to me. What do you think?

vpoulailleau avatar Jun 12 '25 19:06 vpoulailleau

@liZe I don't have the time right now, maybe in july. The suggestions of @luca-vercelli look good to me. What do you think?

@vpoulailleau Looks good to me. You can write a dedicated function for that, so that we can easily test it.

(I really hope that it won’t be too complex though. Comments like the ones in this thread may help to find corner cases.)

liZe avatar Jun 12 '25 19:06 liZe

about the case of ../../folder/document.html, I agree with you, not necessarily because of permissions but simply because the default behavior most users expect (and is what most programs implement, I believe) is that if you run a process in a directory, the output will be in that directory.

Firefly7-7 avatar Aug 05 '25 05:08 Firefly7-7