I would like to add a DRAFT watermark to my documents using your Aspose.Word tool. Currently I am doing this using word automation and would like to stop using that.
This is how I am currently doing this. How would I do this using your tool?:
The following is the error message that I am receiving:
Message "Object reference not set to an instance of an object." String
StackTrace " at Aspose.Words.DocumentBuilder.InsertNode(Node node)
at Aspose.Words.DocumentBuilder.InsertImage(Byte[] imageBytes, RelativeHorizontalPosition horzPos, Double left, RelativeVerticalPosition vertPos, Double top, Double width, Double height, WrapType wrapType)
at Aspose.Words.DocumentBuilder.InsertImage(Stream stream, RelativeHorizontalPosition horzPos, Double left, RelativeVerticalPosition vertPos, Double top, Double width, Double height, WrapType wrapType)
at Aspose.Words.DocumentBuilder.InsertImage(String fileName, RelativeHorizontalPosition horzPos, Double left, RelativeVerticalPosition vertPos, Double top, Double width, Double height, WrapType wrapType)
at Aspose.Words.DocumentBuilder.InsertImage(String fileName, Double width, Double height)
at Aspose.Words.DocumentBuilder.InsertImage(String fileName)
at Test.Net.Form1.Button7\_Click(Object sender, EventArgs e) in C:\Projects\Test.Net\Form1.vb:line 674" String
The first time the following code runs, it works fine. I get this error after I run the following code on an existing document a second time. It happens on the call to InsertImage. It is the same error I get when I use InsertNode.
oDialog.Filter = "Word Document (\*.doc)|\*.doc"
oDialog.ShowDialog()
szFile = oDialog.FileName
'Open the template document
oDoc = New Aspose.Words.Document(szFile)
'Create a document builder that will allow us to modify the document.
oBuilder = New DocumentBuilder(oDoc)
'The cursor is in the first section already, navigate to the header as this is where
'we want to insert the watermark.
oBuilder.MoveToHeaderFooter(HeaderFooterType.HeaderPrimary)
'remove any existing watermarks
For Each oSection In oDoc.Sections
oSection.DeleteHeaderFooterShapes()
Next
oShape = oBuilder.InsertImage("C:\Program Files\Aspose\Aspose.Words\Demos\Documents\Aspose.Logo.gif")
'oShape = oBuilder.InsertImage("C:\Test Reports\draft8.GIF")
oShape.WrapType = WrapType.None
oShape.BehindText = True
' Position the image in the center of the page.
oShape.RelativeHorizontalPosition = RelativeHorizontalPosition.Page
oShape.HorizontalAlignment = HorizontalAlignment.Center
oShape.RelativeVerticalPosition = RelativeVerticalPosition.Page
oShape.VerticalAlignment = VerticalAlignment.Center
'Insert a table with other office information in the footer.
oBuilder.MoveToHeaderFooter(HeaderFooterType.FooterPrimary)
Dim topBorder As Aspose.Words.Border = oBuilder.CellFormat.Borders(BorderType.Top)
topBorder.LineStyle = LineStyle.Single
topBorder.LineWidth = 1
oBuilder.InsertCell()
oBuilder.CellFormat.Width = 3 \* 72
oBuilder.Write(String.Format("Processed on: {0}", DateTime.Today.ToLongDateString()))
oBuilder.InsertCell()
oBuilder.ParagraphFormat.Alignment = ParagraphAlignment.Right
oBuilder.Write("Version 1.00")
oBuilder.EndRow()
oBuilder.EndTable()
oDoc.Save(szFile, SaveFormat.Doc)
Also I noticed that I will lose pages on the document. Is this because I am using the trial version of Aspose.Words?
Yes, it maybe caused by trial version limitations as trial version truncates the document. Try requesting a temporary license as described in https://docs.aspose.com/words/net/licensing/
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
Enables storage, such as cookies, related to analytics.
Sets consent for sending user data to Google for online advertising purposes.
Sets consent for personalized advertising.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
More info
Enables storage, such as cookies, related to analytics.
Enables storage, such as cookies, related to advertising.
Sets consent for sending user data to Google for online advertising purposes.
Sets consent for personalized advertising.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
More info
Enables storage, such as cookies, related to analytics.
Enables storage, such as cookies, related to advertising.
Sets consent for sending user data to Google for online advertising purposes.