ReporteRs (version 0.8.2)

addImage.docx: Add external image into a docx object

Description

Add external images into a docx object.

Usage

# S3 method for docx
addImage(doc, filename, bookmark,
  par.properties = parProperties(text.align = "center", padding = 5), width,
  height, ppi = 72, ...)

Arguments

doc

Object of class docx where external image has to be added

filename

"character" value, complete filename of the external image

bookmark

a character value ; id of the Word bookmark to replace by the image. optional. if missing, image is added at the end of the document. See bookmark.

par.properties

paragraph formatting properties of the paragraph that contains images. An object of class parProperties

width

image width in inches

height

image height in inches

ppi

dot per inches, default to 72

...

further arguments, not used.

Value

an object of class docx.

Details

If arguments width and height are missing, values will be defined as their respective number of pixels divide by ppi.

See Also

docx, addPlot.docx , addImage, bookmark

Examples

Run this code
# NOT RUN {
#START_TAG_TEST
doc.filename = "addImage_example.docx"

# set default font size to 10
options( "ReporteRs-fontsize" = 10 )

doc = docx( )
# files 'logo.jpg' and 'logosm.jpg' only exist in R for Windows
img.file1 = file.path( Sys.getenv("R_HOME"), "doc", "html", "logo.jpg" )
img.file2 = file.path( Sys.getenv("R_HOME"), "doc", "html", "logosm.jpg" )

if( file.exists( img.file1 ) && file.exists( img.file2 ) ){
  doc = addTitle( doc, "Add images with defaut PPI (72)", level = 1)
  doc = addTitle( doc, "Image 1", level = 2)
  doc = addImage(doc, img.file1 )
  doc = addTitle( doc, "Image 2", level = 2)
  doc = addImage(doc, img.file2 )
  doc = addTitle( doc, "Add images with their respective PPI", level = 1)
  doc = addTitle( doc, "Image 1", level = 2)
  doc = addImage(doc, img.file1, ppi = 300 )
  doc = addTitle( doc, "Image 2", level = 2)
  doc = addImage(doc, img.file2, ppi = 96)
  doc = addTitle( doc, "Add images with width and height", level = 1)
  doc = addImage(doc, img.file1, width = 4, height = 2 )
}
if( exists("win.metafile") ){
	win.metafile(filename = "image.wmf", width = 5, height = 5 )
	barplot( 1:6, col = 2:7)
	dev.off()
	
	doc =addImage(doc, "image.wmf", width = 5, height = 5 )
}

# Write the object
writeDoc( doc, file = doc.filename )
#STOP_TAG_TEST
# }

Run the code above in your browser using DataLab