Free Support Forum - aspose.com

Aspose.Words converting Word to PDF wraps foreground text when a large footer is present

Our customers create Microsoft Word letters with their agency's letterhead and then use that as a template with our product that will automatically fill in the agency's staff member name, address, etc.

With Aspose.Words version 9.4.0.0 and prior, our customers were able to use their Word letter templates successfully with our application providing some of the content and then using Aspose.Words to convert to PDF. Starting in 11.8.0.0 (our first experience anyway) and persisting in the latest version 13.3.0.0, the Word document's footer is no longer being interpreted in the background. Instead Aspose.Words believes it needs to avoid that background footer and wraps the foreground text to avoid the footer.

Our customers have many 100s of letters so changing their letters would be very burdensome. We would appreciate returning the functionality to the way it worked in 9.4.0.0.

I have attached the Word template and then the converted .PDF so you can see how the text is getting wrapped.

Hi Craig,


Thanks for your inquiry. I have tested the scenario by using following code snippet and have not found the shared issue. Please see the attached pdf file.

Document doc = new
Document(MyDir + “Appointment+Letter+New.doc”);<o:p></o:p>

doc.Save(MyDir + "out.pdf");


It would be great if you please shared following detail for investigation purposes. What environment are you running on?

  • OS (Windows Version or Linux Version)
  • Architecture (32 / 64 bit)
  • .NET Framework version
  • Please supply us with the code from your application that is causing the issue

As soon as you get these pieces of information to us we'll start our investigation into your issue.

Windows 2008 R2<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

64-bit

.NET 3.5 framework, 2.0 runtime

Code:

public byte[] ConvertDocxToPdf(ref Dictionary<int, byte[]> docxDictionary, string watermarkText = "")
  {
    var masterDocument = new Document();
    bool firstdoc = false;
 
    foreach (int key in docxDictionary.Keys)
    {
      Document letterdoc = ConvertDocxToDocument(docxDictionary[key]);
 
     if (!string.IsNullOrEmpty(watermarkText))
      {
        InsertWatermarkText(letterdoc, watermarkText);
      }
 
      if (firstdoc == false)
      {
        firstdoc = true;
        masterDocument = letterdoc;
      }
      else
      {
        masterDocument.AppendDocument(letterdoc, ImportFormatMode.KeepSourceFormatting);
      }
    }
 
    var finaldoc = ConvertDocumentToPdfBytes(masterDocument);
    return finaldoc;
  }

public static Document ConvertDocxToDocument(byte[] docxFile)

{

var mem = new MemoryStream(docxFile);

var doc = new Document(mem, new LoadOptions(LoadFormat.Docx, null, null));

return doc;

}

  public static byte[] ConvertDocumentToPdfBytes(Document doc)
  {
    byte[] pdfBytes;
 
    using (var pdfStream = new MemoryStream())
    {
      doc.Save(pdfStream, SaveFormat.Pdf);
      pdfBytes = pdfStream.ToArray();
    }
 
    return pdfBytes;
  }

Hi Craig,


Thanks for sharing the code. I have tested the scenario at Windows 2008 R2 and have not found the shared issue. Please make sure that you are using the latest version of Apose.Words for .NET. I have used the following code snippet to test this issue. Please find the output pdf file in attachment.


Dictionary<int,
byte[]> d = new
Dictionary<int,
byte[]>();

d.Add(1, File.ReadAllBytes(MyDir + "in.doc"));

byte[] pdf = ConvertDocxToPdf(ref d, "");

File.WriteAllBytes(MyDir + "out.pdf", pdf);


It would be great if you please create a sample Visual Studio application which demonstrate your issue and share it here for our reference. I will investigate the issue on my side and provide you more information.

In your code, you didn't convert the docx to a Document object before converting to a PDF. I am wondering if that is causing the issue. Can you please repeat with that one extra step to get your test code closer to the code we are running?

Thank you.

Hi Craig,


Thanks for your inquiry. I have used the following code snippet to test your scenario and have not found the shared issue. Could you please create a sample Visual Studio application and attach it here for our reference? I will investigate the issue on my side and provide you more information.

Moreover, please make sure that you have attached the correct document in this thread.

Dictionary<int,
byte[]> d = new
Dictionary<int,
byte[]>();<o:p></o:p>

d.Add(1, File.ReadAllBytes(MyDir + "in.doc"));

Document doc = ConvertDocxToDocument(File.ReadAllBytes(MyDir + "in.doc"));

doc.Save(MyDir + "out-1.pdf");

byte[] pdf = ConvertDocxToPdf(ref d, "");

File.WriteAllBytes(MyDir + "out-2.pdf", pdf);