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

Good afternoon,

 

I am trying to insert a text and picture into a pdf file. My code so far looks like this

options orientation=portrait
		papersize=A4
		nodate
		topmargin=.001in
		bottommargin=.001in
		leftmargin=.001in
		rightmargin=.001in;
ods noproctitle;
ods escapechar="^";

title;
footnote;

ods pdf file="J:\Learning SAS\Example.pdf";
ods layout start width = 19cm height = 28cm ; 
ods region y=2cm x=2cm width=6cm; 
ods text="Some Random Information:";
ods region width=0.5cm height=0.25cm;
ods text= '^{style[preimage="C:/Users/WissMit/Desktop/example jpg.jpg"]}';
ods layout end;
ods pdf close; 

And the Output looks like this:

 

Example Output.PNG

Unfortunately, the PDF looks like this:

Example pdf.PNG

Somehow the .jpg is missing. Does anyone have a clue what I am missing? In several articles it always looks so easy... Furthermore, I would like to have control over the image size. Is there a way to control the size without adjusting it beforehand?

 

1 ACCEPTED SOLUTION

Accepted Solutions
BrunoMueller
SAS Super FREQ

Give this code below a go, if it works fine. Otherwise we might need some more coding. The image will automatically scale to the size of the region you define. The bordercolor and borderwidth are not really need, it is just to show the size of the region. I would also recommend to only use the ODS PDF desination and no other.

options orientation=portrait
		papersize=A4
		nodate
		topmargin=.001in
		bottommargin=.001in
		leftmargin=.001in
		rightmargin=.001in;
ods noproctitle;
ods escapechar="^";

title;
footnote;

ods pdf file="c:\temp\sas2pdf_example.pdf";
ods layout start width = 19cm height = 28cm ; 
ods region y=2cm x=2cm width=6cm; 
ods text="Some Random Information:";
ods region y=4cm x=2cm width=2cm height=2cm style={bordercolor=red borderwidth=10px backgroundimage="c:\temp\bird.jpg" };
ods text=" ";
ods layout end;
ods pdf close;

View solution in original post

10 REPLIES 10
Cynthia_sas
SAS Super FREQ

Hi:
I notice that you are writing the PDF to your J drive but the image is on your C: drive. Did you have error messages in your log? Perhaps something like this or another warning that indicates output will be suppressed?
WARNING: The absolute region was too small to accommodate the output supplied for the PDF
destination. Output will be suppressed.

That's usually what causes no output to be produced. When I tried a simplified form of your code (switching CM to IN and using my image, I was able to create PDF output as shown below.

Cynthia_sas_0-1656509951736.png

When I use ODS TEXT to a specific destination, I like to be sure to use ODS PDF TEXT= or ODS RTF TEXT= to make sure that I am not accidentally writing my text to a destination that's open, but isn't the ultimate output I want. As you can see in the code, I'm writing the output to one folder, but getting the image from another folder. I only had a PNG to use, but it worked for me with simplified and tweaked code. The only other thing I added was a {NEWLINE 1} after the first line of text. I usually do that because I like to have control over the line feeds.


I do not think you can use your ODS statements to resize the image. My experience with using preimage is that I need to make sure the image is the size I want before using the image in the PREIMAGE style override. You might wish to look in the documentation or open a track with Tech Support.
Cynthia

_Manhattan
Quartz | Level 8

Hi Cynthia,

 

thank you for your reply! Your code seems to work aswell, but I am not able to customize the image size (as you already stated) so I am sticking with brunos approach. Anyways, thank you for the hints with the ods pdf text statement 🙂

 

Kind regards,

Jakob

BrunoMueller
SAS Super FREQ

Give this code below a go, if it works fine. Otherwise we might need some more coding. The image will automatically scale to the size of the region you define. The bordercolor and borderwidth are not really need, it is just to show the size of the region. I would also recommend to only use the ODS PDF desination and no other.

options orientation=portrait
		papersize=A4
		nodate
		topmargin=.001in
		bottommargin=.001in
		leftmargin=.001in
		rightmargin=.001in;
ods noproctitle;
ods escapechar="^";

title;
footnote;

ods pdf file="c:\temp\sas2pdf_example.pdf";
ods layout start width = 19cm height = 28cm ; 
ods region y=2cm x=2cm width=6cm; 
ods text="Some Random Information:";
ods region y=4cm x=2cm width=2cm height=2cm style={bordercolor=red borderwidth=10px backgroundimage="c:\temp\bird.jpg" };
ods text=" ";
ods layout end;
ods pdf close;

Cynthia_sas
SAS Super FREQ
@BrunoMueller:
That's cool. My JPG image resized but the PNG image did not. And good idea to use backgroundimage instead of preimage.
Thanks for the example,
Cynthia
_Manhattan
Quartz | Level 8

Thank you so much Bruno! That worked for me 🙂 But I've still got two questions as I am not sure if I understand everything thats going on in the code:

 

- Why do I need to include the 'ods text = " " ' and 'backgroundimage' statement? I am a bit frustrated that the code didnt work out with 'pre/postimage' and I do not get why it doesn't. I would really like to understand what the ods text statement is doing there (as it doesn't work without it)

 

- May seem a bit redundant as I was the one putting it there in the first place, but: Do I need the whole 'options' to 'footnote' part? The results appear to be the same and I was just following instructions out of an article (I attached it, in case anyones interested, see p. 4)

 

 

BrunoMueller
SAS Super FREQ
ODS TEXT is needed so we actually create some content in the region.

The options and footnote statement are not needed for the example. Setting papersize, orientation and margins do affect the result. To position something using ODS LAYOUT ABSOLUTE I recommend to the set the proper margins. Then the X= and Y= will be measured from the margins settings.
ballardw
Super User

Just for curiosity sake, why are your paper margins in inches when all the other measures are in CM?

 

_Manhattan
Quartz | Level 8
That is due to the article I was building the code with. But as I am more familiar with cm, it seemed somehow easier to work with cm for specific objects (e. g. ods text) and use the "template" from the paper which used inches.
KerryLuis
Calcite | Level 5

Make sure the path to your image is correct. Double-check the file location, and maybe try using a relative path. Consider the image format – the code suggests a .jpg, but the file extension in your text might be a typo (".jpg.jpg"). Ensure consistency. As for controlling image size without pre-adjusting, you can try the width and height options in your ods text statement.

KerryLuis
Calcite | Level 5

For example: scss Copy code ods text='^{style[preimage="C:/Users/WissMit/Desktop/example.jpg" width=200px height=150px]}'; Feel free to experiment with those values to get the desired size.

 

And when you need to compress image, you can just use JPEG Optimizer tools or functions within SAS.

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!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 10 replies
  • 4119 views
  • 6 likes
  • 5 in conversation