I am facing the problem that the license is not being applied correctly. Here I have some test code:
- Code: Select all
public static void Main(string[] args)
{
var fileMemoryStream =
new MemoryStream(File.ReadAllBytes("C:\\Users\\cjosse\\Downloads\\MIL-KBOS-00163_OFF_DIR_ALG_UG1_N_2146.rtf"));
Document doc = new Document();
doc.LoadFromStream(fileMemoryStream, FileFormat.Rtf);
MemoryStream pdfMemoryStream = new MemoryStream();
doc.SaveToStream(pdfMemoryStream, FileFormat.PDF);
File.WriteAllBytes("DDDDD.pdf", pdfMemoryStream.ToArray());
fileMemoryStream =
new MemoryStream(File.ReadAllBytes("C:\\Users\\cjosse\\Downloads\\815_SNapp_bestelling_243605_ - Copy.rtf"));
//doc = new Document();
doc.LoadFromStream(fileMemoryStream, FileFormat.Rtf);
doc.SaveToStream(pdfMemoryStream, FileFormat.PDF);
File.WriteAllBytes("EEEE.pdf", pdfMemoryStream.ToArray());
}
If I uncomment the line "//doc = new Document();" the second converted pdf will have a limit of 10 pages and the "Evaluation Warning: The document was created with Spire.Doc for .NET." on all pages.
Our actual project is of course not this simple, as I need to convert multiple files asynchronously. Which should work because example like this has no problem detecting the license correctly:
- Code: Select all
public static async Task Main(string[] args)
{
var files = new List<string>
{
"C:\\Users\\cjosse\\Downloads\\MIL-KBOS-00163_OFF_DIR_ALG_UG1_N_2146.rtf",
"C:\\Users\\cjosse\\Downloads\\AnotherFile.rtf"
};
var tasks = new List<Task>();
foreach (var file in files)
{
tasks.Add(ConvertFileAsync(file));
}
await Task.WhenAll(tasks);
}
private static async Task ConvertFileAsync(string filePath)
{
await Task.Run(() =>
{
var fileMemoryStream = new MemoryStream(File.ReadAllBytes(filePath));
Document doc = new Document();
doc.LoadFromStream(fileMemoryStream, FileFormat.Rtf);
MemoryStream pdfMemoryStream = new MemoryStream();
doc.SaveToStream(pdfMemoryStream, FileFormat.PDF);
string outputFileName = Path.GetFileNameWithoutExtension(filePath) + ".pdf";
File.WriteAllBytes(outputFileName, pdfMemoryStream.ToArray());
});
}
But again our project is not as simple, the conversion is called from different classes. Is there a way to set up de project so that the license will get detected correctly?
Here are all the functions where the library is called:
- Code: Select all
public void ConvertRtfToPdf(MemoryStream fileMemoryStream, string pdfFilePath)
{
Document doc = new Document();
doc.LoadFromStream(fileMemoryStream, FileFormat.Rtf);
doc.SaveToFile(pdfFilePath, FileFormat.PDF);
}
public MemoryStream ConvertRtfToPdf(Stream fileMemoryStream)
{
Document doc = new Document();
doc.LoadFromStream(fileMemoryStream, FileFormat.Rtf);
MemoryStream pdfMemoryStream = new MemoryStream();
doc.SaveToStream(pdfMemoryStream, FileFormat.PDF);
return pdfMemoryStream;
}
public async Task<MemoryStream> ConvertRtfToPdf(string rtfFilePath)
{
var fileMemoryStream = await getMemoryStreamHttpsAsync(rtfFilePath);
fileMemoryStream.Position = 0;
return ConvertRtfToPdf(fileMemoryStream);
}
public async Task ConvertRtfToPdf(string rtfFilePath, string pdfOutputFilePath)
{
ConvertRtfToPdf(await getMemoryStreamHttpsAsync(rtfFilePath), pdfOutputFilePath);
}
public async Task<(MemoryStream convertedPdf, int pageCount)> ConvertRtfToPdf_andPageCount(string rtfFilePath)
{
Document doc = new Document();
var fileMemoryStream = await getMemoryStreamHttpsAsync(rtfFilePath);
fileMemoryStream.Position = 0;
doc.LoadFromStream(fileMemoryStream, FileFormat.Rtf);
var pageCount = doc.PageCount;
MemoryStream pdfMemoryStream = new MemoryStream();
doc.SaveToStream(pdfMemoryStream, FileFormat.PDF);
return (pdfMemoryStream, pageCount);
}