Wie kann ein Bilddiagramm mit skalierten Abmessungen in ein PDF ohne Glättungseffekte eingebettet werden?

598
ws_e_c421

Ich muss eine Bilddarstellung der Daten als PDF erstellen. Die Daten enthalten eine kleine Anzahl von Pixeln (ungefähr 100 x 100), sodass jedes Pixel erkennbar ist (kein glattes Bild). Ich habe versucht, ein PDF mit ein paar verschiedenen wissenschaftlichen Computerprogrammen zu exportieren, aber wenn ich mir das PDF in OS X Preview oder dem Firefox-Plugin pdf.js ansehe, sehen die Daten schlecht aus. Jedes einzelne Pixel von Daten sieht so aus, als ob es entlang einer Dimension in etwa fünf Pixel und in der anderen in drei Pixel aufgeteilt wurde (das Seitenverhältnis ist nicht 1: 1 in der Abbildung). Diese Subpixel haben etwas andere Farben, so dass die Daten unscharf werden . Ich habe versucht, das PDF in Inkscape zu öffnen, und dort sieht es gut aus. Von Inkscape aus habe ich festgestellt, dass die Daten als 100 x 100 Pixel png eingebettet werden, was in der Vorschau gut aussieht, wenn ich sie aus dem PDF-Dokument extrahiere und selbst ansehe.

Was ist also die beste Option, um ein pdf mit einem scharfen Datendiagramm zu erhalten? Fürs Erste werde ich eine überabgetastete PNG der Daten erstellen und diese in pdf einbetten. Diese Lösung gefällt mir nicht besonders gut, da dadurch die Dateigröße der Figur unnötig groß wird und das Bild beim Zoomen immer noch unscharf ist. Sollte es möglich sein, das PDF-Dokument zum Rendern eines gestreckten Bildes ohne Glätten zu erhalten? Formatieren meine Scientific Computing-Programme (Igor Pro und MATLAB) die PDF-Datei nicht ordnungsgemäß, oder werden Vorschau und Firefox nicht korrekt dargestellt, indem sie geglättet werden?

2

1 Antwort auf die Frage

1
ws_e_c421

Okay, I finally found the answer to this question in a couple posts on the TeX section of stackexchange: My pixel perfect picture gets blurry when compiled in LaTeX and Included PNG appears blurry in PDF.

Summary of those posts: many PDF viewers have an optional setting to smooth PDF output ("Smooth text and line art" in OS X Preview, "Anti-alias text and line art" in Skim; some programs like Firefox's pdf.js extension have this setting on without an obvious way to disable it; others like Google Chrome's pdf viewer do not seem to have this setting; note that the Preview and Skim setting names are misleading because raster images, not just line are, are smoothed if this setting is enabled). For the programs that do have this setting, disabling the setting makes the embedded image look good, but other aspects of the pdf (and other pdfs) will not look as good (text will be pixelated etc.). The PDF format does not have an internal option for telling the viewer program not to anti-alias an element (perhaps one day...), so it seems like for now the solution I described above is actually the method that is typically used for embedding pixelated images into pdfs: oversample the image to the required resolution*.

The other option is to convert the image into a vector image of colored rectangles. I experimented with this method with Inkscape (use the trace option of the tile clone method to clone a single pixel rectangle over the image; see this documentation page for some of the details), but because this method requires specifying all of the coordinates of each pixel's rectangle object it ends up being much less efficient disk space wise compared to embedding a raster image.

* One way to oversample an image is to use ImageMagick with the sample flag setting the dimensions to higher multiples of the base image's dimensions. Note that you need a \! after the new dimensions if you want to change the aspect ratio (e.g. if you stretch out the image in the pdf, you might want to make each original pixel ten pixels wide but only three pixels high).