I'm using aspose.words in .net for a few things within my app. I'm adding a timestamp to the firstpage header. I'm also allowing the user to convert the word document to a pdf
The addition of the Timestamp works fine, but when the document is converted to a pdf the timestamp overlaps the exisiting header text. We need to be able to convert the document to pdf and keep the timestamp as it displays in the word document. Please Help!
I have attached a copy of the word docuemnt and below is the code we are using to add the timestamp and convert the document.
'''''''''''''''''''''''''''''''''''''''''Code to covert word document to pdf
Public Shared Function ConvertWordToPdf(ByRef length As Integer, ByVal stream As Stream, ByVal AcceptFinalChanges As Boolean) As Byte()
Try
Dim license As New Aspose.Words.License()
license.SetLicense(HttpContext.Current.Server.MapPath("~\Utility\Aspose.Words.lic"))
'create a new aspose document
Dim doc As New Document(stream)
Dim bytContent As Byte()
Using ms As New MemoryStream()
If (AcceptFinalChanges) Then
'accept all revisions if there are any (pending)
doc.AcceptAllRevisions()
End If
'convert the document to pdf and save into a memory stream
doc.Save(ms, SaveFormat.Pdf)
'set bytcontent equal to the memorystream
bytContent = ms.ToArray()
length = CType(ms.Length, Integer)
End Using
doc = Nothing
Return bytContent
Catch ex As Exception
Throw
Finally
If stream IsNot Nothing Then
stream.Flush()
stream.Close()
End If
End Try Public Shared Function ConvertWordToPdf(ByRef length As Integer, ByVal stream As Stream, ByVal AcceptFinalChanges As Boolean) As Byte()
Try
Dim license As New Aspose.Words.License()
license.SetLicense(HttpContext.Current.Server.MapPath("~\Utility\Aspose.Words.lic"))
'create a new aspose document
Dim doc As New Document(stream)
Dim bytContent As Byte()
Using ms As New MemoryStream()
If (AcceptFinalChanges) Then
'accept all revisions if there are any (pending)
doc.AcceptAllRevisions()
End If
'convert the document to pdf and save into a memory stream
doc.Save(ms, SaveFormat.Pdf)
'set bytcontent equal to the memorystream
bytContent = ms.ToArray()
length = CType(ms.Length, Integer)
End Using
doc = Nothing
Return bytContent
Catch ex As Exception
Throw
Finally
If stream IsNot Nothing Then
stream.Flush()
stream.Close()
End If
End Try
'''''''''''''''''''''''''''''''''''''''''Code to add watermark
' Create a watermark shape. This will be a WordArt shape.
' You are free to try other shape types as watermarks.
Dim watermark As New Shape(doc, ShapeType.TextPlainText)
' Set up the text of the watermark.
watermark.TextPath.Text = "Published on: " + datePublished
watermark.TextPath.FontFamily = "Arial"
watermark.Width = 300
watermark.Height = 10
' Text will be directed from the bottom-left to the top-right corner.
watermark.Rotation = 0
' Remove the following two lines if you need a solid black text.
watermark.Fill.Color = Color.Red
watermark.StrokeColor = Color.Red
watermark.VerticalAlignment = VerticalAlignment.Bottom
watermark.HorizontalAlignment = HorizontalAlignment.Left
' Create a new paragraph and append the watermark to this paragraph.
Dim watermarkPara As New Paragraph(doc)
watermarkPara.AppendChild(watermark)
Return watermarkPara ' Create a watermark shape. This will be a WordArt shape.
' You are free to try other shape types as watermarks.
Dim watermark As New Shape(doc, ShapeType.TextPlainText)
' Set up the text of the watermark.
watermark.TextPath.Text = "Published on: " + datePublished
watermark.TextPath.FontFamily = "Arial"
watermark.Width = 300
watermark.Height = 10
' Text will be directed from the bottom-left to the top-right corner.
watermark.Rotation = 0
' Remove the following two lines if you need a solid black text.
watermark.Fill.Color = Color.Red
watermark.StrokeColor = Color.Red
watermark.VerticalAlignment = VerticalAlignment.Bottom
watermark.HorizontalAlignment = HorizontalAlignment.Left
' Create a new paragraph and append the watermark to this paragraph.
Dim watermarkPara As New Paragraph(doc)
watermarkPara.AppendChild(watermark)
Return watermarkPara