BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
NeilH
Obsidian | Level 7

Hello - I'm creating a bar chart with sgplot that produces both html and pdf output. The html formatting is perfect on-screen, while the pdf doesn't display nearly as well, having both layout (title, y-axis labels) and font differences. I'm attaching both charts below. Are there ODS commands - or another way - to guide the pdf formatting so that it appears nearly identical to the html output? I appreciate anyone's help with this. Thanks.Bar char - html.PNGBar char - pdf.PNG

proc sgplot data=rc_temp6;
title 'Faculty Survey Response by Section: Institute vs. National'; 
where survey = 'Faculty';
vbar section / response=rating1 datalabel=rating1 group=source groupdisplay=cluster clusterwidth=.50;
yaxis label='Level of Agreement' values=(0, 33, 67, 100) valuesdisplay=("Disagree (0)" "Somewhat Disagree (33)" "Somewhat Agree (67)" "Agree (100)");
xaxis display=(nolabel);
footnote "N: Institute = 10, National = 100";
run;
1 ACCEPTED SOLUTION

Accepted Solutions
Cynthia_sas
SAS Super FREQ

Hi:

  I ran a quick test using SASHELP.PRDSALE using THIS code:


options orientation=landscape topmargin=.25in bottommargin=.25in rightmargin=.25in leftmargin=.25in;
ods graphics / width=10.5in height=7.5in;

ods pdf(id=1) file='c:\temp\test_graf.pdf' style=htmlblue nogtitle nogfootnote;
proc sgplot data=sashelp.prdsale;
  title 'Test difference HTML/PDF';
  where product in ('DESK' 'CHAIR' 'SOFA' 'TABLE');
  vbar product / response=actual group=region groupdisplay=cluster clusterwidth=.50;
  xaxis display=(nolabel);
  yaxis label='Level of Agreement' values=(0, 50000, 80000) valuesdisplay=("None (0)" "The Middle (50K)" "The Highest (80K)");
  footnote "N: Institute = 10, National = 100";
run;

ods pdf(id=1) close;

ods html(id=2) path='c:\temp\' file='test_graf.html' style=htmlblue nogtitle nogfootnote;
proc sgplot data=sashelp.prdsale;
  title 'Test difference HTML/PDF';
  where product in ('DESK' 'CHAIR' 'SOFA' 'TABLE');
  vbar product / response=actual group=region groupdisplay=cluster clusterwidth=.50;
  xaxis display=(nolabel);
  yaxis label='Level of Agreement' values=(0, 50000, 80000) valuesdisplay=("None (0)" "The Middle (50K)" "The Highest (80K)");
  footnote "N: Institute = 10, National = 100";
run;
ods html(id=2) close;

I didn't mess with fonts or DPI, all I did was generate 2 different files, one HTML and one PDF that sort of copied your general VBAR.

Here's the PDF file viewed in Acrobat Reader:

Cynthia_sas_0-1723749292960.png

 

And here's the HTML file viewed in Chrome:

