The SAS Output Delivery System and reporting techniques

ODS PDF How to set different margins on each page of PDF document

Reply
Contributor
Posts: 32

ODS PDF How to set different margins on each page of PDF document

Subject:
   Option LEFTMARGIN not working in ODS PDF if I change it after first page

Problem Description:
   I used OPTIONS LEFTMARGIN=0cm; for printing first pdf page.

After printing first page, I changed LEFTMARGIN value to 2cm and printing 2nd page.

But output PDF still has leftmargin=0cm for the second page and the following pages.
Please let me know why leftmargin is not working if I change it after first page.

SAS Super FREQ
Posts: 620

Re: ODS PDF How to set different margins on each page of PDF document

Hi

 

This is currently not possible, once a destination has been opened, the margins can not be changed. However there is a way to workaround this using ODS LAYOUT. See below for an example. This might work for you.

 

options
  nocenter
  leftmargin=0cm
;


ods pdf file="c:\temp\sample.pdf" startpage=never;
ods layout gridded  columns=1 x=0cm;
ods region;
title "First page";
proc print data=sashelp.class;
run;
title;
ods layout end;

ods pdf startpage=now;
ods layout gridded  columns=1 x=2cm;
ods region;
title "Second page";
proc print data=sashelp.class;
run;
title;
ods layout end;
ods pdf close;

Bruno

Valued Guide
Posts: 505

Re: ODS PDF How to set different margins on each page of PDF document

Create a pdf with different styles for each page

I do this all the time because I need to combine
SAS ODF output with R/Python output

HAVE 2 pdfs with different left and right margins and
I need to combine them

%utl_pdflan100(
   style=utl_pdflan1in
  ,rightmargin=.5in
  ,leftmargin=.5in
  );

* create two PDFs;
ods pdf file="d:/pdf/part1.pdf" style=utl_pdflan1in;
proc print data=sashelp.class(obs=10);
run;quit;
ods pdf close;

%utl_pdflan100(
   style=utl_pdflan2in
  ,rightmargin=1in
  ,leftmargin=1in
  );

ods pdf file="d:/pdf/part2.pdf" style=utl_pdflan2in;
proc print data=sashelp.class(firstobs=9);
run;quit;
ods pdf close;

Solution

%utl_pdfcombine(file1=d:/pdf/part1.pdf,file2=d:/pdf/part2.pdf,file12=d:/pdf/part12.pdf);

GPL Ghostscript 9.19 (2016-03-23)
Copyright (C) 2016 Artifex Software, Inc.  All rights reserved.
This software comes with NO WARRANTY: see the file PUBLIC for details.
Processing pages 1 through 1.
Page 1
Processing pages 1 through 1.
Page 1
NOTE: 7 records were read from the infile CMD.
      The minimum record length was 6.
      The maximum record length was 70.
NOTE: DATA statement used (Total process time):
      real time           0.60 seconds
      user cpu time       0.03 seconds
      system cpu time     0.00 seconds
      memory              245.56k
      OS Memory           16616.00k
      Timestamp           12/12/2016 05:02:00 PM
      Step Count                        237  Switch Count  0


MPRINT(UTL_PDFCOMBINE):  quit;
MPRINT(UTL_PDFCOMBINE):   filename cmd clear;
NOTE: Fileref CMD has been deassigned.
MLOGIC(UTL_PDFCOMBINE):  Ending execution.


