MathGroup Archive 2011

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Problems Exporting to PDF

  • To: mathgroup at smc.vnet.net
  • Subject: [mg115850] Re: Problems Exporting to PDF
  • From: djorser at comcast.net
  • Date: Sat, 22 Jan 2011 03:24:53 -0500 (EST)

Hi All! 

The multi-page PDF problem keeps coming up and Bob Hanlon's 
solution seems worth generalizing a bit. This works for me: 

MultiPagePDF[file_, title_, header_, filter_, linesPerPage_] := 
Labeled[Grid[Join[{Pick[header, filter, 1]}, #], Frame -> All, 
ItemStyle -> {{"Text"}, {{Red, Bold}, {"Text"}}}, 
Background -> {None, {LightGray, None}}], 
Style[title, "Subtitle"], Top] & /@ 
Partition[ 
Join[Table[ 
Pick[file[[i]], Take[filter, Length[file[[1]]]], 1], {i, 1, 
Length[file]}], Table[{}, {linesPerPage - 1}]], linesPerPage]; 

I believe the Styling needs some additional work, but this 
conveys the idea. 

As I have files (tables) with over 50 elements per record, 
and need only a smaller subset at a time, 
I have incorporated 
a filter consisting of a list of 0's and 1's which select the elements 
I want, including the column heading labels. 

For an example use: 

T1 = Table[ 
Flatten[{StandardForm["Question " <> ToString[n]], 
RandomInteger[{10^3, 10^4}, 5]}], {n, 25}]; 

header = {"Question", "Col1", "Col2", "Col3", "Col4", "Col5"}; 

filterOdd = {1, 1, 0, 1, 0, 1}; 
filterEven = {1, 0, 1, 0, 1, 0}; 

PDFTable = 
MultiPagePDF[T1, "Columns 1, 3 & 5", header , filterOdd, 10] 

PDFTable = MultiPagePDF[T1, "Columns 2 & 4", header , filterEven, 10] 

As I find it useful to export these "pages" as Edit|Export As|Metafile to 
MS Word, I have kept the export of PDFTable[[i]] , i=1, end as PDF 
files a separate operation. 

Table[Export[ 
"PDFTable" <> " " <> ToString[i] <> 
",.pdf", PDFTable[[i]]], {i, 1, Length[PDFTable]}] 


Don J. Orser 




----- Original Message ----- 
From: "AES" <siegman at stanford.edu> 
To: mathgroup at smc.vnet.net 
Sent: Thursday, January 20, 2011 6:26:37 AM 
Subject: [mg115850] [mg115750] Re: Problems Exporting to PDF 

In article <ih6egp$3ih$1 at smc.vnet.net>, Bob Hanlon <hanlonr at cox.net> 
wrote: 

> You could break it into pages 
> linesPerPage = 40; 
> grid5 = Grid[#, Frame -> All] & /@ 
> Partition[ 
> Join[ 
> Table[Flatten[ 
> {StandardForm["Question " <> ToString[n]], 
> RandomInteger[{10^5, 10^8}, 5]}], 
> {n, 100}], 
> Table[{}, {linesPerPage - 1}]], 
> linesPerPage]; 
> Table[Export["grid5" <> "_" <> ToString[n] <> ".pdf", 
> grid5[[n]]], {n, Length[grid5]}] 
> {"grid5_1.pdf", "grid5_2.pdf", "grid5_3.pdf"} 
> Bob Hanlon 

I have no quarrel at all with an example like the above (and admiration 
for those who can code this kind of thing). 

But thinking back on the recent threads about procedural vs functional 
programming and trying to decipher what this code does for myself makes 
it ever more clear why my approach to the same problem -- and I think 
the recommended approach for most Mathematica users -- would be something like a Do loop, generating and exporting one "block" (one example of 
"grid5_n.pdf") per loop. 

And suppose instead Helen Read wanted to generate many questions of 
varying length (let each question be a separate "grid5_n" block), and 
then export as many individual questions to a page as would fit on that 
exported page, but never have the last question on a page run off the 
bottom of the page, or over to the next page? (The process that TeX 
handles so beautifully and easily with \filbreak) How might that be 
coded functionally? 

(And of course there could be a fews cases where an occasional "grid5_n" 
question or block is individually longer than a single page . . . ) 


  • Prev by Date: Re: problem with LessEqual::nord:
  • Next by Date: Re: Simple n-tuple problem - with no simple solution
  • Previous by thread: Re: Problems Exporting to PDF
  • Next by thread: Re: Problems Exporting to PDF