PDF page is spilling over to the next page in Azure published site

Hi Aspose Support,

I am using Aspose.Words version 11.9.0.0 . I have developed the software using C# and Visual Studio 2012.

Please find below attached Word Document (FNMA-1073.docx) regarding which I have a issue. On local machine, the PDF is getting generated correctly (see attached 1073_1111_912013_17514.pdf) . However, when the site is published on Azure, the PDF contains formatting issue like a page is spilling over to the next page (see attached 1073_dfgdfh_912013_143312.pdf) . I think maybe this is a font issue. Please provide solution to this problem.

Thanks in advance.

Hi Sanjay,

Thanks for your inquiry. I would suggest you please upgrade to the latest version of Aspose.Words i.e. v11.11.0 and let us know how it goes on your side. I hope, this will help.

Hi Aspose Support,

We have deployed Aspose.Words.dll ver 11.11.0 on Azure, but still the issue persists. The PDF page is spilling over to the next page in Azure published site and the formatting is not coming correctly. The DOCX Word Document on Azure publishing site is generated correctly. Please find the attached DOCX & PDF documents generated on Azure publishing site (1073_dsgdgfd_1712013_7049.pdf,
1004_dsgdgfd_1712013_6419.pdf, 1073_dsgdgfd_1712013_7049.docx &
1004_dsgdgfd_1712013_6419.docx)

On local machine, the DOCX Word Document is rendered correctly. If I use Aspose.Words.dll ver 11.9.0, then the PDF is rendered correctly on local machine (see 1004_dsfdsfsd_1712013_134041.pdf). However when I use Aspose.Words.dll ver 11.11.0 in local machine, then the formatting of the PDF is not correct (see 1004_sgdfgfd_1712013_134332.pdf) .

Please provide solution as this is urgent.

Thanks

Hi Sanjay,

Thanks for sharing the files. We are working over your query and will update you asap.

Hi Sanjay,

Thanks for your patience. I have managed to reproduce the issue while using following code snippet. Please confirm, are you using the same scenario? It would be great if you please share your code from which you generated the PDF file.

I have attached the output PDF file with this post.

Document doc = new Document(MyDir + "1004_dsgdgfd_1712013_6419.docx");
foreach (Table tab in doc.GetChildNodes(NodeType.Table, true))
    foreach (Row r in tab.Rows)
        r.RowFormat.ClearFormatting();
doc.UpdateTableLayout();
doc.Save(MyDir + "out.pdf");

Hi Aspose Support,

Please find below method used to generate PDF. I am taking the Word Document path value from database. Please also find the attached Word Documents which are used to generate the PDF (SupportingPage_1.docx, FNMA-1004.docx, FNMA-1004-Comps.docx, FNMA-1004-1.docx, FNMA-MC.docx & SupportingPage_2.docx)

