Free Support Forum - aspose.com

Trouble during pdf conversion

Dear Mudassir,
I'm using Aspose word 11.11.0 for .net.
I'm having some trouble converting a word document to a pdf due to some weird characters in table converted to pdf.

This is my save configuration:
Aspose.Words.Saving.PdfSaveOptions saveopt = new Aspose.Words.Saving.PdfSaveOptions();
saveopt.SaveFormat = Aspose.Words.SaveFormat.Pdf;
saveopt.PrettyFormat = true;
saveopt.Compliance = Aspose.Words.Saving.PdfCompliance.Pdf15;

Is there any way to solve this?

If you need some examples or other information feel free to contact me.

thanks.


This message was posted using Email2Forum by Mudassir.

Hi Andrea,


Thanks for inquiring Aspose.

I have received private message from you but I may help you with Aspose.Slides related inquiries. However, your inquiry seems related to Aspose.Words. Therefore, I have created a post in Aspose.Words forum on your behalf so that our respective team may help you better in this regard.

Many Thanks,

Hi Andrea,


Thanks for your inquiry. Could you please attach your input Word document here for testing? I will investigate the issue on my side and provide you more information.

Hi Tahir,

here are a docx file and a pdf file generated from it.

Thanks,

Andrea

Hi Andrea,


Thanks for your inquiry. Perhaps, you are using an older version of Aspose.Words; as with Aspose.Words v11.11.0, I am unable to reproduce this problem on my side. 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. I have attached the output PDF file with this post for your kind reference.

If you still face problem, please share your working environment like operating system, .NET framework etc. I will test this scenario at same platform and share my finding with you.

Hi Tahir,

we already use Aspose.Words 11.11.0...

We found the problem and we prepared a sample environment to replicate the issue.


Thanks

Andrea

Hi Andrea,


Thanks for sharing the details. Please use the ToString method with SaveFormat.Text parameter as shown below instead of GetText method.

<span lang=“EN-GB” style=“font-size:
10.0pt;line-height:115%;font-family:“Courier New”;mso-font-kerning:0pt;
mso-no-proof:yes”>((Run)nodetowrite).Text =
tab.Rows[row].Cells[cell].ToString(SaveFormat.Text);


Please replace the following line of code with above line in your code.


((Run)nodetowrite).Text = tab.Rows[row].Cells[cell].GetText();


Moreover, You may also use the
DocumentBase.ImportNode method to imports a nodes from another document to the current document. Importing a node creates a copy of the source node belonging to the importing document. The returned node has no parent. The source node is not altered or removed from the original document.

Please see the code below, hope this helps you.


//open the docx template<o:p></o:p>

Document ReportDoc = new Document(MyDir + "template.docx");

//open a sample docx containing the data (the data usually comes from another source)

Document DataDoc = new Document(MyDir + "data.docx");

//populate the table...

ReportDoc.JoinRunsWithSameFormatting();

Table table = (Table)ReportDoc.FirstSection.Body.GetChild(NodeType.Table, 0, true);

Table table2 = DataDoc.FirstSection.Body.GetChild(NodeType.Table, 0, true) as Aspose.Words.Tables.Table;

foreach (Row row in table2.Rows)

{

Node dstRow = ReportDoc.ImportNode(row, true, ImportFormatMode.KeepSourceFormatting);

table.Rows.Add(dstRow);

}

//save the output docx

ReportDoc.Save(MyDir + "output.docx");

//save the output pdf

ReportDoc.Save(MyDir + "wrong_output.pdf");


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

Hi Tahir,

using your first suggestion (GetText instead of ToString) we resolved the problem.

The second solution is not feasible for various reasons.

Thanks a lot for your help.

Andrea

Hi Andrea,


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