Code: Select all
string _imageTestOriginalDocFilePath = @"C:\Documents and Settings\wesw\Desktop\PDF Inserter Files\AmyuniTest\2009Jan01Letters_0138191_147789.pdf";
string _imageFilePath = @"C:\Documents and Settings\wesw\Desktop\PDF Inserter Files\Amyuni Test\sample-barcode.jpg";
int _pageNumber = 2;
int _xCoord = 0;
int _yCoord = 0;
int _imageHeight = 500;
int _imageWidth = 499;
private void button2_Click(object sender, EventArgs e)
{
acPDFCreatorLib.Initialize();
// Open the original PDF document from file
FileStream origFile = new FileStream(_imageTestOriginalDocFilePath, FileMode.Open, FileAccess.ReadWrite, FileShare.Read);
IacDocument origDocument = new IacDocument(null);
origDocument.Open(origFile, "");
if (_pageNumber > origDocument.PageCount)
_pageNumber = origDocument.PageCount;
// Create image object & create picture object on page
origDocument.GetPage(_pageNumber).CreateObject(IacObjectType.acObjectTypePicture, "barcode");
// Get image object
IacObject newObj = origDocument.ObjectByName("barcode");
//Set Properties
newObj.AttributeByName("FileName").Value = _imageFilePath;
newObj.AttributeByName("Page").Value = _pageNumber;
newObj.AttributeByName("Left").Value = _xCoord;
newObj.AttributeByName("Top").Value = _yCoord;
newObj.AttributeByName("Right").Value = _imageWidth;
newObj.AttributeByName("Bottom").Value = _imageHeight;
// Refresh image and document
newObj.Redraw();
newObj = origDocument.ObjectByName("barcode");
newObj.Refresh();
origDocument.Redraw();
// Save document, remove references to the image object and the document, and close the filestream
origDocument.Save(origFile, IacFileSaveOption.acFileSaveAll);
newObj.Dispose();
origDocument.Dispose();
origFile.Close();
acPDFCreatorLib.Terminate();
Application.Exit();
}
Thanks in advance!
Wes