Message Boards Message Boards

GROUPS:

How to fit a Dataset output in a PDF file?

Posted 9 months ago
3046 Views
|
15 Replies
|
9 Total Likes
|

I need help regarding the following problem:

In my notebook I am creating several datasets and I show the output, as you can see in the following screenshot. mathematica notebook

I want to share the notebook in PDF format as well. When I make use of the "Save as" functionality to create a PDF, I get the following result. pdf file

What can I do to have the full dataset output on the PDF page?

15 Replies

Did you use Grid[] for the tables?

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

Thanks!

Posted 9 months ago

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

enter image description here

enter image description here

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 9 months ago

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

enter image description here

Posted 9 months ago

Hi Jürgen

Cells that can resize as you change the notebook window size will wrap or shrink to fit. Dataset cannot be resized so it gets clipped. The menu option Format / Screen Environment / Printout will show you what will get clipped. One workaround is to shrink the dataset's output size. e.g.

Magnify[dataset, .75]

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?

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

Neil,

Great, it works! Thank you!

I hope the Wolfram Team will come up with an automated concept in 12.3?

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

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]

Hi Henrik,

Thanks for your input. Your code works fine, but it is not the solution. The point is that I want to create a PDF document in Portrait orientation based on a Mathematica notebook. So, a mix of text, graphs, and tables. Regarding the tables, I decided to go for the new layout improvements of Dataset and to make them visible in the notebook and the PDF document as well. In the standard PDF output, the Dataset does simply not fit on the page, apart from the suggested solution by Neil Singer.

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!

You are always welcome.

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

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