Comments (10)
@chengshuanghub 您能否在此处附上您的输入和输出文件以供我们参考。 我们将检查问题并为您提供更多信息。
顺便说一句,最新版本的 Aspose.Words 提供了一种在文档中添加水印的内置方法:
https://docs.aspose.com/words/java/working-with-watermark/
from aspose.words-for-java.
@chengshuanghub 您能否在此处附上您的输入和输出文件以供我们参考。 我们将检查问题并为您提供更多信息。 顺便说一句,最新版本的 Aspose.Words 提供了一种在文档中添加水印的内置方法: https://docs.aspose.com/words/java/working-with-watermark/
麻烦您帮忙看看。
输入文件:
页眉测试.docx
输出文件:
test4.docx
from aspose.words-for-java.
@chengshuanghub 出现此问题的原因是您插入带有段落的水印。 请看下面的截图。 为避免该问题,您应该在现有段落中插入水印形状。
或者您可以简单地使用内置方法插入水印:
Document doc = new Document("C:\\Temp\\in.docx");
doc.getWatermark().setText("11111111111111111111111");
doc.save("C:\\Temp\\out.docx");
from aspose.words-for-java.
@chengshuanghub 出现此问题的原因是您插入带有段落的水印。 请看下面的截图。 为避免该问题,您应该在现有段落中插入水印形状。 或者您可以简单地使用内置方法插入水印:
Document doc = new Document("C:\\Temp\\in.docx"); doc.getWatermark().setText("11111111111111111111111"); doc.save("C:\\Temp\\out.docx");
您好,这个带有段落的水印不是我代码里加的,是加完水印后页眉就变成了2行,我添加的水印是不带段落的。内置方法插入好像设置不了位置,我们需要插入多个水印。
from aspose.words-for-java.
@chengshuanghub 在您的代码中,您为水印形状创建一个段落并将其附加到每个部分的每个标题中。 请参阅以下代码片段:
Paragraph watermarkPara = new Paragraph(doc);
watermarkPara.appendChild(watermark);
for (Section sect : doc.getSections()) {
insertWatermarkIntoHeader(watermarkPara, sect, HeaderFooterType.HEADER_PRIMARY);
}
正如我提到的,如果标题已经包含一个段落,您应该在这个现有段落中插入一个水印形状,而不是创建一个单独的段落。
from aspose.words-for-java.
@chengshuanghub 在您的代码中,您为水印形状创建一个段落并将其附加到每个部分的每个标题中。 请参阅以下代码片段:
Paragraph watermarkPara = new Paragraph(doc); watermarkPara.appendChild(watermark); for (Section sect : doc.getSections()) { insertWatermarkIntoHeader(watermarkPara, sect, HeaderFooterType.HEADER_PRIMARY); }正如我提到的,如果标题已经包含一个段落,您应该在这个现有段落中插入一个水印形状,而不是创建一个单独的段落。
请问您有获取现有段落并插入水印的例子吗?
from aspose.words-for-java.
@chengshuanghub 您可以使用如下代码:
HeaderFooter hf = sect.getHeadersFooters().getByHeaderFooterType(HeaderFooterType.HEADER_PRIMARY);
if(hf!=null)
{
hf.getFirstParagraph().appendChild(watermarkShape.deepClone(true));
}
from aspose.words-for-java.
@chengshuanghub 您可以使用如下代码:
HeaderFooter hf = sect.getHeadersFooters().getByHeaderFooterType(HeaderFooterType.HEADER_PRIMARY); if(hf!=null) { hf.getFirstParagraph().appendChild(watermarkShape.deepClone(true)); }
@AlexNosk 您好,我替换成上面的代码后,程序报错。您能帮忙看看吗?
报错信息:
java.lang.IllegalArgumentException: Cannot insert a node of this type at this location.
at com.aspose.words.CompositeNode.zzWwL(Unknown Source)
at com.aspose.words.CompositeNode.insertAfter(Unknown Source)
at com.aspose.words.CompositeNode.appendChild(Unknown Source)
at FileUtils.insertWatermarkIntoHeader(FileUtils.java:220)
at FileUtils.insertWatermarkText(FileUtils.java:180)
at FileUtils.setWordWaterMarkss(FileUtils.java:143)
at FileUtils.main(FileUtils.java:301)
from aspose.words-for-java.
@chengshuanghub 在您的代码中,您试图将一个段落插入另一个段落。 您应该插入水印形状,而不是水印段落。你应该插入这个节点
Shape watermark = new Shape(doc, ShapeType.TEXT_PLAIN_TEXT);
from aspose.words-for-java.
watermarkShape
@AlexNosk 插入水印形状后好了,谢谢您的帮助
from aspose.words-for-java.
Related Issues (20)
- 如何在手机上使用? HOT 1
- how to show all content of page by structure from top to bottom HOT 1
- Error in compressed image example on official website HOT 3
- All tests for table in LINQ_Reporting_Engine failed HOT 3
- fixed header on each page of the table HOT 2
- docx文件中表格每行高会增加,怎么处理呢?aspose word 15 HOT 6
- 为什么java docx转pdf 红头文件标题直接没了 HOT 5
- Insert html to Word,html forrmat is HOT 9
- Aspose.word function is missing HOT 9
- @SnowflyW Unfortunately, your request is not quite clear. Could you please elaborate your requirements in more details and attach your input document, sample data and the expected output? We will investigate and provide you more information.
- Invalid paragraph spacing setting HOT 2
- Typo Contents_managment HOT 1
- Missing text when convert word to pdf HOT 1
- word生成pdf时,段落中间若有——或短横线-,符号后会莫名加一个换行符 HOT 6
- fonts overlap using aspose HOT 1
- word转pdf后行距增加 HOT 2
- reporting engine how to fill in content controls HOT 1
- 如何在指定页面渲染目录 HOT 1
- the overlapping of labels and values for pie charts HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from aspose.words-for-java.