7
$\begingroup$

I'd like a way of exporting a grid to PDF that isn't one super long page, moreover I'd like the page breaks to be chosen automatically (so that the grid fits/fills each normal sized page).

Is there some way to do this without having to tweak style-sheets or resort to printing?

Example Code:

Export["~/Downloads/tall_grid.pdf", 
    Grid[Partition[Table[
       Labeled[RandomImage[], ResourceFunction["RandomString"][10]], 
       {i, 200}], UpTo @ 5],
    Spacings -> {2, 2}],
    ImageResolution -> 600
]

Related:

$\endgroup$
5
$\begingroup$

Actually, this is strange that such possibility is not a built-in function.

Let's say, we have a list of 150 strings like this:

tbl = Table[{a, ToString@(a RandomReal[{-2, 2}])}, {a, 1, 150}];

My workaround for pages formation is following:

spp = 64; (*the desired number of strings per page, depending on content size and page size*)

tmp = Table[
  tbl[[spp*i + 1 ;; spp*i + spp]], {i, 0, Length@tbl/spp - 1}];
data = Grid[#, Frame -> All] & /@ 
   Join[tmp, {tbl[[spp*Length@tmp + 1 ;; -1]]}];

cd = CreateDocument[
   ExpressionCell[#, PageBreakBelow -> True] & /@ data];
Export["file.pdf", cd]; NotebookClose[cd, Interactive -> False]

This makes the pdf-file with two full-length pages and one more partially filled..

| improve this answer | |
$\endgroup$

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.