Inserting letterhead graphic into document

I have a need to be able to insert a graphic at the top of a Word document file to use as a letterhead. Does anyone have an example of how to do that using Aspose Word? Or is there a way to start with an existing Word document that already has the graphic set up in it, then simply add the text to that file and save it as a new document? Any help with this will be greatly appreciated.

Hi

Thanks for your request. You can use both scenarios.

  1. You can insert your image into the header of the document. Please see the following link to learn how to create Header/footer using Aspose.Words:
    https://docs.aspose.com/words/net/working-with-headers-and-footers/
  2. You can create template in MS Word and use this template to generate documents using Aspose.Words. For example, you can use Mail Merge feature:
    https://docs.aspose.com/words/net/types-of-mail-merge-operations/

Please let me know in case of any issue, I will be glad to help you.
Best regards.

When I try to use this code:

Dim imageFileName As String = MyDir & "Aspose.Words.gif"
builder.InsertImage(imageFileName, RelativeHorizontalPosition.Page, 10, RelativeVerticalPosition.Page, 10, 50, 50, WrapType.Through)

I get this error:
(522): Value of type ‘String’ cannot be converted to ‘System.Drawing.Image’.
(523): Overload resolution failed because no accessible ‘InsertImage’ accepts this number of arguments.
What do I need to change to fix this?

Hi

Thanks for your request. This code works fine on my side. Here is InsertImage method overload you are trying to use:
https://reference.aspose.com/words/net/aspose.words/documentbuilder/insertimage/
Which version of Aspose.Words are you using? Maybe you should try using the latest version.
Also, the following code will do the same:

Shape img = builder.InsertImage(imageFileName);
img.RelativeHorizontalPosition = RelativeHorizontalPosition.Page;
img.Left = 10;
img.RelativeVerticalPosition = RelativeVerticalPosition.Page;
img.Top = 10;
img.Width = 50;
img.Height = 50;
img.WrapType = WrapType.Through;

Best regards.

I am unfamiliar with the Shape item above. I am getting an error that “Shape” is not declared.
Under references, it says our version of Aspose Word is 2.3.3.0.

Hi

Thanks for your inquiry. This is very old version of Aspose.Words. Current version is 6.2.0.
https://releases.aspose.com/words/net
I am not sure does this version of Aspose.Words support this feature or not. Could you please check value of what type DocumentBuilder.InsertImage returns?
Best regards.

I am not sure exactly what you are asking. But when I go to builder.insertimage in the program, it shows me Public sub Insertimage(image as System.drawing.image). Does that help?

Hi

Thank you for additional information. Yes, this helps. InsertImage in your version does not return anything. So only option I can suggest you is to upgrade to some newest version of Aspose.Words.
Best regards.

Is there an old version of Aspose.Word that is still newer than our version, which has this feature, that we could upgrade to at no cost? If not, what is the cheapest way to upgrade to a version that includes this feature?
Or is there an easy way to have a blank document with the graphic already in it, to use as a template, to be my starting document, then after inserting the text, to save as a new document? Do you have an example of how I could do it that way/

Hi

Thanks for your inquiry. The oldest version of Aspose.Words available on our site is 3.5.0.0
https://releases.aspose.com/words/net
You can use template that already contains image in it. Just create such document in MS Word and use it as starting document when create Aspose.Words.Document.

// Open document
Document doc = new Document("in.doc");

Best regards.