/* T0100210 SAS/Ghostscript: Combining pdf files file1+file2 into file12

SAS/Ghostscript: Combining pdf files file1+file2 into file12

It is notable that the WPS Express edition does not support the
pdf destination.
If the two PDFs already exist you can append them in WPS.
As far as I can tell the two free versions of WPS support
command pipes.

inspired by
http://support.sas.com/kb/35/375.html

I could not see how to use the SAS solution above to work with
arbitrary PDFs.
Does not work with staic combinations of SAS PDFs, mixture SAS /non SAS  or none SAS pdfs.

HAVE Two arbitrary pdfs

    d:/pdf/part1.pdf
    d:/pdf/part2.pdf

WANT append Part2.pdf to end of part1.pdf

    d:/pdf/part12.pdf

Solution Working code
=====================

%utl_pdfcombine(file1=d:/pdf/part1.pdf,file2=d:/pdf/part2.pdf,file12=d:/pdf/part12.pdf);

Download ghostscript
http://www.ghostscript.com/download/

I copied the executable gswin64c.exe to my c:\pdf folder
C:\Program Files\gs\gs9.06\bin\gswin64c.exe to c:\pdf\gswin64c.exe

* combining pdf files;

%macro utl_pdfcombine(file1=&hspo01,file2=d:/hsp/pdf/hsp_page1.pdf,file12=&hspo02)
/des label="Combine ppdfs";

    filename cmd pipe "d:\pdf\gswin64c.exe -dNOPAUSE -sDEVICE=pdfwrite -sOUTPUTFILE=&file12 -dBATCH &file1 &file2";
    data _null_;
      infile cmd;
      input;
      putlog _infile_;
    ;run;quit;

    filename cmd clear;

%mend utl_pdfcombine;

%utl_pdfcombine(file1=d:/pdf/part1.pdf,file2=d:/pdf/part2.pdf,file12=d:/pdf/part12.pdf);


%Macro utl_pdflan100
    (
      style=utl_pdflan100
      ,frame=box
      ,TitleFont=14pt
      ,docfont=13pt
      ,fixedfont=12pt
      ,rules=ALL
      ,bottommargin=.25in
      ,topmargin=.25in
      ,rightmargin=.25in
      ,leftmargin=.25in
      ,cellheight=13pt
      ,cellpadding = 2pt
      ,cellspacing = .2pt
      ,borderwidth = .2pt
    ) /  Des="SAS PDF Template for PDF";

ods path work.templat(update) sasuser.templat(update) sashelp.tmplmst(read);

Proc Template;

   define style &Style;
   parent=styles.rtf;

        replace body from Document /

               protectspecialchars=off
               asis=on
               bottommargin=&bottommargin
               topmargin   =&topmargin
               rightmargin =&rightmargin
               leftmargin  =&leftmargin
               ;

        replace color_list /
              'link' = blue
               'bgH'  = _undef_
               'fg'  = black
               'bg'   = _undef_;

        replace fonts /
               'TitleFont2'           = ("Arial, Helvetica, Helv",&titlefont,Bold)
               'TitleFont'            = ("Arial, Helvetica, Helv",&titlefont,Bold)

               'HeadingFont'          = ("Arial, Helvetica, Helv",&titlefont)
               'HeadingEmphasisFont'  = ("Arial, Helvetica, Helv",&titlefont,Italic)

               'StrongFont'           = ("Arial, Helvetica, Helv",&titlefont,Bold)
               'EmphasisFont'         = ("Arial, Helvetica, Helv",&titlefont,Italic)

               'FixedFont'            = ("Courier New, Courier",&fixedfont)
               'FixedEmphasisFont'    = ("Courier New, Courier",&fixedfont,Italic)
               'FixedStrongFont'      = ("Courier New, Courier",&fixedfont,Bold)
               'FixedHeadingFont'     = ("Courier New, Courier",&fixedfont,Bold)
               'BatchFixedFont'       = ("Courier New, Courier",&fixedfont)

               'docFont'              = ("Arial, Helvetica, Helv",&docfont)

               'FootFont'             = ("Arial, Helvetica, Helv", 9pt)
               'StrongFootFont'       = ("Arial, Helvetica, Helv",8pt,Bold)
               'EmphasisFootFont'     = ("Arial, Helvetica, Helv",8pt,Italic)
               'FixedFootFont'        = ("Courier New, Courier",8pt)
               'FixedEmphasisFootFont'= ("Courier New, Courier",8pt,Italic)
               'FixedStrongFootFont'  = ("Courier New, Courier",7pt,Bold);

        replace GraphFonts /
               'GraphDataFont'        = ("Arial, Helvetica, Helv",&fixedfont)
               'GraphValueFont'       = ("Arial, Helvetica, Helv",&fixedfont)
               'GraphLabelFont'       = ("Arial, Helvetica, Helv",&fixedfont,Bold)
               'GraphFootnoteFont'    = ("Arial, Helvetica, Helv",8pt)
               'GraphTitleFont'       = ("Arial, Helvetica, Helv",&titlefont,Bold)
               'GraphAnnoFont'        = ("Arial, Helvetica, Helv",&fixedfont)
               'GraphUnicodeFont'     = ("Arial, Helvetica, Helv",&fixedfont)
               'GraphLabel2Font'      = ("Arial, Helvetica, Helv",&fixedfont)
               'GraphTitle1Font'      = ("Arial, Helvetica, Helv",&fixedfont);

        style Graph from Output/
                outputwidth = 100% ;

        style table from table /
                outputwidth=100%
                protectspecialchars=off
                asis=on
                background = colors('tablebg')
                frame=&frame
                rules=&rules
                cellheight  = &cellheight
                cellpadding = &cellpadding
                cellspacing = &cellspacing
                bordercolor = colors('tableborder')
                borderwidth = &borderwidth;

         replace Footer from HeadersAndFooters

                / font = fonts('FootFont')  just=left asis=on protectspecialchars=off ;

                replace FooterFixed from Footer
                / font = fonts('FixedFootFont')  just=left asis=on protectspecialchars=off;

                replace FooterEmpty from Footer
                / font = fonts('FootFont')  just=left asis=on protectspecialchars=off;

                replace FooterEmphasis from Footer
                / font = fonts('EmphasisFootFont')  just=left asis=on protectspecialchars=off;

                replace FooterEmphasisFixed from FooterEmphasis
                / font = fonts('FixedEmphasisFootFont')  just=left asis=on protectspecialchars=off;

                replace FooterStrong from Footer
                / font = fonts('StrongFootFont')  just=left asis=on protectspecialchars=off;

                replace FooterStrongFixed from FooterStrong
                / font = fonts('FixedStrongFootFont')  just=left asis=on protectspecialchars=off;

                replace RowFooter from Footer
                / font = fonts('FootFont')  asis=on protectspecialchars=off just=left;

                replace RowFooterFixed from RowFooter
                / font = fonts('FixedFootFont')  just=left asis=on protectspecialchars=off;

                replace RowFooterEmpty from RowFooter
                / font = fonts('FootFont')  just=left asis=on protectspecialchars=off;

                replace RowFooterEmphasis from RowFooter
                / font = fonts('EmphasisFootFont')  just=left asis=on protectspecialchars=off;

                replace RowFooterEmphasisFixed from RowFooterEmphasis
                / font = fonts('FixedEmphasisFootFont')  just=left asis=on protectspecialchars=off;

                replace RowFooterStrong from RowFooter
                / font = fonts('StrongFootFont')  just=left asis=on protectspecialchars=off;

                replace RowFooterStrongFixed from RowFooterStrong
                / font = fonts('FixedStrongFootFont')  just=left asis=on protectspecialchars=off;

                replace SystemFooter from TitlesAndFooters / asis=on
                        protectspecialchars=off just=left;
    end;
run;
quit;

%Mend utl_pdflan100;
Contributor
Posts: 32

Re: ODS PDF How to set different margins on each page of PDF document

Hi,

 

Thanks for the solution. But I can't use the external software to append the PDF files in my system env. It is restricted.

 

Is there anyother way to append the pdf files with different leftmargins using only SAS software?

 

I have already tried Proc document and replay it to write the final pdf tile. It is also not giving desired result.

 

My requirement:

 

I am generating 50 PDF files(Each file can have different no of pages in the range of 5 to 20 pages) thru online/Batch with first page using ods layout and ods region with leftmargin =0cm.

 

From 2nd page onwards(till the eof),PDF files should have leftmargin=2cm. Currently the final pdf file is having 0cm as leftmargin in all the pages even if I change it after first page using option leftmargin = 2cm.

 

This is the requirement.

 

Thanks,

Sampath

 

 

 

Contributor
Posts: 32

Re: ODS PDF How to set different margins on each page of PDF document

Hi,

 

Thanks for the idea. But it is also not giving desired result.

 

Is there anyother way to have the left margin = 2cm from 2nd page onwards?

 

I have already tried Proc document and replay it to write the final pdf tile to combine 1st page and the remaining pages. It is also not giving desired result.

 

Even I tried to change using proc template to change the leftmargin..It is not working.

 

My requirement:

 

I am generating 50 PDF files(Each file can have different no of pages in the range of 5 to 20 pages) thru online/Batch with first page using ods layout and ods region with leftmargin =0cm. Only this page is static. Remaining pages are dynamic.

 

From 2nd page onwards(till the eof),PDF files should have leftmargin=2cm. Currently the final pdf file is having 0cm as leftmargin in all the pages even if I change it after first page using option leftmargin = 2cm.

 

This is the requirement.

 

Thanks,

Sampath

 

 

 

Post a Question
Discussion Stats
  • 4 replies
  • 263 views
  • 0 likes
  • 3 in conversation