We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

The document is changed after adding watermark and QR code

Hello,

Sorry to bother you again.

The document is changed after our client add the watermark and QR code. Can you help them to solve it?

I have attached these two documents for your reference.

Thanks & Regards

Sara Yu

Shenzhen Chinasoft Information Technology Co., Ltd.
Rm.209, Shenzhen Academy of Aeroapace Technology Bldg., Kejinan 10th Rd.,South High-tech Zone,Nanshan Dist.,Shenzhen,China 518057

Skype: sara.yu1688
Tel: +86-755-26994896

Fax: +86-755-26996813
Mob:+86-18823209951

Email: yujq@chinasofttech.com
Web: www.sz168.com.cn

Hi Chinasoft,

Thanks for your inquiry. I have tested the scenario using the approach shared here and have not found the shared issue.

In case you are using an older version of Aspose.Words, I would suggest you please upgrade to the latest version (v14.7.0) from here and let us know how it goes on your side. If the problem still remains, please create a standalone/runnable simple Java application that demonstrates the code you used to generate your output document. I will investigate the issue on my side and provide you more information.

Hi,

For the problem, kindly check the attached pictures. The Format of document changes and justified on both side after they add the watermark.

Thanks & Regards

余佳婧 (Sara Yu)

Tel: +86-755-26994896

Mob:+86-18823209951

Hi Chinasoft,

Thanks for your inquiry. In case you are using an older version of Aspose.Words, I would suggest you please upgrade to the latest version (v14.7.0) from here and let us know how it goes on your side.

I have tested the scenario using latest version of Aspose.Words for Java 14.7.0 and have not found the shared issue. I have used the following code example to test this issue. Please check the attached output document.

private static void insertWatermarkImage(Document doc, String image) throws Exception
{
    // Create a watermark shape. This will be a WordArt shape.
    // You are free to try other shape types as watermarks.
    Shape watermark = new Shape(doc, ShapeType.IMAGE);
    watermark.getImageData().setImage(image);
    // Place the watermark in the page center.
    watermark.setRelativeHorizontalPosition(RelativeHorizontalPosition.PAGE);
    watermark.setRelativeVerticalPosition(RelativeVerticalPosition.PAGE);
    watermark.setWrapType(WrapType.NONE);
    watermark.setVerticalAlignment(VerticalAlignment.CENTER);
    watermark.setHorizontalAlignment(HorizontalAlignment.CENTER);
    // Create a new paragraph and append the watermark to this paragraph.
    Paragraph watermarkPara = new Paragraph(doc);
    watermarkPara.appendChild(watermark);
    // Insert the watermark into all headers of each document section.
    for (Section sect : doc.getSections())
    {
        // There could be up to three different headers in each section, since we want
        // the watermark to appear on all pages, insert into all headers.
        insertWatermarkIntoHeader(watermarkPara, sect, HeaderFooterType.HEADER_PRIMARY);
        insertWatermarkIntoHeader(watermarkPara, sect, HeaderFooterType.HEADER_FIRST);
        insertWatermarkIntoHeader(watermarkPara, sect, HeaderFooterType.HEADER_EVEN);
    }
}

Hi,

Thanks.This problem has been solved after they updated to the the newest version.(aspose-words-14.7.0-jdk16.jar)

But a new problem came out. It was unable to add the watermark into the picture (attached document).It works fine in the old version.

Best Regards

Sara

Hi Sara,

Thanks for your inquiry. It would be great if you please share following detail for investigation purposes.

  • Please attach your input Word document.
  • Please

create a standalone/runnable simple Java application that demonstrates the code (Aspose.Words code) you used to generate
your output document

  • Please attach the output Word file that shows the undesired behavior.
  • Please
    attach your target Word document showing the desired behavior. You can
    use Microsoft Word to create your target Word document. I will
    investigate as to how you are expecting your final document be generated
    like.

