We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

Can we insert an image into an existing pdf that was recently created via doc to pdf converter

Do you have a sample that shows how to Insert an image in an existing pdf that was converted from word Doc originally.  Here's the code that I'm using to convert the word doc.

string ext = Path.GetExtension(file.Name).ToLower();
try
{
 FileStream FS;
 if (ext == ".doc" || ext == ".docx")
 {
 string strFullFileName = strPath + file.Name; 
 FS = File.OpenRead(strFullFileName);
 Stream readFile = FS;               

 WordDocument wordDoc = null;
 // check the word extension type
 if (ext == ".doc")
     wordDoc = new WordDocument(readFile, Syncfusion.DocIO.FormatType.Doc);
 else if (ext == ".docx")
     wordDoc = new WordDocument(readFile, Syncfusion.DocIO.FormatType.Docx);
 DocToPDFConverter converter = new DocToPDFConverter();
 //Convert word document into PDF document
 PdfDocument pdfDoc = converter.ConvertToPDF(wordDoc);
Could I insert the image here using pdfDoc or is that something that needs after I save the file (see below)


 // set password for security and view preferences
 pdfDoc.ViewerPreferences.FitWindow = true;
 pdfDoc.Security.OwnerPassword = "blahblahblah";

 //pdfDoc.Security.Permissions = Syncfusion.Pdf.Security.PdfPermissionsFlags.Print;
 pdfDoc.ViewerPreferences.PageLayout = PdfPageLayout.TwoPageLeft;
 NewFileName = NewFileName + ".pdf";
 //pdfDoc.Save(NewFileName, Response, HttpReadType.Save);
 pdfDoc.Save(strSavedFileLocation + NewFileName);
Or do I need to retrieve and load the new .pdf I just saved in the location in the line above (pdfDoc.Save) here.

}
catch{}

What I need to do is add/insert our logo 215px x 52px in the upper right hand corner of the first page.

 Any assistance would be greatly appreciated.

Jeff


1 Reply

PH Praveenkumar H Syncfusion Team October 18, 2013 04:26 AM UTC

Hi Jeff,

Thank you for using Syncfusion products,

We have created the sample to insert the image into pdf document as per your requirement.

The sample is attached for your reference.

http://www.syncfusion.com/downloads/support/directtrac/114248/DocToPdfWithImage890510326.zip

We can create the PdfImage as follow.

PdfImage image = PdfImage.FromFile(Server.MapPath('Data/logo.png'));

We can place the image into page as follow.

page.Graphics.DrawImage(image, pageWidth - 215, 0, 215, 52);

Please let us know if you need further assistance.

With Regards,

Praveen

 


Loader.
Live Chat Icon For mobile
Up arrow icon