Hi,
I am trying to convert the word document file to a PDF file using the below code.
private static void CovertIntoPdf(string documentPath, string path)
{
FileStream docStream = new FileStream(documentPath, FileMode.Open, FileAccess.Read);
WordDocument document = new WordDocument(docStream, Syncfusion.DocIO.FormatType.Automatic);
DocIORenderer render = new DocIORenderer();
render.Settings.ChartRenderingOptions.ImageFormat = ExportImageFormat.Jpeg;
Console.WriteLine("Started " + DateTime.Now.ToString("yyyy.MM.dd HH:mm:ss:ffff"));
PdfDocument pdfDocument = render.ConvertToPDF(document);
Console.WriteLine("Ended " + DateTime.Now.ToString("yyyy.MM.dd HH:mm:ss:ffff"));
render.Dispose();
document.Dispose();
FileStream stream = new FileStream(path, FileMode.Create, FileAccess.ReadWrite);
var encodedData = ConvertPdfStreamToBase64(pdfDocument);
pdfDocument.Save(stream);
pdfDocument.Close();
}
PdfDocument pdfDocument = render.ConvertToPDF(document);
This particular method is taking almost 15 seconds to process the file. File size is only 195KB. For this, It is affecting the performance of my application.
Could you please help with some other alternative method to convert the Docx files to PDF format?
ThankYou in Advance.
Hi,
We have the same issue on our side and I guess this has to do with the docx template that we use and the amount of data (80 pages).
What do you mean with:
"
The main memory utilized by an instance will not be released until the instance is removed from the document.
"
Can you please provide a code example?
We do the pdfDocument.Close(true), is that not enough?
Our (k8s) pod takes 1GB for every call we make and does not seem to release it.
I will also create a support ticket to check our situation.
Hi,
I dont know why, only 21 pages without any images taking more than 1 minute for converting only.
using same method as mention above.
Is there any method for optimization ?.
sharing only conversion part of the code,
WordDocument document = new(byteDocument, FormatType.Automatic);
document.Replace("{{cFullName}}", customerName, caseSensitive, wholeWord);
document.Replace("{{cTckno}}", customerIdentity, caseSensitive, wholeWord);
document.Replace("{{cTaxOfficeAndNumber}}", customerTaxInfo, caseSensitive, wholeWord);
document.Replace("{{cAddress}}", customerAddress, caseSensitive, wholeWord);
document.Replace("{{cPhoneNumber}}", customerPhone, caseSensitive, wholeWord);
document.Replace("{{cEmail}}", customerEmail, caseSensitive, wholeWord);
document.Replace("{{cAuthorizedNameSurname}}", customerAuthFullname, caseSensitive, wholeWord);
document.Replace("{{cAuthorizedTCKN}}", customerAuthIdentity, caseSensitive, wholeWord);
document.Replace("{{cAuthorizedPhone}}", customerAuthPhone, caseSensitive, wholeWord);
document.Replace("{{packageNotIncludedAddress}}", packageNotIncludedAddress, caseSensitive, wholeWord);
document.Replace("{{orderPhoneNumber}}", packageType, caseSensitive, wholeWord);
document.Replace("{{orderCreatedDate}}", orderStartDate, caseSensitive, wholeWord);
document.Replace("{{orderEndDate}}", orderEndDate, caseSensitive, wholeWord);
document.Replace("{{orderMonth}}", orderMonth, caseSensitive, wholeWord);
document.Replace("{{packageType}}", packageType, caseSensitive, wholeWord);
document.Replace("{{monthlyCost}}", "", caseSensitive, wholeWord);
document.Replace("{{totalCost}}", totalCostStr, caseSensitive, wholeWord);
document.Replace("{{branchName}}", locationBranchName, caseSensitive, wholeWord);
document.Replace("{{taxOffice}}", locationTaxOffice, caseSensitive, wholeWord);
document.Replace("{{taxNumber}}", locationTaxNumber, caseSensitive, wholeWord);
document.Replace("{{locationAddress}}", locationAddress, caseSensitive, wholeWord);
document.Replace("{{agreementNumber}}", agreementNumber, caseSensitive, wholeWord);
foreach (WSection section in document.Sections)
{
section.HeadersFooters.Footer.ChildEntities.Clear();
}
DocIORenderer render = new();
render.Settings.ChartRenderingOptions.ImageFormat = (Syncfusion.OfficeChart.ExportImageFormat)ExportImageFormat.Jpeg;
render.Settings.OptimizeIdenticalImages = true;
Console.WriteLine("Started " + DateTime.Now.ToString("yyyy.MM.dd HH:mm:ss:ffff"));
PdfDocument pdfDocument = render.ConvertToPDF(document);
Console.WriteLine("Ended " + DateTime.Now.ToString("yyyy.MM.dd HH:mm:ss:ffff"));
render.Dispose();
document.Dispose();
MemoryStream outputStream = new();
pdfDocument.Save(outputStream);
pdfDocument.Close(true);
var pdfFile = outputStream.ToArray();
outputStream.Close();
I have attached the file which I am converting.
Started 2024.07.26 17:11:47:0103
Ended 2024.07.26 17:12:22:7659
Kindly help me out in this problem.
Thanks
Attachment: Sanal_Ofis_Sozlesme_For_General_31d85682.rar
Hi Sumit,
Based on the provided code snippet and input document, we have created a sample
and converted it to PDF using the given code. The conversion takes 6.44
seconds on our end. Please refer to the screenshot below and the attached
sample for more details.
We recommend upgrading to our latest version (v26.2.5) if you are using
an older version.
Regards,
Dharanya.