Subscribe Bookmark RSS Feed

Scaling to fit to page width

nacka

Occasional Contributor

Joined:

Aug 4, 2016

JMP page setup comes with a scale to fit to page, but i would like to do this in a script without having to use a static scalar.  Is this possible, a "fit to page width"?

 

Specifically, I'd like to make it so that the script will automatically select a scalar for the "Set Page Setup" command based on page layout (Portrait or Landscape, Margin sizes)

 

Current script:

 

 Journal << Set page setup(
margins( .4, .4, .4, .4 ),
scale( .67 ), portrait( 0 ),
paper size( "Letter" )
);

 

 

I would like it to be

 

 

Journal << Set page setup(
margins( .4, .4, .4, .4 ), portrait( 0 ),
paper size( "Letter" )
);
ScaleVariable = /* current page setup width divided by maximum width of objects in journal*/ ;
Journal << Set Page Setup( scale ( ScaleVariable ) ) ;

 

1 ACCEPTED SOLUTION

Accepted Solutions
Craige_Hales

Staff

Joined:

Mar 21, 2013

Solution

this works pretty well in JMP 12.  JMP 11 does not remove the extra page decorations, and JMP 10 needs help sending the parameters to the SetPageSetup message. (Recommending upgrade to 12 (or 13!) if possible.)


// your parameters - paper size and margins
pagewidth = 8.5;
pageheight = 11;
left = .4;
right = .4;
top = .4;
bottom = .4;

dt = Open( "$sample_data/big class.jmp" );

// your reports
//plat = dt << runscript( "bivariate" );
//plat << journal;
//plat << closewindow;

plat = dt << runscript( "fit model" );
plat << journal;
plat << closewindow;

journal = Current Journal();

saved = Get Preferences( "print settings" ); // remember decorations, if any
Preferences( Print Settings( Left Header( "" ), Right Header( "" ) ) ); // remove decorations

{xpix, ypix} = journal << getsize;

marginx = left + right;
marginy = top + bottom;
xinch = pagewidth - marginx;
yinch = pageheight - marginy;
xppi = xpix / xinch;
yppi = ypix / yinch;
ppi = Max( xppi, yppi );
scale = 96 / Ceiling( ppi ); // a little guesswork here. 
// 96 is the pixels per inch of the destination. 72 is another common possibility.
// force the larger dimension to fit.  you could pick a different strategy, make the
// width fit perhaps, or have a minimum scale you don't go below.
Journal << Set page setup( margins( left, top, right, bottom ), scale( scale ), portrait( 1 ), paper size( "Letter" ) ); 
 
journal << save pdf( "$temp\test.pdf" );
journal << closewindow;
Open( "$temp\test.pdf" );
 
eval( saved );

For JMP 11 or 10, remove the preference save/set/restore and for JMP 10 use

// for JMP 10, this will have to suffice...

// your parameters - paper size and margins
pagewidth = 8.5;
pageheight = 11;
left = .4;
right = .4;
top = .4;
bottom = .4;

dt = Open( "$sample_data/big class.jmp" );

// your reports
//plat = dt << runscript( "bivariate" );
//plat << journal;
//plat << closewindow;

plat = dt << runscript( "fit model" );
plat << journal;
plat << closewindow;

journal = Current Journal();

//saved = Get Preferences( "print settings" ); // remember decorations, if any
//Preferences( Print Settings( Left Header( "" ), Right Header( "" ) ) ); // remove decorations

{xpix, ypix} = journal << getsize;

marginx = left + right;
marginy = top + bottom;
xinch = pagewidth - marginx;
yinch = pageheight - marginy;
xppi = xpix / xinch;
yppi = ypix / yinch;
ppi = Max( xppi, yppi );
scale = 96 / Ceiling( ppi ); // a little guesswork here. 
// 96 is the pixels per inch of the destination. 72 is another common possibility.
// force the larger dimension to fit.  you could pick a different strategy, make the
// width fit perhaps, or have a minimum scale you don't go below.
eval(evalexpr(
Journal << Set page setup( margins( expr(left), expr(top), expr(right), expr(bottom) ),
 scale( expr(scale) ), portrait( 1 ), paper size( "Letter" ) )
)); 
 
journal << save pdf( "$temp\test.pdf" );
journal << closewindow;
Open( "$temp\test.pdf" );
 
//eval( saved );

I'm not 100% confident in the hard-coded 96 DPI value, and there may be some rounding errors that the ceiling function is incorrectly trying to account for.

Craige
5 REPLIES
nacka

Occasional Contributor

Joined:

Aug 4, 2016

Did I stump everyone?

nacka

Occasional Contributor

Joined:

Aug 4, 2016

If it helps, I'm using JMP 10.0.2

Craige_Hales

Staff

Joined:

Mar 21, 2013

Solution

this works pretty well in JMP 12.  JMP 11 does not remove the extra page decorations, and JMP 10 needs help sending the parameters to the SetPageSetup message. (Recommending upgrade to 12 (or 13!) if possible.)


// your parameters - paper size and margins
pagewidth = 8.5;
pageheight = 11;
left = .4;
right = .4;
top = .4;
bottom = .4;

dt = Open( "$sample_data/big class.jmp" );

// your reports
//plat = dt << runscript( "bivariate" );
//plat << journal;
//plat << closewindow;

plat = dt << runscript( "fit model" );
plat << journal;
plat << closewindow;

journal = Current Journal();

saved = Get Preferences( "print settings" ); // remember decorations, if any
Preferences( Print Settings( Left Header( "" ), Right Header( "" ) ) ); // remove decorations

{xpix, ypix} = journal << getsize;

marginx = left + right;
marginy = top + bottom;
xinch = pagewidth - marginx;
yinch = pageheight - marginy;
xppi = xpix / xinch;
yppi = ypix / yinch;
ppi = Max( xppi, yppi );
scale = 96 / Ceiling( ppi ); // a little guesswork here. 
// 96 is the pixels per inch of the destination. 72 is another common possibility.
// force the larger dimension to fit.  you could pick a different strategy, make the
// width fit perhaps, or have a minimum scale you don't go below.
Journal << Set page setup( margins( left, top, right, bottom ), scale( scale ), portrait( 1 ), paper size( "Letter" ) ); 
 
journal << save pdf( "$temp\test.pdf" );
journal << closewindow;
Open( "$temp\test.pdf" );
 
eval( saved );

For JMP 11 or 10, remove the preference save/set/restore and for JMP 10 use

// for JMP 10, this will have to suffice...

// your parameters - paper size and margins
pagewidth = 8.5;
pageheight = 11;
left = .4;
right = .4;
top = .4;
bottom = .4;

dt = Open( "$sample_data/big class.jmp" );

// your reports
//plat = dt << runscript( "bivariate" );
//plat << journal;
//plat << closewindow;

plat = dt << runscript( "fit model" );
plat << journal;
plat << closewindow;

journal = Current Journal();

//saved = Get Preferences( "print settings" ); // remember decorations, if any
//Preferences( Print Settings( Left Header( "" ), Right Header( "" ) ) ); // remove decorations

{xpix, ypix} = journal << getsize;

marginx = left + right;
marginy = top + bottom;
xinch = pagewidth - marginx;
yinch = pageheight - marginy;
xppi = xpix / xinch;
yppi = ypix / yinch;
ppi = Max( xppi, yppi );
scale = 96 / Ceiling( ppi ); // a little guesswork here. 
// 96 is the pixels per inch of the destination. 72 is another common possibility.
// force the larger dimension to fit.  you could pick a different strategy, make the
// width fit perhaps, or have a minimum scale you don't go below.
eval(evalexpr(
Journal << Set page setup( margins( expr(left), expr(top), expr(right), expr(bottom) ),
 scale( expr(scale) ), portrait( 1 ), paper size( "Letter" ) )
)); 
 
journal << save pdf( "$temp\test.pdf" );
journal << closewindow;
Open( "$temp\test.pdf" );
 
//eval( saved );

I'm not 100% confident in the hard-coded 96 DPI value, and there may be some rounding errors that the ceiling function is incorrectly trying to account for.

Craige
Craige_Hales

Staff

Joined:

Mar 21, 2013

There is a better way that also works in JMP 10:

journal << set Print Headers( "", "", "" );
journal << save pdf( "$temp\test.pdf" );

removing the print headers (and footers if necessary) makes the PDF page look a lot better.

PDF without JMP headersPDF without JMP headers

Craige
nacka

Occasional Contributor

Joined:

Aug 4, 2016

This is beautiful! Thank you!