Cynthia_sas_1-1723749394813.png

  They look fairly similar to me as far as fonts and readability. (and yes, I know that 50K isn't the middle...my bad) Of course, it's not an apples-to-apples comparison because I can resize the browser window and the graph resizes and same with the PDF file in Acrobat. So I did my best to have them both at 100%.

 

  All I did was use the same ODS options as far as STYLE, and NOGTITLE, NOGFOOTNOTE and then for ODS PDF, I made sure to change the margins and the orientation before ODS PDF started. I also changed the WIDTH and HEIGHT for ODS GRAPHICS, just to be sure that the image filled the entire PDF "page".  As you can see I have the date turned off, but page numbering turned on in the other options. Since HTML ignores date/number options, I wanted to leave the page number in so you could see it placed on the top of the output, with the TITLE.

  When I am making 2 files for comparison purposes, I like to use the ID= suboption to make sure that I am opening the right output file for comparison. In this case, ID= wasn't absolutely necessary, but I also didn't want to clobber any of the automatic HTML files that SAS creates by default (or default PDF files if you have that turned on in EG or SAS Studio).

  If you try using the ODS example and options that I've used and you are still seeing big differences in the 2 different output files, then I would recommend that you open a case with SAS Tech Support so they can help you zero in on what is happening to make your PDF file so different from your HTML file.

  You should be able to run my example and only need to change the path from c:\temp to your path to be able to run the code as a test. Hope this helps,

Cynthia

 

 

View solution in original post

5 REPLIES 5
ballardw
Super User

Since you say you are producing PDF output you should include the ODS PDF statement used to create the output.

 

By default HTML, PDF and RTF (possibly others) have different default ODS styles assigned. Which means different default fonts, font sizes, color lists etc. Generally to get more similar output you need to use the same style for all destinations.

That would be a "sandwich" around your actual output code with the ODS HTML (if sending to files) and ODS PDF statements.

 

Find out which ODS style your HTML output uses. Defaults likely are HTMLBLUE or SASWEB. I think PDF uses Pearl.

So try adding Style=Htmlblue to your ODS destination statement where I would expect you to have a File= to create your PDF.

NeilH
Obsidian | Level 7

Thanks, that's helpful. Changing the pdf style to Htmlblue does change the coloring scheme, so it's definitely  having an effect. Although the title and y-axis labels still appear to be left justified - or just out of alignment compared to the html output. Exactly as before for the text positioning. I don't know if there are other ods commands that need to be called to reposition the title and y-axis label text into more standard positions.

 

ods html close;
ods pdf file='M:\Engagement Surveys - 2024\Scratch\output.pdf' style=HTMLBlue;
proc sgplot data=rc_temp6;
title 'Faculty Survey Response by Section: Institute vs. National'; 
where survey = 'Faculty';
vbar section / response=rating1 datalabel=rating1 group=source groupdisplay=cluster clusterwidth=.50;
yaxis label='Level of Agreement' values=(0, 33, 67, 100) valuesdisplay=("Disagree (0)" "Somewhat Disagree (33)" "Somewhat Agree (67)" "Agree (100)");
xaxis display=(nolabel);
footnote "N: Institute = 10, National = 100";
run;
Cynthia_sas
SAS Super FREQ
Hi:
HTML and PDF are inherently different types of destinations. PDF is designed as a "measured" destination, with a definite "page" concept, with margins that reduce the available display space on the page and the concept of page breaks. However, HTML is NOT a "measured" destination. There are not any real "margins" in an HTML page because an HTML web page is not intended to be printed. If you do have an HTML page visible in your browser and you print the HTML page, sending the text on the page to a printer is handled by the browser interface to the printer. Any page breaks that are inserted are only there because of the browser's interface to the printer, not because of any instructions that came from SAS or from ODS.
By comparison, when you use ODS PDF, to create output, you need to be aware of the margin and orientation options in place before you start to create your output and you also need to be aware of the fact that using tiny font sizes will change where the output inserts the page breaks into the final PDF document. My suggestion is slightly different -- it looks to me as though your title is being handled by ODS, which means that ODS HTML has NOGTITLE set as an option, but your PDF looks like the TITLE is inside the graph image, which means that GTITLE is set as an option for ODS PDF. Having the title inside the graph will take away from the real estate available for the graph image. Your fonts in the PDF file also look a bit fuzzy, so I'd suspect that you need to change the DPI setting and probably the font settings if you want the font to look better.
Cynthia
Ksharp
Super User
If want better support from us, you'd better post your real data and full code ,so we can test your code and replicated your problem.
Cynthia_sas
SAS Super FREQ

Hi:

  I ran a quick test using SASHELP.PRDSALE using THIS code:


options orientation=landscape topmargin=.25in bottommargin=.25in rightmargin=.25in leftmargin=.25in;
ods graphics / width=10.5in height=7.5in;

ods pdf(id=1) file='c:\temp\test_graf.pdf' style=htmlblue nogtitle nogfootnote;
proc sgplot data=sashelp.prdsale;
  title 'Test difference HTML/PDF';
  where product in ('DESK' 'CHAIR' 'SOFA' 'TABLE');
  vbar product / response=actual group=region groupdisplay=cluster clusterwidth=.50;
  xaxis display=(nolabel);
  yaxis label='Level of Agreement' values=(0, 50000, 80000) valuesdisplay=("None (0)" "The Middle (50K)" "The Highest (80K)");
  footnote "N: Institute = 10, National = 100";
run;

ods pdf(id=1) close;

ods html(id=2) path='c:\temp\' file='test_graf.html' style=htmlblue nogtitle nogfootnote;
proc sgplot data=sashelp.prdsale;
  title 'Test difference HTML/PDF';
  where product in ('DESK' 'CHAIR' 'SOFA' 'TABLE');
  vbar product / response=actual group=region groupdisplay=cluster clusterwidth=.50;
  xaxis display=(nolabel);
  yaxis label='Level of Agreement' values=(0, 50000, 80000) valuesdisplay=("None (0)" "The Middle (50K)" "The Highest (80K)");
  footnote "N: Institute = 10, National = 100";
run;
ods html(id=2) close;

I didn't mess with fonts or DPI, all I did was generate 2 different files, one HTML and one PDF that sort of copied your general VBAR.

Here's the PDF file viewed in Acrobat Reader:

Cynthia_sas_0-1723749292960.png

 

And here's the HTML file viewed in Chrome:

Cynthia_sas_1-1723749394813.png

  They look fairly similar to me as far as fonts and readability. (and yes, I know that 50K isn't the middle...my bad) Of course, it's not an apples-to-apples comparison because I can resize the browser window and the graph resizes and same with the PDF file in Acrobat. So I did my best to have them both at 100%.

 

  All I did was use the same ODS options as far as STYLE, and NOGTITLE, NOGFOOTNOTE and then for ODS PDF, I made sure to change the margins and the orientation before ODS PDF started. I also changed the WIDTH and HEIGHT for ODS GRAPHICS, just to be sure that the image filled the entire PDF "page".  As you can see I have the date turned off, but page numbering turned on in the other options. Since HTML ignores date/number options, I wanted to leave the page number in so you could see it placed on the top of the output, with the TITLE.

  When I am making 2 files for comparison purposes, I like to use the ID= suboption to make sure that I am opening the right output file for comparison. In this case, ID= wasn't absolutely necessary, but I also didn't want to clobber any of the automatic HTML files that SAS creates by default (or default PDF files if you have that turned on in EG or SAS Studio).

  If you try using the ODS example and options that I've used and you are still seeing big differences in the 2 different output files, then I would recommend that you open a case with SAS Tech Support so they can help you zero in on what is happening to make your PDF file so different from your HTML file.

  You should be able to run my example and only need to change the path from c:\temp to your path to be able to run the code as a test. Hope this helps,

Cynthia

 

 

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 612 views
  • 3 likes
  • 4 in conversation