Hi,
When I render the Word and PDF versions of my document, the content does not line up between the two versions. New pages are added at different locations to the content. Aka the Paragraphs are not being split the same between the two versions. My content is very table heavy, so I am figuring that has something to do with it.
Below is a simplified version of my code that shows what happens. Any ideas?
Thanks.
private void AsposeTestFunction(string list, string dock, string source, string time, string type, string apple, string oranges, BorderCollection borders, DocumentBuilder builder)
{
try
{
builder.RowFormat.ClearFormatting();
builder.RowFormat.Height = ConvertUtil.InchToPoint(0.2);
builder.RowFormat.AllowAutoFit = false;
borders.LineStyle = LineStyle.Double;
borders.LineWidth = 1;
borders.Color = System.Drawing.Color.Gray;
builder.RowFormat.Alignment = RowAlignment.Left;
builder.RowFormat.BottomPadding = 0;
builder.RowFormat.TopPadding = 0;
builder.RowFormat.RightPadding = 0;
builder.RowFormat.BottomPadding = 0;
builder.RowFormat.ClearCellPadding();
// Setup column widths
PageSetup pageSetup = builder.CurrentSection.PageSetup;
int tableWidth = (int)(pageSetup.PageWidth - pageSetup.LeftMargin - pageSetup.RightMargin);
builder.CellFormat.Width = (tableWidth / 4);
builder.ParagraphFormat.NoSpaceBetweenParagraphsOfSameStyle = true;
builder.ParagraphFormat.SpaceAfter = 1;
builder.ParagraphFormat.SpaceBefore = 1;
builder.ParagraphFormat.Alignment = ParagraphAlignment.Left;
builder.StartTable();
builder.RowFormat.Alignment = RowAlignment.Center;
builder.InsertCell();
builder.Write("List: ");
builder.InsertCell();
builder.Write(list);
builder.InsertCell();
builder.ParagraphFormat.Alignment = ParagraphAlignment.Left;
builder.Write("Dock: ");
builder.InsertCell();
builder.ParagraphFormat.Alignment = ParagraphAlignment.Left;
builder.Write(dock);
builder.EndRow();
builder.InsertCell();
builder.Write("Source: ");
builder.InsertCell();
builder.Write(source);
builder.InsertCell();
builder.ParagraphFormat.Alignment = ParagraphAlignment.Left;
builder.Write("Time: ");
builder.InsertCell();
builder.ParagraphFormat.Alignment = ParagraphAlignment.Left;
builder.Write(time);
builder.EndRow();
builder.InsertCell();
builder.Write("Type: ");
builder.InsertCell();
builder.CellFormat.HorizontalMerge = CellMerge.First;
builder.Write(type);
builder.InsertCell();
builder.CellFormat.HorizontalMerge = CellMerge.Previous;
builder.Write(" ");
builder.InsertCell();
builder.CellFormat.HorizontalMerge = CellMerge.Previous;
builder.EndRow();
{
builder.InsertCell();
builder.Write("Apple: ");
builder.InsertCell();
builder.CellFormat.HorizontalMerge = CellMerge.First;
builder.Write("1");
builder.InsertCell();
builder.CellFormat.HorizontalMerge = CellMerge.Previous;
builder.Write(" ");
builder.InsertCell();
builder.CellFormat.HorizontalMerge = CellMerge.Previous;
builder.EndRow();
}
{
builder.InsertCell();
builder.Write("Oranges: ");
builder.InsertCell();
builder.CellFormat.HorizontalMerge = CellMerge.First;
builder.Write("1");
builder.InsertCell();
builder.CellFormat.HorizontalMerge = CellMerge.Previous;
builder.Write(" ");
builder.InsertCell();
builder.CellFormat.HorizontalMerge = CellMerge.Previous;
builder.EndRow();
}
if (oranges != string.Empty)
{
builder.InsertCell();
builder.Write("Oranges: ");
builder.InsertCell();
builder.CellFormat.HorizontalMerge = CellMerge.First;
builder.Write(oranges);
builder.InsertCell();
builder.CellFormat.HorizontalMerge = CellMerge.Previous;
builder.Write(" ");
builder.InsertCell();
builder.CellFormat.HorizontalMerge = CellMerge.Previous;
builder.EndRow();
}
if (apple != string.Empty)
{
builder.InsertCell();
builder.Write("Apples: ");
builder.InsertCell();
builder.CellFormat.HorizontalMerge = CellMerge.First;
builder.Write(apple);
builder.InsertCell();
builder.CellFormat.HorizontalMerge = CellMerge.Previous;
builder.Write(" ");
builder.InsertCell();
builder.CellFormat.HorizontalMerge = CellMerge.Previous;
builder.EndRow();
}
builder.InsertCell();
builder.Write("Content: ");
Cell cell = builder.InsertCell();
builder.CellFormat.HorizontalMerge = CellMerge.First;
string contentString = "The posting system is a baseball player transfer system that operates between Japan’s Nippon Professional Baseball (NPB) and the United States’ Major League Baseball (MLB). Despite the drafting of the United States – Japanese Player Contract Agreement in 1967 designed to regulate NPB players moving to MLB, problems arose in the late 1990s. Some NPB teams lost star players without compensation, an issue highlighted when NPB stars Hideo Nomo and Alfonso Soriano left to play in MLB after using loopholes to void their existing contracts. A further problem was that NPB players had very little negotiating power if their teams decided to deal them to MLB. In 1998, the Agreement was rewritten to address both problems and was dubbed the "posting system". Under this system, when an NPB player is "posted", MLB holds a four-day-long silent auction during which MLB teams can submit sealed bids in an attempt to win the exclusive rights to negotiate with the player. If the MLB team with the winning bid and the NPB player agree on contract terms before the 30-day period has expired, the NPB team receives the bid amount as a transfer fee, and the player is free to play in MLB.";
builder.InsertHtml(contentString);
if (cell.Paragraphs.Count >= 2)
{
cell.LastParagraph.Remove();
}
builder.InsertCell();
builder.CellFormat.HorizontalMerge = CellMerge.Previous;
builder.Write(" ");
builder.InsertCell();
builder.CellFormat.HorizontalMerge = CellMerge.Previous;
builder.EndRow();
builder.EndTable();
builder.RowFormat.ClearFormatting();
builder.CellFormat.ClearFormatting();
}
catch (Exception ex)
{
_Logger.Error("An unexpected error occurred while building thingy for the Word document.", ex);
throw;
}
}
{ // Test code to reproduce Word and PDF not having same content.
Document doc3 = new Document();
DocumentBuilder builder3 = new DocumentBuilder(doc3);
BorderCollection borders3 = builder3.CellFormat.Borders;
for (int i = 0; i < 100; i++)
{
AsposeTestFunction("DVD", "doc", "apples", "forever", "red", "3", "4", borders3, builder3);
builder3.Writeln("");
}
System.Diagnostics.Stopwatch timer = new System.Diagnostics.Stopwatch();
timer.Start();
doc3.UpdateFields();
doc3.UpdatePageLayout();
timer.Stop();
Console.WriteLine("Time taken: " + timer.Elapsed.TotalSeconds);
doc3.Save("test3.doc", SaveFormat.Doc);
doc3.Save("test3.pdf", SaveFormat.Pdf);
}