Hello Aspose,
I migrate from Aspose.pdf 10.4 to latest Aspose.pdf. With the new version a new effect was introduced: When rendering a PDF containing a table with cell borders and zooming the PDF in a viewer the borders are flickering (changing display width).
TableBorderFlickering.pdf (168.0 KB)
private static string TableBordersFlickering(Page page)
{
var table = new Table()
{
ColumnWidths = null,
Alignment = HorizontalAlignment.Left,
ColumnAdjustment = ColumnAdjustment.AutoFitToWindow,
DefaultColumnWidth = "100",
RepeatingColumnsCount = 0,
RepeatingRowsCount = 5,
Broken = TableBroken.None,
IsBroken = true,
DefaultCellBorder = null,
DefaultCellPadding = null,
Margin = new MarginInfo() { Left = 0, Top = 20, Right = 0, Bottom = 20 },
VerticalAlignment = VerticalAlignment.Center,
HorizontalAlignment = HorizontalAlignment.Left,
IsFirstParagraphInColumn = false,
IsInLineParagraph = false,
IsInNewPage = false,
IsKeptWithNext = false,
IsBordersIncluded = true
};
var titleRow = new Row();
var groupHeaderRow = new Row();
var headerRow = new Row();
var secondHeaderRow = new Row();
var date1Row = new Row();
var date2Row = new Row();
var date3Row = new Row();
table.Rows.Add(titleRow);
table.Rows.Add(groupHeaderRow);
table.Rows.Add(headerRow);
table.Rows.Add(secondHeaderRow);
table.Rows.Add(date1Row);
table.Rows.Add(date2Row);
table.Rows.Add(date3Row);
var defaultHeaderCellMargins = new MarginInfo() { Left = 7, Top = 10, Right = 7, Bottom = 10 };
var secondHeaderCellMargins = new MarginInfo() { Left = 7, Top = 8, Right = 7, Bottom = 8 };
var dataRowCellMargins = new MarginInfo() { Left = 7, Top = 10, Right = 7, Bottom = 10 };
var defaultHeaderTextFormat = new TextState("Arial", false, false) { HorizontalAlignment = HorizontalAlignment.Left, FontSize = 10, LineSpacing = 1 };
var secondHeaderTextFormat = new TextState("Arial", false, false) { HorizontalAlignment = HorizontalAlignment.Right, FontSize = 7, LineSpacing = 1 };
var dataRowTextFormat = new TextState("Arial", false, false) { HorizontalAlignment = HorizontalAlignment.Left, FontSize = 9, LineSpacing = 1 };
var dataRowNumericsFormat = new TextState("Arial", true, false) { HorizontalAlignment = HorizontalAlignment.Left, FontSize = 9, LineSpacing = 1 };
var titleCell = new Cell()
{
Alignment = HorizontalAlignment.Left,
VerticalAlignment = VerticalAlignment.Center,
IsNoBorder = false,
IsOverrideByFragment = false,
IsWordWrapped = true,
ColSpan = 5,
RowSpan = 1,
Margin = defaultHeaderCellMargins,
DefaultCellTextState = new TextState("Arial", true, false) { HorizontalAlignment = HorizontalAlignment.Left, FontSize = 10F, LineSpacing = 1 },
Paragraphs = { new TextFragment("Status on a Table") },
};
titleRow.Cells.Add(titleCell);
var headerColumnCell = new Cell()
{
Alignment = HorizontalAlignment.Left,
VerticalAlignment = VerticalAlignment.Center,
IsNoBorder = false,
IsOverrideByFragment = false,
IsWordWrapped = true,
ColSpan = 1,
RowSpan = 2,
Margin = defaultHeaderCellMargins,
DefaultCellTextState = defaultHeaderTextFormat,
BackgroundColor = Color.FromArgb(230, 230, 230),
Paragraphs = { new TextFragment("Header Column") },
Border = new BorderInfo(BorderSide.Right, 1F, Color.FromArgb(153, 153, 153))
};
var groupHeaderColumnCell = new Cell()
{
Alignment = HorizontalAlignment.Left,
VerticalAlignment = VerticalAlignment.Center,
IsNoBorder = false,
IsOverrideByFragment = false,
IsWordWrapped = true,
ColSpan = 3,
RowSpan = 1,
Margin = defaultHeaderCellMargins,
DefaultCellTextState = defaultHeaderTextFormat,
BackgroundColor = Color.FromArgb(230, 230, 230),
Paragraphs = { new TextFragment("Header") },
Border = new BorderInfo(BorderSide.Right | BorderSide.Bottom, 1F, Color.FromArgb(153, 153, 153))
};
var headerColumnCell2 = new Cell()
{
Alignment = HorizontalAlignment.Left,
VerticalAlignment = VerticalAlignment.Center,
IsNoBorder = false,
IsOverrideByFragment = false,
IsWordWrapped = true,
ColSpan = 1,
RowSpan = 2,
Margin = defaultHeaderCellMargins,
DefaultCellTextState = defaultHeaderTextFormat,
BackgroundColor = Color.FromArgb(230, 230, 230),
Paragraphs = { new TextFragment("") },
};
groupHeaderRow.Cells.Add(headerColumnCell);
groupHeaderRow.Cells.Add(groupHeaderColumnCell);
groupHeaderRow.Cells.Add(headerColumnCell2);
var headerCell = new Cell()
{
Alignment = HorizontalAlignment.Left,
VerticalAlignment = VerticalAlignment.Center,
IsNoBorder = false,
IsOverrideByFragment = false,
IsWordWrapped = true,
ColSpan = 1,
RowSpan = 1,
Margin = defaultHeaderCellMargins,
DefaultCellTextState = defaultHeaderTextFormat,
BackgroundColor = Color.FromArgb(230, 230, 230),
Paragraphs = { new TextFragment("") },
Border = new BorderInfo(BorderSide.Right, 1F, Color.FromArgb(153, 153, 153))
};
var headerCell2 = new Cell()
{
Alignment = HorizontalAlignment.Left,
VerticalAlignment = VerticalAlignment.Center,
IsNoBorder = false,
IsOverrideByFragment = false,
IsWordWrapped = true,
ColSpan = 1,
RowSpan = 1,
Margin = defaultHeaderCellMargins,
DefaultCellTextState = defaultHeaderTextFormat,
BackgroundColor = Color.FromArgb(230, 230, 230),
Paragraphs = { new TextFragment("[V]") },
Border = new BorderInfo(BorderSide.Right, 1F, Color.FromArgb(153, 153, 153))
};
var headerCell3 = new Cell()
{
Alignment = HorizontalAlignment.Left,
VerticalAlignment = VerticalAlignment.Center,
IsNoBorder = false,
IsOverrideByFragment = false,
IsWordWrapped = true,
ColSpan = 1,
RowSpan = 1,
Margin = defaultHeaderCellMargins,
DefaultCellTextState = defaultHeaderTextFormat,
BackgroundColor = Color.FromArgb(230, 230, 230),
Paragraphs = { new TextFragment("[mV]") },
Border = new BorderInfo(BorderSide.Right, 1F, Color.FromArgb(153, 153, 153))
};
headerRow.Cells.Add(headerCell);
headerRow.Cells.Add(headerCell2);
headerRow.Cells.Add(headerCell3);
var secondHeaderCell = new Cell()
{
Alignment = HorizontalAlignment.Left,
VerticalAlignment = VerticalAlignment.Center,
IsNoBorder = false,
IsOverrideByFragment = false,
IsWordWrapped = true,
ColSpan = 1,
RowSpan = 1,
Margin = secondHeaderCellMargins,
DefaultCellTextState = secondHeaderTextFormat,
BackgroundColor = Color.FromArgb(230, 230, 230),
Paragraphs = { new TextFragment("") },
Border = new BorderInfo(BorderSide.Bottom | BorderSide.Right, 1F, Color.FromArgb(153, 153, 153))
};
var secondHeaderCell2 = new Cell()
{
Alignment = HorizontalAlignment.Left,
VerticalAlignment = VerticalAlignment.Center,
IsNoBorder = false,
IsOverrideByFragment = false,
IsWordWrapped = true,
ColSpan = 1,
RowSpan = 1,
Margin = secondHeaderCellMargins,
DefaultCellTextState = secondHeaderTextFormat,
BackgroundColor = Color.FromArgb(230, 230, 230),
Paragraphs = { new TextFragment("") },
Border = new BorderInfo(BorderSide.Bottom | BorderSide.Right, 1F, Color.FromArgb(153, 153, 153))
};
var secondHeaderCell3 = new Cell()
{
Alignment = HorizontalAlignment.Right,
VerticalAlignment = VerticalAlignment.Center,
IsNoBorder = false,
IsOverrideByFragment = false,
IsWordWrapped = true,
ColSpan = 1,
RowSpan = 1,
Margin = secondHeaderCellMargins,
DefaultCellTextState = secondHeaderTextFormat,
BackgroundColor = Color.FromArgb(230, 230, 230),
Paragraphs = { new TextFragment("Tolerance: 5\u202f…\u202f6") },
Border = new BorderInfo(BorderSide.Bottom | BorderSide.Right, 1F, Color.FromArgb(153, 153, 153))
};
var secondHeaderCell4 = new Cell()
{
Alignment = HorizontalAlignment.Right,
VerticalAlignment = VerticalAlignment.Center,
IsNoBorder = false,
IsOverrideByFragment = false,
IsWordWrapped = true,
ColSpan = 1,
RowSpan = 1,
Margin = secondHeaderCellMargins,
DefaultCellTextState = secondHeaderTextFormat,
BackgroundColor = Color.FromArgb(230, 230, 230),
Paragraphs = { new TextFragment("Tolerance: \u2264\u202f6.03") },
Border = new BorderInfo(BorderSide.Bottom | BorderSide.Right, 1F, Color.FromArgb(153, 153, 153))
};
var secondHeaderCell5 = new Cell()
{
Alignment = HorizontalAlignment.Left,
VerticalAlignment = VerticalAlignment.Center,
IsNoBorder = false,
IsOverrideByFragment = false,
IsWordWrapped = true,
ColSpan = 1,
RowSpan = 1,
Margin = secondHeaderCellMargins,
DefaultCellTextState = secondHeaderTextFormat,
BackgroundColor = Color.FromArgb(230, 230, 230),
Paragraphs = { new TextFragment("") },
Border = new BorderInfo(BorderSide.Bottom, 1F, Color.FromArgb(153, 153, 153))
};
secondHeaderRow.Cells.Add(secondHeaderCell);
secondHeaderRow.Cells.Add(secondHeaderCell2);
secondHeaderRow.Cells.Add(secondHeaderCell3);
secondHeaderRow.Cells.Add(secondHeaderCell4);
secondHeaderRow.Cells.Add(secondHeaderCell5);
var dataCell11 = new Cell()
{
Alignment = HorizontalAlignment.Left,
VerticalAlignment = VerticalAlignment.Center,
IsNoBorder = false,
IsOverrideByFragment = false,
IsWordWrapped = true,
ColSpan = 1,
RowSpan = 1,
Margin = dataRowCellMargins,
DefaultCellTextState = dataRowTextFormat,
BackgroundColor = Color.FromArgb(242, 242, 242),
Paragraphs = { new TextFragment("Light Markers") },
Border = new BorderInfo(BorderSide.Bottom | BorderSide.Right, 1F, Color.FromArgb(153, 153, 153))
};
var dataCell12 = new Cell()
{
Alignment = HorizontalAlignment.Left,
VerticalAlignment = VerticalAlignment.Center,
IsNoBorder = false,
IsOverrideByFragment = false,
IsWordWrapped = true,
ColSpan = 1,
RowSpan = 1,
Margin = dataRowCellMargins,
DefaultCellTextState = dataRowNumericsFormat,
BackgroundColor = Color.FromArgb(242, 242, 242),
Paragraphs = { new TextFragment("5.0") },
Border = new BorderInfo(BorderSide.Bottom | BorderSide.Right, 1F, Color.FromArgb(153, 153, 153))
};
var dataCell13 = new Cell()
{
Alignment = HorizontalAlignment.Left,
VerticalAlignment = VerticalAlignment.Center,
IsNoBorder = false,
IsOverrideByFragment = false,
IsWordWrapped = true,
ColSpan = 1,
RowSpan = 1,
Margin = dataRowCellMargins,
DefaultCellTextState = dataRowNumericsFormat,
BackgroundColor = Color.FromArgb(242, 242, 242),
Paragraphs = { new TextFragment("0") },
Border = new BorderInfo(BorderSide.Bottom | BorderSide.Right, 1F, Color.FromArgb(153, 153, 153))
};
var dataCell14 = new Cell()
{
Alignment = HorizontalAlignment.Left,
VerticalAlignment = VerticalAlignment.Center,
IsNoBorder = false,
IsOverrideByFragment = false,
IsWordWrapped = true,
ColSpan = 1,
RowSpan = 1,
Margin = dataRowCellMargins,
DefaultCellTextState = dataRowNumericsFormat,
BackgroundColor = Color.FromArgb(242, 242, 242),
Paragraphs = { new TextFragment("15.03") },
Border = new BorderInfo(BorderSide.Bottom | BorderSide.Right, 1F, Color.FromArgb(153, 153, 153))
};
var dataCell15 = new Cell()
{
Alignment = HorizontalAlignment.Left,
VerticalAlignment = VerticalAlignment.Center,
IsNoBorder = false,
IsOverrideByFragment = false,
IsWordWrapped = true,
ColSpan = 1,
RowSpan = 1,
Margin = dataRowCellMargins,
DefaultCellTextState = dataRowNumericsFormat,
BackgroundColor = Color.FromArgb(242, 242, 242),
Paragraphs = { new TextFragment("5.0") },
Border = new BorderInfo(BorderSide.Bottom, 1F, Color.FromArgb(153, 153, 153))
};
date1Row.Cells.Add(dataCell11);
date1Row.Cells.Add(dataCell12);
date1Row.Cells.Add(dataCell13);
date1Row.Cells.Add(dataCell14);
date1Row.Cells.Add(dataCell15);
var dataCell21 = (Cell)dataCell11.Clone();
dataCell21.DefaultCellTextState = dataCell11.DefaultCellTextState;
var dataCell22 = (Cell)dataCell12.Clone();
dataCell22.DefaultCellTextState = dataCell12.DefaultCellTextState;
var dataCell23 = (Cell)dataCell13.Clone();
dataCell23.DefaultCellTextState = dataCell13.DefaultCellTextState;
var dataCell24 = (Cell)dataCell14.Clone();
dataCell24.DefaultCellTextState = dataCell14.DefaultCellTextState;
var dataCell25 = (Cell)dataCell15.Clone();
dataCell25.DefaultCellTextState = dataCell15.DefaultCellTextState;
date2Row.Cells.Add(dataCell21);
date2Row.Cells.Add(dataCell22);
date2Row.Cells.Add(dataCell23);
date2Row.Cells.Add(dataCell24);
date2Row.Cells.Add(dataCell25);
var dataCell31 = (Cell)dataCell11.Clone();
dataCell31.DefaultCellTextState = dataCell11.DefaultCellTextState;
var dataCell32 = (Cell)dataCell12.Clone();
dataCell32.DefaultCellTextState = dataCell12.DefaultCellTextState;
var dataCell33 = (Cell)dataCell13.Clone();
dataCell33.DefaultCellTextState = dataCell12.DefaultCellTextState;
var dataCell34 = (Cell)dataCell14.Clone();
dataCell34.DefaultCellTextState = dataCell12.DefaultCellTextState;
var dataCell35 = (Cell)dataCell15.Clone();
dataCell35.DefaultCellTextState = dataCell12.DefaultCellTextState;
date3Row.Cells.Add(dataCell31);
date3Row.Cells.Add(dataCell32);
date3Row.Cells.Add(dataCell33);
date3Row.Cells.Add(dataCell34);
date3Row.Cells.Add(dataCell35);
page.Paragraphs.Add(table);
return Path.Combine(myDataDir, "TableBorderFlickering.pdf");
}
My observation is that the borders appear with different thickness when zooming the PDF. In fact these borders have all the correct thickness:
grafik.png (122.4 KB)
Sometimes the lines are disappearing or small holes appear between the border endings:
grafik.png (119.5 KB)
The line below the ‘Header’ cell is completely invisible:
grafik.png (121.2 KB)
In fact all the graphic objects appears correctly in the PDF but the order is not as optimal as it was in Aspose.pdf 10.4.
As an expample:
grafik.png (123.1 KB)
If the graphical object is moved down the line will appear:
grafik.png (122.9 KB)
I checked the flickering effect by moving other border lines down as well and the flickering was disappearing.
So I propose to order the operators for borders drawing after the operators for cell background and cell contents as it was done in the former Aspose.pdf 10.4 Generator API.
As a workaround I tried tried to move the operators after processing the paragraphs e.g. with Document. ProcessParagraphs(), but I failed.
I can identify the border line operators: e.g.
(SetRGBColorStroke): 0.6 0.6 0.6 RG
(SetLineWidth): 1 w
(MoveTo): 422 687.5 m
(LineTo): 173 687.5 l
(Stroke): S
Is it possible to find this block of operators in Page.Contests and to move?
I tried it with:
var last = doc.Pages[1].Contents.Count;
for (int i = 1; i <= last; i++)
{
if (doc.Pages[1].Contents[i] is SetRGBColorStroke
&& doc.Pages[1].Contents[i + 1] is SetLineWidth
&& doc.Pages[1].Contents[i + 2] is MoveTo
&& doc.Pages[1].Contents[i + 3] is LineTo
&& doc.Pages[1].Contents[i + 4] is Stroke)
{
doc.Pages[1].Contents.Add(doc.Pages[1].Contents[i]);
doc.Pages[1].Contents.Add(doc.Pages[1].Contents[i+1]);
doc.Pages[1].Contents.Add(doc.Pages[1].Contents[i+2]);
doc.Pages[1].Contents.Add(doc.Pages[1].Contents[i+3]);
doc.Pages[1].Contents.Add(doc.Pages[1].Contents[i+4]);
doc.Pages[1].Contents.Delete(i);
doc.Pages[1].Contents.Delete(i);
doc.Pages[1].Contents.Delete(i);
doc.Pages[1].Contents.Delete(i);
doc.Pages[1].Contents.Delete(i);
last -= 5;
}
}
But without effect after saving the PDF.
How to do this correctly?
Regards
Gerd