How can I include the (approximate) file size of the generated pdf within a pdflatex document? I envision having to compile it three times: once to create the pdf, a second time to write the size to an .aux file and the third pass will include it in the document. A minimal working example would be pedagogic and useful!
|
|
||||
|
|
You test the existence of the PDF file produced in the previous run before It won't be accurate to the byte, because of compression. I get
in successive runs over the document. Dividing by 1024 and rounding could be better:
|
|||
|
|
|
Here is an implementation in ConTeXt MkIV. I use The filesize never stabilizes! Here is the implementation.
Starting in a scratch directory, compiling the file and grepping for
As can be seen, even after 8 runs, the file size has not stabilized. I ran it again (without deleting any temporary file) and get
So, even after 16 runs, the file size has not stabilized. I thought that the oscillation in file size is because the pdf output is compressed. I added
on top of the file, and started from scratch again. This time I get
Again, an oscillating file size and I don't know why that is happening. So, in the end I decided to round the file size in kilo bytes, by diving the file size by
This time, as expected, the compilation stops after three runs.
|
|||
|
|
|
The file size does not stabilise because of how pdf compresses (the digits). As soon as you enter a new file size (with different digits), it compresses differently when converted to pdf. For example, this code:
and this code:
will produce files of equal size but this code:
will produce a pdf file of a different size. So when you insert this new size into the document, just because the digits are different from the last time, it will produce a pdf file of a different size. However, you might find that after a number of iterations, the pdf file size appears to cycle through the same numbers. |
||||
|
|