Problem while converting RTF documents to PDF

Hello,

We developed an application that generates RTF output documents. Then, we use Aspose.Words to convert those documents to PDF. After conversion, text that was previously in a table from the RTF file is moved to the top of the page into the resulting PDF document. This is some kinda strange!On the other hand, we found a workaround for this problem. If the same document is first converted to DOC and then converted to PDF, the resulting file is correct. The problem seems specific to RTF files and does not occur for DOC or DOCX files.

Here is the code:

// Ensure the format of the file is correct
FileFormatInfo fileFormat = FileFormatUtil.DetectFileFormat(documentToConvert);
if (fileFormat.LoadFormat == LoadFormat.Rtf)
{
    // Convert the file to DOC
    // Note: Converting to DOCX does not create the right output document
    LogInformation("The document generation service has been requested to convert a RTF file to PDF.\r\nConversion requires a conversion from RTF to DOC before converting to PDF.");
    Document tmpDoc = new Document(documentToConvert);
    Stream tmpOutputStream = new MemoryStream();
    tmpDoc.Save(tmpOutputStream, SaveFormat.Doc);
    // Rewind the stream position back to zero so it is ready for next reader
    tmpOutputStream.Position = 0;
    documentToConvert = tmpOutputStream;
}
else if (fileFormat.LoadFormat == LoadFormat.Unknown)
{
    LogWarning(string.Format("The document generation service detected an invalid format file during conversion to PDF.\r\nConversion might failed."));
}
// Convert the file to PDF
Document doc = new Document(documentToConvert);
Stream outputStream = new MemoryStream();
doc.Save(outputStream, SaveFormat.Pdf);
// Rewind the stream position back to zero so it is ready for next reader
outputStream.Position = 0;

May you tell us whether this is a bug or not? In a perfect world, we would like to have the same code for all types of input files to convert to PDF.

Thanks and have a nice day!

Hi Emeline,

Thanks for your inquiry. Could you please attach your input Rtf file along with Pdf file (showing the undesired behaviour) here for testing? I will investigate the issue on my side and provide you more information.

Hi,

Here is the RTF input file that causes the problem and two
PDF output files. The first one has an inappropriate format. The postal address
was moved to the top of the page during conversion to PDF. The second PDF file
is the one generated from our code, which temporally converts the RFT file to
DOC before final conversion to PDF.

May you tell us whether this is a real problem? Is there a better way to fix this?

Thanks for your support and have a nice day!

Emeline

Hi Emeline,

Thanks for your inquiry. I have managed to reproduce the same issue at my side. I have logged this issue as WORDSNET-8580 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. As a workaround, first you need to convert your RTF to Doc and then Doc to Pdf.

We apologize for your inconvenience.

Hi,

Is this problem still in progress or is it completed?

Thanks and have a nice day.

Hi Emeline,

Thanks for your inquiry.

I have verified the status of your issue from our issue tracking system and like to share with you that your issue is under analysis phase. I am afraid, I cannot provide you any reliable estimate at the moment. Once your issue is analyzed, we will then be able to provide you an estimate.

Thank you for your patience and understanding.

Hi,

In addition to the previous problem, we notice that the date at the top of our document becomes changed after conversion to PDF. The date is basically a standard Word merge field for dates, which refers to the date of the operating system. Are you able to observe that the date changes during conversion from RTF to PDF?

Thanks for your support.

Emeline

Hi Emeline,

Thanks for your inquiry.

I have tested the scenario and have not found the shared issue. Please call the Document.UpdateFields method before saving the Pdf file. In case you are using an older version of Aspose.Words, I would suggest you please upgrade to the latest version (v13.7.0) from here and let us know how it goes on your side. Hope this helps you.

var doc = new Document(MyDir + "InputFile.rtf");
doc.UpdateFields();
doc.Save(MyDir + "out.pdf");

Hi,

We downloaded the latest version of Aspose.Words, which is 13.7.0. Unfortunately, both problems (text moved and incorrect date) are still there.

By looking closer to your attached file (out.pdf), the name and the address are moved to the top of the letter, which is incorrect and different from the input RTF file. The date is correct but the text that was previously in a table in the RTF file was moved to the top of the page into the resulting PDF document.

On our side, the date is also incorrect if our code is running on a French version of Windows. However, the date is correct while running on an English version of Windows. We hope that this information will help you fixing this bug.

Have a nice day!

Hi Emeline,

Thanks for your feedback. I have tested the scenario at French culture as shown in following code snippet and have not found any issue with date. I have attached the output Pdf file with this post for your kind reference. It would be great if you please share your input document along with output Pdf showing undesired behavior. I will investigate the issue on my side and provide you more information.

CultureInfo currentCulture = Thread.CurrentThread.CurrentCulture;
Thread.CurrentThread.CurrentCulture = new CultureInfo("fr-FR");
var doc = new Document(MyDir + "InputFile.rtf");
doc.UpdateFields();
doc.Save(MyDir + "out.pdf");
Thread.CurrentThread.CurrentCulture = currentCulture;

Regarding your issue WORDSNET-8580 (postal address is moved to the top of the page), this issue is under analysis phase. We will update you via this forum thread once this issue is resolved.

Hi,

By looking closer to your attached file (out.pdf), the French date is incorrect. It shall be “21 août 2013” instead of “août 21, 2013”. Using the English culture, the code gives “August 21, 2013”, which is correct. The problem only hapens for French conversions.

Thanks and have a nice
day!

Hi Emeline,

Thanks for your inquiry.

Please note that Aspose.Words mimics the same behavior as MS Word do. If you insert the same Date field with same field codes in MS Word document by using MS Word, you will get the same output. Your input rtf has Date field codes as follow:

{ DATE \@ "MMMM d, yyyy" }

With this field code, the output will be “août 21, 2013”. Please change the field code as { DATE \@ "d MMMM yyyy" } to get the output like “21 août 2013”.

Hope this answers your query. Please let us know if you have any more queries.

Hi,

Thanks for
your support; this fixes the problem related to the date.

On the
other hand, by using the latest version of Aspose.Words (13.7.0), a problem
still happens. During conversion to PDF, the text in the table in the input RTF
file is still moved to the top of the page into the resulting PDF document. Until this bug is fixed, we will keep our workaround,
which consist of first converting the file to DOC and then converting to PDF.
In this case, the resulting file is correct. The problem seems specific to RTF
files and does not occur for DOC or DOCX files.

Thanks and have a nice day!

Emeline

Hi Emeline,

Thanks for your feedback. Regarding your issue (the postal address is moved to the top of the page in pdf file), this issue is under analysis phase at the moment. We will update you via this forum thread once this issue is resolved.

We appreciate you patience.

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


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