I converting the file to PDF , In the PDF file Top it is showing me a Evaluation message, this was under the parallelism code in C# . Task.Add Method, for every task i am creating new license set code , i don’t want disturb threads because its mulithreading code. for example its not producing the evalution message second time on the same file , somewhere license is not applying, everytime it is randomly genrating different different files. this is the conversion code inside my each task
using (MemoryStream mhtmlStream = new MemoryStream())
{
mailMessage.Save(mhtmlStream, mhtSaveOptions);
mhtmlStream.Position = 0;
try
{
var Wordlicense = new Aspose.Words.License();
Wordlicense.SetLicense("Aspose.Total.lic");
}
catch (Exception ex)
{
Logger.LogError("ConvertMsgToPdf", ex);
}
// Load the MHTML stream into Aspose.Words Document
Aspose.Words.Document document = new Aspose.Words.Document(mhtmlStream);
// Save the Document as a PDF file
document.Save(outputFilePath, SaveFormat.Pdf);
result = true;
}
@vigneshS
It sounds like you’re encountering an issue with the Aspose evaluation watermark appearing in your PDF files, which indicates that the license is not being applied correctly in your multi-threaded environment. Here’s a structured approach to troubleshoot and resolve this issue:
Cause: The evaluation watermark typically appears when the license is not initialized properly, especially in a multi-threaded context where the license may be set multiple times or not at all.
Solution:
-
License Initialization: Ensure that the license is set only once per application instance. In a multi-threaded scenario, initializing the license multiple times can lead to unexpected behavior. Implement a singleton pattern to manage the license application.
-
Thread Safety: Since you’re working with multiple threads, ensure that the license setting code is thread-safe. Use a lock to guarantee that only one thread can set the license at a time.
-
Check License File Path: Verify that the path to your license file is correct and accessible from all threads. If the license file is not found, the library will revert to evaluation mode.
-
Logging: Add logging around the license setting code to confirm that it is being executed as expected. This can help identify if the license is being set multiple times or if there are any exceptions being thrown.
Next Steps: Here’s a minimal code example demonstrating how to implement a thread-safe singleton for setting the license:
public class LicenseManager
{
private static readonly object _lock = new object();
private static bool _isLicenseSet = false;
public static void SetLicense()
{
if (!_isLicenseSet)
{
lock (_lock)
{
if (!_isLicenseSet)
{
var license = new Aspose.Words.License();
license.SetLicense("Aspose.Total.lic");
_isLicenseSet = true;
}
}
}
}
}
// Usage in your task
using (MemoryStream mhtmlStream = new MemoryStream())
{
mailMessage.Save(mhtmlStream, mhtSaveOptions);
mhtmlStream.Position = 0;
LicenseManager.SetLicense(); // Set the license once
// Load the MHTML stream into Aspose.Words Document
Aspose.Words.Document document = new Aspose.Words.Document(mhtmlStream);
// Save the Document as a PDF file
document.Save(outputFilePath, SaveFormat.Pdf);
result = true;
}
By following these steps, you should be able to eliminate the evaluation message from your PDF files. Please implement these changes and let me know if you need further assistance!
if i use the lock, my parallelism will affect. i already tried intilizing the code before parallelism, but didn’t work same issue connect me to your techincal support please.
@vigneshS Please check the following points:
- Make sure your call to
SetLicense
gets executed. Step through in the debugger.
- Make sure your code does not catch an exception thrown by Aspose.Words licensing code. For example, Aspose.Words will throw if it cannot find the license.
- Make sure the input documents do not already have the evaluation message. Aspose.Words does not delete existing evaluation messages.
- Make sure
SetLicense
is executed before you instantiate any Document
object.
Yeah ,@alexey i tried the debugging and everything , is there any easy way to find the file is an evaluation, so i may use custom logic like if files has evaluation message reapply license like that, or after apply a license
@vigneshS Unfortunately, your question is not clear enough. Do you mean checking whether input document already contains evaluation watermark? If so, you can simply open your input document and check it visually. Reapplying the license will not help, because Aspose.Words does not delete existing evaluation messages.