Extract an image from a file and add it to the current page.

 

   

Syntax
 

[C#]
int AddImageFile(string path)
int AddImageFile(string path, int frame)

[Visual Basic]
Function AddImageFile(path As String) As Integer
Function AddImageFile(path As String, frame As Integer) As Integer

Throws Exceptions may throw Exception()

 

   

Params
 
Name Description
path

A file path, URL or html string to be added to the page.

frame

Some image types support multiple frames or pages. This is the one based index specifying the required frame (default one).

return The Object ID of the newly added Image Object.

 

   

Notes
 

Adds an image to the current page returning the ID of the newly added object.

This method supports JPEG, JPEG 2000, TIFF, EMF, WMF, PS (PostScript) or EPS (Encapsulated PostScript).

Images embedded using this method are inserted using a restricted range of ReadModules. For this reason you may wish to prefer the use of the AddImageObject method. AddImageFile is the equivalent of AddImageObject with the transparent parameter set to true.

The only difference between AddImageFile and AddImageObject relates to the treatment of EMF and WMF files. AddImageFile defaults to the EmfVector ReadModule which means that the vector nature of such files will be preserved. AddImageObject defaults to the BasicImage ReadModule which means that such files will be rasterized. For more details see the ReadModule property.

The image is scaled to fill the current Rect. It is transformed using the current Transform.

Transparency. Occasionally you may find that you need to invert the transparency of your image. To do this you can assign a decode array using the ID returned from this function.

To invert the transparency:

theDoc.SetInfo(theDoc.GetInfoInt(theID, "XObject"), "/SMask*/Decode", "[1 0]")

A similar technique can be used for inverting or altering color levels on the image itself.

To invert an RGB image:

theDoc.SetInfo(theDoc.GetInfoInt(theID, "XObject"), "/Decode", "[1 0 1 0 1 0]")

 

   

Example
 

The following code adds an image to the current page positioned at the bottom left. The width and height of the image are automatically inferred from the file supplied.

[C#]
Doc theDoc = new Doc();
theDoc.Rect.String = "0 0 0 0";
string thePath = Server.MapPath("../mypics/pic.jpg");
theDoc.AddImageFile(thePath, 1);
theDoc.Save(Server.MapPath("docaddimage.pdf"));
theDoc.Clear();

[Visual Basic]
Dim theDoc As Doc = New Doc()
theDoc.Rect.String = "0 0 0 0"
Dim thePath As String = Server.MapPath("../mypics/pic.jpg")
theDoc.AddImageFile(thePath, 1)
theDoc.Save(Server.MapPath("docaddimage.pdf"))
theDoc.Clear()


docaddimage.pdf