Unfortunately,
it is difficult to say what the problem is without the Document(s) and
simplified application. We need your Document(s) and simple project to
reproduce the problem. As soon as you get these pieces of information to
us we’ll start our investigation into your issue.

Hi ,

Here the code:

private void xxxxxx(DecorateContext context, byte[] qrCodeBytes, byte[] wmBytes) throws Exception
{
    Document doc = context.getContent(Document.class);

    Map<String, Paragraph> wmGraphMap = new HashMap<>();
    Map<String, Paragraph> qrCodeGraphMap = new HashMap<>();
    HeaderFooter headerFooter = null  ;
    // Insert the watermark into all headers of each document section.
    for (Section sect : doc.getSections()) {
        PageSetup ps = sect.getPageSetup();
        String key = ps.getPageWidth() + "_" + ps.getPageHeight();
        if (wmBytes != null) {
            Paragraph watermarkPara = wmGraphMap.get(key);
            if (watermarkPara == null) {
                watermarkPara = new Paragraph(doc);
                watermarkPara.appendChild(generateShape(context, doc, ps, wmBytes, ImageType. WATERMARK));
                wmGraphMap.put(key, watermarkPara);
            }
            // There could be up to three different headers in each section,
            // since we want
            // the watermark to appear on all pages, insert into all headers.
            insertWatermarkIntoHeader(watermarkPara, sect, headerFooter, HeaderFooterType. HEADER_PRIMARY);
            insertWatermarkIntoHeader(watermarkPara, sect, headerFooter, HeaderFooterType. HEADER_FIRST);
            insertWatermarkIntoHeader(watermarkPara, sect, headerFooter, HeaderFooterType. HEADER_EVEN);
        }
    }
    doc.updatePageLayout();
}

private void yyyyy(Paragraph watermarkPara, Section sect, HeaderFooter headerFooter, int headerType) throws  Exception {
    HeaderFooter header = sect.getHeadersFooters().getByHeaderFooterType(headerType);
    if(header == null  ) {
        if(headerFooter == null  ) {
            header = new HeaderFooter(sect.getDocument(), headerType);
            sect.getHeadersFooters().add(header);
        }
        else  {
            header = (HeaderFooter)headerFooter.deepClone(true  );
        }
    }
    else  {
        headerFooter = (HeaderFooter)header.deepClone(true  );
    }
    Paragraph gg = header.getLastParagraph();
    if(gg != null  ) {
        Paragraph newnode = (Paragraph)watermarkPara.deepClone(true  );
        int  count = newnode.getCount();
        if(count >= 1) {
            gg.appendChild(newnode.getFirstChild());
        }
        if(count >= 2) {
            gg.appendChild(newnode.getLastChild());
        }
    }
    else  {
        header.appendChild(watermarkPara.deepClone(true  ));
    }
}

And when they add the watermark in the document, it said:

