While converting the Excel first to pdf and then to Word, a box around the watermark text can be seen in Word format. This is fine in PDF.
I have attached the PDF and converted Word file as well to this ticket.
The code to convert these files is attached as well:
import com.aspose.cells.*
import com.aspose.pdf.*
import com.aspose.pdf.DocSaveOptions
import java.io.FileInputStream
def excelFile = '/Users/nitesh.kc/Downloads/single page excel.xlsx'
def pdfFile = '/Users/nitesh.kc/Downloads/test pdf.pdf'
def wordFile = '/Users/nitesh.kc/Downloads/test word.docx'
def textStampWatermark = { finalPDF, watermarkMessage ->
TextStamp textStamp = new TextStamp(watermarkMessage)
textStamp.setBackground(false)
textStamp.setDraw(true)
textStamp.setOpacity(0.5)
textStamp.setOutlineOpacity(0.2)
textStamp.setOutlineWidth(1)
textStamp.setYIndent(20)
textStamp.setRotateAngle(55)
textStamp.getTextState().setFontSize(100)
textStamp.horizontalAlignment = HorizontalAlignment.Center
textStamp.verticalAlignment = VerticalAlignment.Center
textStamp.height = 60
textStamp.width = 500
for (int x = 1; x <= finalPDF.getPages().size(); x++) {
finalPDF.getPages().get_Item(x).addStamp(textStamp)
}
return finalPDF
}
// Step 1: Excel -> PDF
println "Converting Excel to PDF..."
def workbook = new com.aspose.cells.Workbook(excelFile)
workbook.save(pdfFile, com.aspose.cells.SaveFormat.PDF)
println "PDF created: ${pdfFile}"
// Step 2: Apply watermark
println "Applying watermark..."
def doc = new com.aspose.pdf.Document(pdfFile)
doc = textStampWatermark(doc, "Test Application")
doc.save(pdfFile)
println "Watermark applied"
// Step 3: PDF -> DOCX
println "Converting PDF to Word..."
def doc2 = new com.aspose.pdf.Document(pdfFile)
def saveOptions = new DocSaveOptions()
saveOptions.format = DocSaveOptions.DocFormat.DocX
doc2.save(wordFile, saveOptions)
println "Word file created: ${wordFile}"
The Aspose version we are using is:
‘com.aspose:aspose-words:26.2:jdk17’
‘com.aspose:aspose-cells:26.2’
‘com.aspose:aspose-pdf:26.1’
‘com.aspose:aspose-slides:26.2:jdk16’
test word.docx (134.1 KB)
test pdf.pdf (75.4 KB)
a { text-decoration: none; color: #464feb; } tr th, tr td { border: 1px solid #e6e6e6; } tr th { background-color: #f5f5f5; }
Could you please check why a box appears around the watermark text in the Word document?