lilypond-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Rendering cropped SVG


From: David Wright
Subject: Re: Rendering cropped SVG
Date: Thu, 17 Sep 2015 10:33:43 -0500
User-agent: Mutt/1.5.21 (2010-09-15)

> > Am 17.09.2015 um 03:08 schrieb David Wright <address@hidden>:
> > 
> > I wrote earlier:
> >>>> After all, in your script you have:
> >>>> pdfcrop --margins 1 '$file_base_name.pdf' '$file_base_name.pdf'
> >>>> where the output filename is the same as the input filename.
> > 
> > Well I'm still worried about the line I quoted above, which I think is
> > inviting trouble (unless you clearly understand the mechanism that is
> > being used). Bear in mind, in my script I used an intermediate file:
> > $ pdfcrop --margins 1 foo.pdf bar.pdf

Quoting address@hidden (address@hidden):
> Apparently I don't clearly understand the mechanism.
> Why can't the program write the cropped pdf to the same file?

When you're lucky, the program will read a small input file and, if
you're really lucky, close it before opening the output file, doing
the processing and then writing the output.

In general, programs aren't designed to do that because it limits the
quantity of input to what will fit in memory. pdfcrop is designed to
handle arbitrarily large input files and, indeed, it will handle
input from a pipe (which means it has no idea how much input there
will eventually be). Also consider what happens if you press ^C
halfway through the process: you've destroyed the input file.

That's dealing with only a tiny part of the file-handling
implications, and doesn't even consider file-locking on some OSes
which will prevent your opening a file for writing when it's already
open for reading. But now look at it from a naive point of view. You
assume that less data has been written than has been read at *all*
times during the process (as well by the end). Can you guarantee that?

These filesizes might surprise you (they did me):

Input file, the moderately-sized Lua Reference Manual,
obviously output from the TeX family
474818  refman-5.0.pdf

Output from   $ pdfcrop --margins 1 refman-5.0.pdf via-file
4709449 via-file

Output from   $ pdfcrop --margins 1 - via-pipe < refman-5.0.pdf
4709378 via-pipe

So with your script, you're likely to come a cropper one day.
(Sorry, had to get that in!) If you're going to write a script,
always use the most conservative assumptions, not short-cuts.
And before you try to debug a script with a possible race-condition,
you need to remove any obvious potential sources for the problem.

Cheers,
David.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]