PDF Xpress for .NET - User Guide > How To > Modify PDF Document Content > Add Images to a PDF Page |
Images can be added to a specified location on an existing PDF page, using the AddImage methods.
C# Example |
Copy Code
|
---|---|
// This code demonstrates how to add an image from a file // Adds an image to a page in an open PDF document public void AddImageFromFile(Document document, Int32 pageIndex, String imageFilename, Int32 imagePageIndex) { try { // Get the chosen page's dimensions PageInfo pageInfo = document.GetInfo(pageIndex); // Will fit the image to the current PDF page dimensions document.AddImage(pageIndex , pageInfo.ClipX , pageInfo.ClipY , pageInfo.ClipWidth , pageInfo.ClipHeight , ImageFitSettings.Grow , imageFilename , imagePageIndex ); } catch (PdfXpressLibraryException) { // A problem was encountered attempting to add image } catch (PdfXpressException) { // A problem was encountered attempting to add image } finally { } } |
C# Example |
Copy Code
|
---|---|
// This code demonstrates how to add an image from Global Memory public void AddImageFromGlobalMemory(Document document, Int32 pageIndex, IntPtr globalBufferHandlePtr, Int32 imagePageIndex) { try { // Get the chosen page's dimensions. PageInfo pageInfo = document.GetInfo(pageIndex); // Will fit the image to the current PDF page dimensions. document.AddImage(pageIndex , pageInfo.ClipX , pageInfo.ClipY , pageInfo.ClipWidth , pageInfo.ClipHeight , ImageFitSettings.Grow , globalBufferHandlePtr , imagePageIndex ); } catch (PdfXpressLibraryException) { // A problem was encountered attempting to add image } catch (PdfXpressException) { // A problem was encountered attempting to add image } finally { } } |
C# Example |
Copy Code
|
---|---|
// This code demonstrates how to add an image from Local Memory public void AddImageFromLocalMemory(Document document, Int32 pageIndex, byte[] imageData, Int32 imagePageIndex) { try { // Get the chosen page's dimensions. PageInfo pageInfo = document.GetInfo(pageIndex); // Will fit the image to the current PDF page dimensions document.AddImage(pageIndex , pageInfo.ClipX , pageInfo.ClipY , pageInfo.ClipWidth , pageInfo.ClipHeight , ImageFitSettings.Grow , imageData , imagePageIndex ); } catch (PdfXpressLibraryException) { // A problem was encountered attempting to add image } catch (PdfXpressException) { // A problem was encountered attempting to add image } finally { } } |