Spire.Doc is a professional Word .NET library specifically designed for developers to create, read, write, convert and print Word document files. Get free and professional technical support for Spire.Doc for .NET, Java, Android, C++, Python.

Tue Dec 19, 2023 7:54 am

I have a folder store all fonts which will be embedded into Pdf file using Spire.Doc.Document.SaveToFile(string, ToPdfParameterList). First time i create Pdf file have fonts embedded using code below, it works fine. In second time, i delete one font in folder which embedded in first document. Problem is here, the Spire.Doc.Document.SaveToFile(string, ToPdfParameterList) method throw exception which have content like image i attach below. But when i restart my app, this problem disappear and everything work fine like nothing happened. Please help me investigate and solve this problem. Thanks for support.

Code: Select all
public byte[] ConvertToPDFBinary(string domainName, byte[] binaryWordData, string assignerSignager, string assignerBranch, string assignerInstitution, int strategyId)
        {
            byte[] bytePDF = null;
            try
            {
                var serverTempFolder = ApplicationConfiguration.GetSysConfiguration(Constants.ServerTempFolder);

                if (string.IsNullOrEmpty(serverTempFolder))
                    throw new InvalidOperationException("ServerTempFolder is not configured for domain [" + domainName + "]");

                var pathFileTemplate = Path.Combine(serverTempFolder, "LetterTemplate.PDF");

                using (var document = new Document())
                {
                    using (Stream s = new MemoryStream(binaryWordData))
                    {
                        document.LoadFromStream(s, FileFormat.Docx);

                        //replace dummy data
                        ReplaceDummyData(document, assignerSignager, assignerBranch);

                        var isEmbedFonts = GetIsEmbedFonts(strategyId);

                        var toPdfParams = new ToPdfParameterList();
                        if (isEmbedFonts)
                        {
                            toPdfParams = GetToPdfParameterList();
                        }
                        else
                        {
                            toPdfParams.UsePSCoversion = true;
                        }
                        document.SaveToFile(pathFileTemplate, toPdfParams);

                        var PDFVersion = GetPDFVersion();

                        if (PDFVersion != Spire.Pdf.PdfVersion.Version1_5)
                        {
                            using (var documentPDF = new Spire.Pdf.PdfDocument())
                            {
                                documentPDF.LoadFromFile(pathFileTemplate);
                                documentPDF.FileInfo.Version = PDFVersion;
                                documentPDF.SaveToFile(pathFileTemplate);
                            }
                        }

                        bytePDF = File.ReadAllBytes(pathFileTemplate);
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Error(ex);
                LogErrorToDB("ConvertToPDFBinary", ex.Message, Constants.SEV_URGENT, Constants.LEVEL_ERROR);
                bytePDF = null;
            }

            return bytePDF;
        }


public static ToPdfParameterList GetToPdfParameterList()
        {
            var fontsPath = Path.Combine(HttpContext.Current.Server.MapPath(Constants.FontFolderPath));

            var toPdfParams = new ToPdfParameterList()
            {
                UsePSCoversion = true
            };

            using (var fontCollection = new PrivateFontCollection())
            {
                var dInfo = new DirectoryInfo(fontsPath);
                var fonts = new List<PrivateFontPath>();

                if (dInfo.Exists)
                {
                    var fInfos = dInfo.GetFiles();
                    for (var i = 0; i < fInfos.Length; i++)
                    {
                        var f = fInfos[i];
                        if (f.Extension.EndsWith("ttf") || f.Extension.EndsWith("otf") ||
                            f.Extension.EndsWith("fon") || f.Extension.EndsWith("fnt"))
                        {
                            fontCollection.AddFontFile(f.FullName);
                            fonts.Add(new PrivateFontPath(fontCollection.Families[i].Name, f.FullName));
                        }
                    }

                    if (fonts.Count > 0)
                    {
                        toPdfParams.UsePSCoversion = false;
                        toPdfParams.PrivateFontPaths = fonts;
                    }
                }
            }

            return toPdfParams;
        }

PhamNguyen
 
Posts: 14
Joined: Tue Oct 24, 2023 9:03 am

Tue Dec 19, 2023 10:06 am

Hello,

Thanks for your inquiry.
Based on the information you provided, I conducted preliminary tests and reproduced the issue you mentioned. I need some time to do more investigation to check if there are solution to solve your issue. Once there are any updates, I'll inform you in time.

Sincerely,
Annika
E-iceblue support team
User avatar

Annika.Zhou
 
Posts: 1657
Joined: Wed Apr 07, 2021 2:50 am

Wed Dec 20, 2023 6:16 am

Hello,

Thank you for your patience.
After conducting a thorough investigation, we regret to inform you that we currently do not have a solution for the issue at hand. I have logged the issue into our bug tracking system with the ticket number SPIREDOC-10134. Our development team will investigate and fix it. Once it is resolved, I will inform you in time. Sorry for the inconvenience caused.

Sincerely,
Annika
E-iceblue support team
User avatar

Annika.Zhou
 
Posts: 1657
Joined: Wed Apr 07, 2021 2:50 am

Wed Dec 20, 2023 9:34 am

Thanks for your support. This bug makes a function in my app inoperable, so please notify me when this bug is fixed. I look forward to your future updates :D

PhamNguyen
 
Posts: 14
Joined: Tue Oct 24, 2023 9:03 am

Wed Dec 20, 2023 9:41 am

Hello,

Thank you for your continued support.
We understand that this error is causing a particular function in your application to be inoperable, and we apologize for the inconvenience it has caused.
Rest assured, we are fully committed to resolving this bug as soon as possible. Our development team is actively working on finding a solution and implementing the necessary fixes. Once this issue is resolved, we will notify you immediately to ensure that you can restore the full functionality of your application.


Sincerely,
Annika
E-iceblue support team
User avatar

Annika.Zhou
 
Posts: 1657
Joined: Wed Apr 07, 2021 2:50 am

Return to Spire.Doc

cron