The code below results in a very inaccurate pdf file compared to the docx when using the latest version of the Spire.Office for WPF. It may be related to having nested tables.
- Code: Select all
using System.IO;
using Spire.Doc;
using Spire.Doc.Documents;
namespace PdfProblem
{
class Program
{
static void Main(string[] args)
{
using (Document doc = new Document())
{
doc.CreateMinialDocument();
Section section = doc.Sections[0];
Table table = section.AddTable(false);
table.ResetCells(1, 2);
table.PreferredWidth = new PreferredWidth(WidthType.Percentage, 100);
table.TableFormat.LayoutType = LayoutType.Fixed;
TableRow row = table.Rows[0];
row.Cells[0].SetCellWidth(60, CellWidthType.Percentage);
Table table1 = row.Cells[0].AddTable(false);
table1.ResetCells(1, 1);
table1.PreferredWidth = new PreferredWidth(WidthType.Percentage, 100);
table1.TableFormat.LayoutType = LayoutType.Fixed;
TableRow row1 = table1.Rows[0];
row1.Cells[0].SetCellWidth(100, CellWidthType.Percentage);
Paragraph paragraph = row1.Cells[0].AddParagraph();
paragraph.AppendText("1_2_3_4_5_6_7_8_9_0_1_2_3_4_5_6_7_8_9_0");
table1 = row.Cells[1].AddTable(false);
table1.ResetCells(1, 1);
table1.PreferredWidth = new PreferredWidth(WidthType.Percentage, 100);
table1.TableFormat.LayoutType = LayoutType.Fixed;
row1 = table1.Rows[0];
row1.Cells[0].SetCellWidth(100, CellWidthType.Percentage);
paragraph = row1.Cells[0].AddParagraph();
paragraph.AppendText("A_B_C_D_E_F_G_H_I_J_K_L_M_N_O_P_Q_R_S_T_U_V_W_X_Y_Z");
if (File.Exists(Path.Combine(Path.GetTempPath(), "PdfProblem.docx")))
File.Delete(Path.Combine(Path.GetTempPath(), "PdfProblem.docx"));
doc.SaveToFile(Path.Combine(Path.GetTempPath(), "PdfProblem.docx"), FileFormat.Docx2013);
if (File.Exists(Path.Combine(Path.GetTempPath(), "PdfProblem.pdf")))
File.Delete(Path.Combine(Path.GetTempPath(), "PdfProblem.pdf"));
ToPdfParameterList toPdf = new ToPdfParameterList() { CreateWordBookmarks = true };
doc.SaveToFile(Path.Combine(Path.GetTempPath(), "PdfProblem.pdf"), toPdf);
}
}
}
}
Thanks,
Mark