public bool CreatePDFOrAndXML(int parentTemplateId, int templateId, string selectedPageByTemplate, String[] fieldNames, Object[] fieldValues,
string fileName, string pdfPath, bool includeXML)
{
    bool result = false;

    try
    {
        TemplateRepository templateRepository = new TemplateRepository();

        List templateList = templateRepository.GetTemplateListByParentId(parentTemplateId);

        if (templateId > 0)
        {
            templateList = templateList.Where(t => t.TemplateId == templateId).ToList();
        }

        Document document = new Document();
        SectionCollection secCollection = document.Sections;

        // delete all sections in the blank document
        foreach (Section section in secCollection)
        {
            section.Remove();
        }

        if (templateList != null && templateList.Count > 0)
        {
            foreach (TemplateDTO templateDTO in templateList)
            {
                Document templateDocument = new Document(HttpContext.Current.Server.MapPath(templateDTO.FilePath));

                if (!string.IsNullOrEmpty(selectedPageByTemplate))
                {
                    DocumentBuilder docBuilder = new DocumentBuilder(templateDocument);

                    string[] selectedPageByTemplateList = selectedPageByTemplate.Split(Constants.Separator);

                    if (selectedPageByTemplateList != null && selectedPageByTemplateList.Length > 0)
                    {
                        List sectionList = new List();

                        foreach (string mergetag in selectedPageByTemplateList)
                        {
                            if (docBuilder.MoveToMergeField(mergetag, false, false))
                            {
                                sectionList.Add(docBuilder.CurrentSection);
                            }
                        }

                        SectionCollection templateSectionCollection = templateDocument.Sections;

                        foreach (Section section in templateSectionCollection)
                        {
                            if (!sectionList.Contains(section))
                            {
                                section.Remove();
                            }
                        }
                    }
                }

                document.AppendDocument(templateDocument, ImportFormatMode.KeepSourceFormatting);
            }

            // Hide Section if data is not present
            MergeTagRepository mergeTagRepository = new MergeTagRepository();
            List mergeTagMappingRuleDTOList = mergeTagRepository.GetMergeTagMappingRules().Where(m => m.IsRemoveSection == true).ToList();

            foreach (MergeTagMappingRuleDTO mergeTagMappingRuleDTO in mergeTagMappingRuleDTOList)
            {
                int index = Array.IndexOf(fieldNames, mergeTagMappingRuleDTO.MergeTag);

                if (index > 0 && string.IsNullOrEmpty(fieldValues[index].ToString().Trim()))
                {
                    DocumentBuilder builder = new DocumentBuilder(document);

                    if (builder.MoveToMergeField(mergeTagMappingRuleDTO.MergeTag, false, false))
                    {
                        Section section = builder.CurrentSection;
                        section.Remove();
                    }
                }
            }
        }

        #region Set Legal Size for all Sections in Document

        SectionCollection sectionCollection = document.Sections;

        // Set PDF to Legal size
        foreach (Section section in sectionCollection)
        {
            section.PageSetup.PaperSize = Aspose.Words.PaperSize.Legal;
        }

        #endregion Set Legal Size for all Sections in Document

        if (document.Sections.Count > 0)
        {
            NodeCollection runs = document.LastSection.GetChildNodes(NodeType.Run, true);

            // Find the runs that contain the last page break characters in this section and remove the character.
            for (int i = runs.Count - 1; i >= 0; i--)
            {
                Run run = (Run)runs[i];

                if (run.Text.IndexOf(ControlChar.PageBreakChar) >= 0)
                {
                    run.Text = run.Text.Remove(run.Text.IndexOf(ControlChar.PageBreakChar), 1);
                    break;
                }
            }

            // Setup mail merge event handler to do the custom work.
            document.MailMerge.FieldMergingCallback = new HandleMergeField();

            // Execute mail merge.
            document.MailMerge.Execute(fieldNames, fieldValues);
        }

        // Save the document.
        document.Save(pdfPath + fileName + Constants.DOCX);

        // Save the pdf. 
        document.Save(pdfPath + fileName + Constants.PDF);

        if (includeXML)
        {
            // Save the XML
            GenerateXML(pdfPath + fileName + Constants.PDF);
        }

        result = true;
    }
    catch (Exception ex)
    {
        throw ex;
    }

    return result;
}

Hi Sanjay,

Please accept my apologize for late response.

Thanks for sharing the code. Unfortunately, I am unable to execute the shared code. It would be great if you please share a sample Visual Studio application which describes the issue. We are really keen to help you but need some more details from your side. I will really appreciate your cooperation for this.

Hi Aspose Support,

As per your request, I have attached Sample Visual Studio 2012 application in zip format

Please follow the instructions mentioned in the ReadMe.txt file that I have attached.

In local environment, the PDF is rendered correctly, but in Azure published site, the PDF is not rendered correctly with certain pages spilling over to the next page.

Please provide solution asap, as this is urgent.

Thanks in advance

Hi Sanjay,

Thanks for sharing the sample Visual Studio 2012 application. I will check the scenario and will update you asap.

Hi Aspose Support,

Have you found solution to the problem ? Please give status update.

Thanks

Hi Sanjay,

Thanks for your patience.

I have tested the scenario by using the shared Visual Studio 2012 application and have found the table’s rendering issue. The tables in output PDF file are moved to the next page as shown in attached image. I have tested the shared application at Windows 7. Please check the page numbers 5, 7, and 9 of attached PDF file. Are you facing the same issue with all of your documents? Please confirm.

Hi Tahir,

We are facing PDF overflow issue for the following templates on Azure published site :

2055 - Page 5 (attached 2055_efewfwefew_2812013_12129.pdf)

1073 - Page 5, Page 7 & Page 9 (attached 1073_ewerterter_2812013_121033.pdf)

1075 - Page 5, Page 7 & Page 9 (1075_ewerterter_2812013_121141.pdf)

This issue is occuring only in Azure published site. On local machine, all the PDFs are rendered correctly.

Template Type is chosen in the UI as per the following :
Please select a URAR Template : 1004 /* you may select 1004 or 2055 or 1073 or 1075 * /
I request you to please provide me the solution to this problem asap.
Thanks in advance.

Hi Sanjay,

Thanks for your patience. I have managed to reproduce the same issue at my side by creating a simple web application in Visual Studio 2012. I have logged this issue as WORDSNET-7699 in our issue tracking system. I have linked this forum thread to the same issue and you will be notified via this forum thread once this issue is resolved. We apologize for your inconvenience.

Please feel free to ask if you have any question about Aspose.Words, we will be happy to help you.

Hi Tahir,

This issue needs to be resolved asap.

Please let us know the approximate time-frame in which this issue will be resolved… Will it take 2 to 3 days or 1 week or more than that ?

Thanks.

Hi Sanjay,

Thanks for your inquiry. Currently, this issue is pending for analysis and is in the queue. I am afraid, I can’t provide you any reliable estimate at the moment. Once your issue is analyzed, we will then be able to provide you an estimate.

We apologize for your inconvenience.

Hi Sanjay,

Thanks for your patience.

Please note that Aspose.Words requires TrueType fonts when rendering documents to fixed-page formats (e.g. PDF, XPS or SWF). Most likely the shared problem occurs when you use Aspose.Words at Operating System where Aspose.Words cannot locate fonts on your computer.

Please make sure that you have all fonts used by your template document at Windows Azure. The problem might occur because some fonts may not be installed at the Windows Azure. I think your issue will be resolved after installing fonts.

Moreover, you can use the FontSettings.SetFontsFolders to specify the location of the font files. I suggest you please read following documentation link for your kind reference.
https://docs.aspose.com/words/net/specifying-truetype-fonts-location/

Please let us know if you have any more queries.

Hi Aspose Support,

I have copied C:Windows\Fonts folder to Azure and PDF overflow issue got resolved by using the below code :

FontSettings.SetFontsFolder(pdfPath.Replace(Constants.Output, Constants.Fonts), false);

However, the Fonts folder is 377 MB in size.

How can I get a list of the fonts that are used by a Word Document. ?

If I have this list, then I need to upload only the fonts mentioned in the list.

Please reply asap…

Thanks…

Hi Sanjay,

Thanks for your inquiry. It is nice to hear from you that your problem has been solved.

Please use the Document.FontInfos property to access the collection of fonts defined in a document. Please read members of FontInfo Class from following link:
https://reference.aspose.com/words/net/aspose.words.fonts/fontinfo/

Document doc = new Document(MyDir + "in.doc");
FontInfoCollection fonts = doc.FontInfos;
int fontIndex = 1;
// The fonts info extracted from this document does not necessarily mean that the fonts themselves are
// used in the document. If a font is present but not used then most likely they were referenced at some time
// and then removed from the Document.
foreach (FontInfo info in fonts)
{
    // Print out some important details about the font.
    Console.WriteLine("Font #{0}", fontIndex);
    Console.WriteLine("Name: {0}", info.Name);
    Console.WriteLine("IsTrueType: {0}", info.IsTrueType);
    fontIndex++;
}

The issues you have found earlier (filed as WORDSNET-7699) have been fixed in this .NET update and this Java update.

This message was posted using Notification2Forum from Downloads module by aspose.notifier.