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

Free Support Forum - aspose.com

Set License of Aspose.Words for Java using Streams | FileInputStream | java.io.File

Hi

I used below code for Aspose word License but its not working.
String wordFilePath = “Doc/Aspose.Total.Java.lic”;
FileInputStream wordStream = new FileInputStream(new File(wordFilePath));
// Instantiate the License class
com.aspose.words.License wordLicense = new com.aspose.words.License();
// Set the license through the stream object
wordLicense.setLicense(wordStream);

@dixit44,

I am afraid, we do not see any problem when setting license using your code on our end. Do you see evaluation watermark in generated document or does this code throw any exception?

Please post your license file via private message. In order to send a private message with attachment, please click on my name and find “Message” button.

License is not working for Aspose word

We will then investigate the issue with your license file on our end and provide you more information.

P.S. Please do not share your license file publicly in forum threads.

Hi Awais

As you suggest i post file using private message.

@dixit44,

Thanks for sharing your license file via private message. But, the license file you shared is working perfectly fine when testing it with the latest version of Aspose.Words for Java i.e. 20.2 on our end. So, we suggest you please upgrade to the latest version of Aspose.Words for Java on your end. Hope, this helps.

We used the following code to test your license file on our end:

String wordFilePath = "Aspose.Total.Java.lic";
FileInputStream wordStream = new FileInputStream(new File(wordFilePath));
// Instantiate the License class
com.aspose.words.License wordLicense = new com.aspose.words.License();
// Set the license through the stream object
wordLicense.setLicense(wordStream);

Hi Awais

I am using Aspose with Alfresco for WaterMarking.
I am creating one Jar with Aspose code and adding jar in side Alfresco jar folder.
i try to add License file with jar but getting
[http-apr-8080-exec-1] Aspose.Total.Java.lic (No such file or directory)
2020-03-09 05:01:32,938 ERROR [org.springframework.extensions.webscripts.AbstractRuntime] [http-apr-8080-exec-1] Exception from executeScript: null
java.lang.NullPointerException
at com.tcs.addWatermarkWebscript.execute(addWatermarkWebscript.java:69)

where should i add this License file ?

@dixit44,

You can specify complete absolute path to the LIC file e.g.

E:\\YourApp\\Resources\\Aspose.Total.Java.lic

For more information, please refer to the following section of documentation:

Hi Awais

My Watermark Text hidden with image .word file attach. how can i make transparent watermark over the image ?
word.zip (122.0 KB)

Hi Awais

I tested with below code ,it’s working fine with .docx format but not working with .doc format . did you check with .doc format.

String wordFilePath = “Aspose.Total.Java.lic”;
FileInputStream wordStream = new FileInputStream(new File(wordFilePath));
// Instantiate the License class
com.aspose.words.License wordLicense = new com.aspose.words.License();
// Set the license through the stream object
wordLicense.setLicense(wordStream);

@dixit44,

The problem occurs because watermark shape resides inside header footer story and main content is inside body story (please see Story class). If you insert a watermark using Microsoft Word 2019, you will observe the same behavior. All content of document’s header/footer is always behind the main content of the document.

However, you may overcome this problem by manually inserting watermarks in each Page. You can achieve this by moving the cursor to the first Run in each Page of your document and then making those Runs as an anchor points for your watermarks. Please see the following code for example:

Document doc = new Document("E:\\Temp\\Word\\UI Flow for  atv-tables-crudDoc.doc");

Node[] runs = doc.getChildNodes(NodeType.RUN, true).toArray();
for (int i = 0; i < runs.length; i++) {
    Run run = (Run) runs[i];
    int length = run.getText().length();

    Run currentNode = run;
    for (int x = 1; x < length; x++) {
        currentNode = SplitRun(currentNode, 1);
    }
}

DocumentBuilder builder = new DocumentBuilder(doc);
PageSetup ps = builder.getPageSetup();

NodeCollection smallRuns = doc.getChildNodes(NodeType.RUN, true);
LayoutCollector collector = new LayoutCollector(doc);

int pageIndex = 1;
for (int i = 0; i < smallRuns.getCount(); i++) {
    Run run = (Run) smallRuns.get(i);
    if (collector.getStartPageIndex(run) == pageIndex) {
        Shape watermark = new Shape(doc, ShapeType.TEXT_PLAIN_TEXT);
        watermark.setRelativeHorizontalPosition(RelativeHorizontalPosition.PAGE);
        watermark.setRelativeVerticalPosition(RelativeVerticalPosition.PAGE);

        watermark.setWidth(300);
        watermark.setHeight(70);
        watermark.setHorizontalAlignment(HorizontalAlignment.CENTER);
        watermark.setVerticalAlignment(VerticalAlignment.CENTER);

        watermark.setRotation(-40);
        watermark.getFill().setColor(Color.GRAY);
        watermark.setStrokeColor(Color.GRAY);

        watermark.getTextPath().setText("ALTICE CONFIDENTIAL");
        watermark.getTextPath().setFontFamily("Arial");

        watermark.setName("WaterMark_" + i + "");
        watermark.setWrapType(WrapType.NONE);

        builder.moveTo(run);
        builder.insertNode(watermark);

        pageIndex++;
    }
}

doc.save("E:\\Temp\\Word\\awjava-20.3.doc");

private static Run SplitRun(Run run, int position) throws Exception {
    Run afterRun = (Run) run.deepClone(true);
    afterRun.setText(run.getText().substring(position));
    run.setText(run.getText().substring(0, position));
    run.getParentNode().insertAfter(afterRun, run);
    return afterRun;
}

Hope, this helps.

@dixit44,

The license file you shared earlier still works fine even when processing DOC format on our end. Please check the output DOC file that we generated by using the code from here: