2
$\begingroup$

I'm trying to create a multi-page "PDF" (application/pdf Adobe Acrobat format) file with code similar to this minimum working example code, featuring PlotLegends and "LargeLabels"

Export["Test.PDF",
    CreateDocument[
        ExpressionCell[
            #
            , PageBreakBelow -> True
            , WindowSize->All
        ]& /@ Table[
            ListPlot[
                Sort/@RandomReal[1,{5,20}]
                , Joined -> True
                , PlotLegends -> RandomWord[5]
                , PlotTheme -> {"Scientific","LargeLabels"}
                , PlotLabel -> RandomWord[]
                , ImageSize-> 600
            ]
            ,{5}
        ]
    ]
    , "PDF"
]

The image shows the problem: Legends are clipped and the page is portrait instead of Landscape.

enter image description here

I'm struggling to find a good way to programmatically avoid PlotLegends being clipped, other than changing ImageSize by trial and error. As pages are created programmatically, checking all by hand is undesirable.

Also, I can't find out how to define the correct page orientation, i.e to force a Landscape page if AspectRatio $< 1$ and Portrait otherwise.

How can one create a multi-page PDF file with the correct page orientation and avoid clipping PlotLegends?

$\endgroup$
1
  • 1
    $\begingroup$ I guess, the problem is in the determination of correct width of the plots. The ImageSize->600 is 600 printer points but it does not correlate with screen resolution and visible size of the plots.. $\endgroup$
    – Rom38
    Aug 17 at 5:32

1 Answer 1

2
$\begingroup$

Over the years of the site's existence, questions have regularly arisen about the export of multi-page PDF files, similar to this one, and for all this time an adequate solution without an involvement of third-party utilities has not been found. To my knowledge, using third party utilities is the only workable approach so far. It consists of two stages:

  1. Export each page as a separate PDF file.
  2. Merge all exported pages into one document using one of the third party utilities. I recommend PyMuPdf. Alternatively, one can use pdfunite from Poppler utils as shown here.
$\endgroup$
1
  • $\begingroup$ Thanks, @AlexeyPopkov, you seem to be correct about this. Not the answer I was expecting, but I think likely the only good answer one can expect. $\endgroup$
    – rhermans
    Aug 19 at 8:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.