0

I'm trying to use NPOI to add watermark to .docx document.

Unfortunately documentation for NPOI is very scarce.

I found one method CreateWatermark() that is suppose to add the watermark.

    public FileResult Test()
    {
        Stream stream = new System.IO.FileStream(@"C:\wordFiles\test.docx", FileMode.Open);

        XWPFDocument document = new XWPFDocument(stream);

        XWPFHeaderFooterPolicy hfPolicy = new XWPFHeaderFooterPolicy(document);
        hfPolicy.CreateWatermark("My Watermark");


        MemoryStream output = new MemoryStream();
        document.Write(output);

        return File(output.ToArray(),   
        "application/msword",
        "test.docx");   

    }

But this corrupts the docx document. It says when trying to open it : ,,unidentified error. Localization word/header1.xml"

Have you encountered this type of problem?

2
  • Can I assume that the mention of XLS and Excel in the comments are simple typos? Dec 12, 2014 at 10:07
  • @MartinLiversage yes sory :) that code was copied from somewhere else and i didnt edit the comments :)
    – cah1r
    Dec 12, 2014 at 10:09

1 Answer 1

0

This looks to be a bug of NPOI. https://github.com/nissl-lab/npoi/issues/678 is created

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.