Message Boards Message Boards

How to fit a Dataset output in a PDF file?

Posted 3 years ago
POSTED BY: Jürgen Kanz
15 Replies

You might want to try ItemSize option to resize all columns. For example:

Dataset[{
   <|"a" -> 1, "b" -> "x", "c" -> {1}|>,
   <|"a" -> 2, "b" -> "y", "c" -> {2, 3}|>,
   <|"a" -> 3, "b" -> "z", "c" -> {3}|>,
   <|"a" -> 4, "b" -> "x", "c" -> {4, 5}|>,
   <|"a" -> 5, "b" -> "y", "c" -> {5, 6, 7}|>,
   <|"a" -> 6, "b" -> "z", "c" -> {}|>
    },
    ItemSize->10
]

enter image description here

POSTED BY: Sa'di Altamimi

Hi all,

if it is just about the Dataset only - how about displaying the Dataset in all its beauty (using the option MaxItems -> {All, All}) and then simply export it as PDF?

(* creating "large" test-Dataset: *)
{dimx, dimy} = {25, 30};
rowKeys = RandomWord[dimy];
colKeys = RandomWord[dimx];
dataset = 
 Dataset[AssociationThread[rowKeys, 
   Table[AssociationThread[colKeys, RandomReal[{0, 1}, dimx]], dimy]],
   MaxItems -> {All, All}]
(* ... and exporting it: *)
Export["ds.pdf", dataset]
POSTED BY: Henrik Schachner
POSTED BY: Jürgen Kanz

Hello Juergen, yes, yes, some time after my post I got that feeling that I might have misunderstood something. But thanks for your nice response!

POSTED BY: Henrik Schachner

You are always welcome.

POSTED BY: Jürgen Kanz

Glad I could help.

I use the same technique to export other graphics for import into other programs. For example, if you export plots with huge amounts of points and import them into Microsoft Word, you can slow Word and actually crash it. Every single point is exported as a separate line even if not visible. If you rasterize and export as tiff or jpg or pdf, everything is fine and you can make sure you get great resolution.

Regards

Neil

POSTED BY: Neil Singer

Jürgen,

I recommend rasterizing the dataset in Mathematica and controlling the output. I started with a dummy dataset.

dataset = Dataset[{
    <| "min" -> <|"aaaaaaaaaaaaaaaaaaaaa" -> RandomReal[], 
       "baaaaaaaaaaaaaaaaaaaa" -> "xxxxx", 
       "caaaaaaaaaaaaaaaaaaaa" -> RandomReal[], 
       "daaaaaaaaaaaaaaaaaaaa" -> RandomReal[], "e" -> RandomReal[], 
       "f" -> RandomReal[], "g" -> RandomReal[]|>|>,
    <| "max" -> <|"aaaaaaaaaaaaaaaaaaaaa" -> RandomReal[], 
       "baaaaaaaaaaaaaaaaaaaa" -> "yyyyy", 
       "caaaaaaaaaaaaaaaaaaaa" -> RandomReal[], "e" -> RandomReal[], 
       "daaaaaaaaaaaaaaaaaaaa" -> RandomReal[], "f" -> RandomReal[], 
       "g" -> RandomReal[]|>|>,
    <| "median" -> <|"aaaaaaaaaaaaaaaaaaaaa" -> RandomReal[], 
       "baaaaaaaaaaaaaaaaaaaa" -> "zzzzz", 
       "caaaaaaaaaaaaaaaaaaaa" -> RandomReal[], "e" -> RandomReal[], 
       "daaaaaaaaaaaaaaaaaaaa" -> RandomReal[], "f" -> RandomReal[], 
       "g" -> RandomReal[]|>|>,
    <| "SDSDSDSDSDSDSDSDSDSDSDSDSDSDSD" -> <|
       "aaaaaaaaaaaaaaaaaaaaa" -> RandomReal[], 
       "baaaaaaaaaaaaaaaaaaaa" -> "xxxxx", 
       "caaaaaaaaaaaaaaaaaaaa" -> RandomReal[], "e" -> RandomReal[], 
       "daaaaaaaaaaaaaaaaaaaa" -> RandomReal[], "f" -> RandomReal[], 
       "g" -> RandomReal[]|>|>,
    <| "var" -> <|"aaaaaaaaaaaaaaaaaaaaa" -> RandomReal[], 
       "baaaaaaaaaaaaaaaaaaaa" -> "yyyyy", 
       "caaaaaaaaaaaaaaaaaaaa" -> RandomReal[], "e" -> RandomReal[], 
       "daaaaaaaaaaaaaaaaaaaa" -> RandomReal[], "f" -> RandomReal[], 
       "g" -> RandomReal[]|>|>,
    <| "max" -> <|"aaaaaaaaaaaaaaaaaaaaa" -> RandomReal[], 
       "baaaaaaaaaaaaaaaaaaaa" -> "zzzzz", 
       "caaaaaaaaaaaaaaaaaaaa" -> RandomReal[], "e" -> RandomReal[], 
       "daaaaaaaaaaaaaaaaaaaa" -> RandomReal[], "f" -> RandomReal[], 
       "g" -> RandomReal[]|>|>}];

Rasterize the dataset to whatever resolution and ultimate size you want.

dataRasterized = 
 Rasterize[dataset, ImageSize -> 1000, ImageResolution -> 300]

and create the PDF file from that:

Export["mypdf.pdf", dataRasterized]

Regards,

Neil

POSTED BY: Neil Singer
POSTED BY: Jürgen Kanz
Posted 3 years ago
POSTED BY: Rohit Namjoshi

Thank you, Rohit!

Yes, with Magnify[] it is possible to get impact on the dataset output size, but it is not satisfying. Please have a look:

It was my first attempt to work with Magnify[dataset, GoldenRatio]. Looks good in the *.nb but not in PDF: enter image description here Only half of the table is visible.

Afterwards, I tried several magnifications factors. Unfortunately, it was not possible to show the entire dataset in PDF. One example: Magnify[dataset, 0.4] in the notebook enter image description here

Finally, Magnify[dataset, 0.4] in PDF: enter image description here

It seems to me that something is happening regarding the AspectRatio of the output during the translation to PDF.

Any other idea?

POSTED BY: Jürgen Kanz
Posted 3 years ago

You could try to change the page orientation to Landscape before saving as pdf:

enter image description here

enter image description here

POSTED BY: Hans Milton

Good idea, Hans!

In my current case, it would solve the problems because I have only 6 to 7 data columns in my Dataset[]. If I would have more columns then I would go in trouble again. Please have a look at a modified dataset printed as PDF in Landscape mode. enter image description here

POSTED BY: Jürgen Kanz
Posted 3 years ago

When needed you can change to a larger paper size. For example A3:

enter image description here

POSTED BY: Hans Milton

Did you use Grid[] for the tables?

POSTED BY: Raspi Rascal

Yes, I have tried, but it does not solve the problem.

Thanks!

POSTED BY: Jürgen Kanz
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract