cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Check out the JMP® Marketplace featured Capability Explorer add-in
Choose Language Hide Translation Bar
nacka
Level II

Scaling to fit to page width

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
Super User

Re: Scaling to fit to page width

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

View solution in original post

7 REPLIES 7
nacka
Level II

Re: Scaling to fit to page width

Did I stump everyone?

nacka
Level II

Re: Scaling to fit to page width

If it helps, I'm using JMP 10.0.2

Craige_Hales
Super User

Re: Scaling to fit to page width

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
Super User

Re: Scaling to fit to page width

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
Level II

Re: Scaling to fit to page width

This is beautiful! Thank you!

VA103
Level I

Re: Scaling to fit to page width

Thanks for sharing this.

I have difficulty in running this part:

scale( expr(scale) )

It seems jmp16 does not recognize this as a numeric value. 

Any suggestions?

It only works if I put a number there.

Thanks,

Craige_Hales
Super User

Re: Scaling to fit to page width

The original snip of JSL looks like this

eval(evalexpr(
Journal << Set page setup( margins( expr(left), expr(top), expr(right), expr(bottom) ),
 scale( expr(scale) ), portrait( 1 ), paper size( "Letter" ) )
)); 

The extra eval(evalexpr( ... expr(...) ...)) functions are working around a problem that existed in the JMP 10 time (and apparently still exists.) The problem was/is in the <<SetPageSetup method for a journal. That method did not evaluate the arguments to margins() and scale() properties, thus requiring them to be specified as constants. The extra stuff is a way to workaround the problem. It means find each of the expr(...) wrappers and replace them with their value, then eval the whole thing. It is a pattern for substituting a variable's value for the variable.

 

I think you left out the eval/evalexpr wrapper.

 

Edit: sent a note to development team.

 

Craige