I've an image I made with Inkscape and exported to PDF that I want to include in my document. However, there is one annoying thing: The line width (e.g. the border width of a rectangle) depends on the scaling of the PDF. For example, when I include it two times like this
\includegraphics[width=1.00\textwidth]{Example.pdf}
\includegraphics[width=0.50\textwidth]{Example.pdf}
the lines in the upper image are thicker than in the lower.
Can I override the line width somehow such that it is always, say, 1mm, regardless of the scaling or (re)define the base that is used to calculate the actucal width?
Best Answer
In general the answer is no. Very often the line width is explicitly set in the
.pdf
file. This setting will overwrite any setting that the TeX file might have set before.With knowledge of PDF internals and PDF page stream operators, sometimes the
.pdf
file can be tweaked. Lets take a simple PostScript file:Then the program epstopdf calls ghostscript and generates a
.pdf
file. Since we need to take a look at the page stream, it can be uncompressed byThe page stream can be found via the
/Contents
key in the/Page
object (here annotated by comments, sometimes with corresponding PostScript operators):Here ghostscript has added a line width setting, the PostScript file didn't set the line width. It can be removed by commenting or overwriting with spaces. It is very important that the size of the object is not changed, otherwise many other settings needs updating:
/Length
in the dict stream object.xref
table.Example for disabling the line width setting (
%
is the comment char in both PostScript and PDF):Optionally the modified
.pdf
file can be recompressed, see above the command line withpdftk
.The following example uses pdfTeX. Since we do not want to keep the changed settings after the graphics (and to surprise pdfTeX), the changed settings are put between a
save
/restore
pair, in pdfTeX:\pdfsave
/\pdfrestore
. However this also affects the current point, the two primitives must be called at the exact same point. Otherwise the synchronization of TeX internal coordinate system and the coordinate system of the PDF output is lost.Several problems/drawbacks can be seen:
The media size/bounding box of the included
.pdf
file is not changed. That is seen by TeX. If the line width is changed, then the bounding box might change. Optiontrim
can help here: positive values, if the line width is smaller than the original or negative values if the bounding box increases. Sometimes the values can be easily calculated, otherwise it can be measured visually (e.g.:\fbox
with\setlength{\fboxsep}{0pt}
). Depending on the image, the values can even be different for the four sides.Even, if the line width is the same, the scaled image can look quite different, because the proportions from line width and shape are different, if the shape is scaled.