log4j:WARN No appenders could be found for logger (webLogger).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See <http://logging.apache.org/log4j/1.2/faq.html#noconfig> for more info.
com.huawei.it.edoc.decorate.DecorateException: process failed
at com.huawei.it.edoc.decorate.WordDecorator.process(WordDecorator.java:247)
at com.huawei.it.edoc.decorate.AbstractDecorator.decorate(AbstractDecorator.java:78)
at com.huawei.it.edoc.decorate.WordDecoratorTest.test(WordDecoratorTest.java:64)
at com.huawei.it.edoc.decorate.WordDecoratorTest.main(WordDecoratorTest.java:31)
Caused by: java.lang.RuntimeException: java.lang.RuntimeException: java.lang.IllegalArgumentException: Width (0) and height (0) cannot be <= 0
at com.aspose.words.zzZQK.zzZ(Unknown Source)
at com.aspose.words.zzZQK.zzY(Unknown Source)
at com.aspose.words.zzZ4A.zzZiC(Unknown Source)
at com.aspose.words.zzZ49.getWidth(Unknown Source)
at com.aspose.words.zzZ4B.zzu0(Unknown Source)
at com.aspose.words.zzZ54.getWidth(Unknown Source)
at com.aspose.words.zzZPV.zzZLr(Unknown Source)
at com.aspose.words.zzZPV.zzT(Unknown Source)
at com.aspose.words.zzZQ2.zzS(Unknown Source)
at com.aspose.words.zzZQ1.zzQ(Unknown Source)
at com.aspose.words.zzZQ1.zzX(Unknown Source)
at com.aspose.words.zzWN.zzZ(Unknown Source)
at com.aspose.words.zzZ5I.zzZkN(Unknown Source)
at com.aspose.words.zzZ5I.zzZ(Unknown Source)
at com.aspose.words.zzXJ.zzvn(Unknown Source)
at com.aspose.words.zzXJ.zzX(Unknown Source)
at com.aspose.words.zzZE8.zzJ(Unknown Source)
at com.aspose.words.zzZE8.zzS(Unknown Source)
at com.aspose.words.zzZDQ.zzy(Unknown Source)
at com.aspose.words.zzZ3Q.zzSy(Unknown Source)
at com.aspose.words.zzDD.zzXY(Unknown Source)
at com.aspose.words.zzDE.zz9r(Unknown Source)
at com.aspose.words.zzZR3.zzZ(Unknown Source)
at com.aspose.words.Document.updatePageLayout(Unknown Source)
at com.huawei.it.edoc.decorate.WordDecorator.insertTextWatermark(WordDecorator.java:172)
at com.huawei.it.edoc.decorate.WordDecorator.process(WordDecorator.java:243)
… 3 more
Caused by: java.lang.RuntimeException: java.lang.IllegalArgumentException: Width (0) and height (0) cannot be <= 0
at com.aspose.words.zzE6.zzZ(Unknown Source)
at com.aspose.words.zzG1.zzZ(Unknown Source)
at com.aspose.words.zzG1.zzZ(Unknown Source)
at com.aspose.words.zzG1.zzY(Unknown Source)
at com.aspose.words.zzZQK.zzX(Unknown Source)
at com.aspose.words.zzZQK.zzZ(Unknown Source)
… 28 more
Caused by: java.lang.IllegalArgumentException: Width (0) and height (0) cannot be <= 0
at java.awt.image.DirectColorModel.createCompatibleWritableRaster(DirectColorModel.java:1016)
at java.awt.image.BufferedImage.(BufferedImage.java:340)
at asposewobfuscated.zzOY.(Unknown Source)
at asposewobfuscated.zzOY.(Unknown Source)
at asposewobfuscated.zzOY.(Unknown Source)
at com.aspose.words.zzF6.zzY(Unknown Source)
at com.aspose.words.zzF6.zzY(Unknown Source)
at com.aspose.words.zzF6.zzY(Unknown Source)
at com.aspose.words.zzF6.zzZ(Unknown Source)
at com.aspose.words.zzFK.zzZ(Unknown Source)
at com.aspose.words.zzFK.zzE(Unknown Source)
at com.aspose.words.zzFT.zzY(Unknown Source)
at com.aspose.words.zzFT.zzB(Unknown Source)
at com.aspose.words.zzFT.zzY(Unknown Source)
at com.aspose.words.zzFT.zzZ(Unknown Source)
at com.aspose.words.zzFT.zzZ(Unknown Source)
at com.aspose.words.zzH4.zzZ(Unknown Source)
at com.aspose.words.zzE6.zzZ(Unknown Source)
… 33 more

The version they used is aspose-words-14.7.0

And I also added the input document.

Any comments pls let me know.

Sara

Hi Sara,

Thanks for sharing the detail. I am afraid I can not find the code for generateShape method. Please share the complete code which you are using to generate output document.

Please
attach your target Word document showing the desired behavior. You can
use Microsoft Word to create your target Word document. I will
investigate as to how you are expecting your final document be generated
like.