Hello Aspose,
I’m using the latest aspose.pdf.dll version 24.4 and I found this issue:
public static void Main()
{
Document doc = new Document();
Page page = doc.Pages.Add();
//var file = HeadingFormat(page);
var file = ImageFormatMitFehlerBlaVerschwindet(page);
if (File.Exists(file)) { File.Delete(file);}
doc.Save(file);
Process.Start(file);
}
private static string ImageFormatMitFehlerBlaVerschwindet(Page page)
{
var table = new Table
{
RepeatingRowsCount = 0,
Alignment = HorizontalAlignment.Left,
ColumnAdjustment = ColumnAdjustment.AutoFitToWindow,
DefaultColumnWidth = "100",
RepeatingColumnsCount = 0,
Broken = TableBroken.None,
IsBroken = true,
DefaultCellPadding = new MarginInfo() { Left = 0, Top = 0, Right = 5, Bottom = 0 },
DefaultCellTextState = new TextState()
{
Font = FontRepository.FindFont("Arial"),
FontSize = 9,
FontStyle = FontStyles.Regular,
LineSpacing = 1,
HorizontalAlignment = HorizontalAlignment.Left
},
Margin = new MarginInfo() { Left = 0, Top = 10, Right = 0, Bottom = 10 },
DefaultCellBorder = new BorderInfo(BorderSide.All, (float)0.5)
};
var r = table.Rows.Add();
// Any image
var c1 = NewCell();
r.Cells.Add(c1);
var image = NewImage();
c1.Paragraphs.Add(image);
c1.Paragraphs.Add(new TextFragment("Bla Bla"));
var c2 = NewCell();
r.Cells.Add(c2);
image = NewImage();
c2.Paragraphs.Add(image);
c2.Paragraphs.Add(new TextFragment("Bla Bla"){IsInLineParagraph = true});
c2.Paragraphs.Add(new TextFragment("Bla Bla"));
var c3 = NewCell();
r.Cells.Add(c3);
image = NewImage();
c3.Paragraphs.Add(new TextFragment("Bla Bla"));
c3.Paragraphs.Add(image);
var c4 = NewCell();
r.Cells.Add(c4);
image = NewImage();
image.IsInLineParagraph = true;
c4.Paragraphs.Add(new TextFragment("Bla Bla"));
c4.Paragraphs.Add(image);
page.Paragraphs.Add(table);
return Path.Combine(myDataDir, "ImageFormat.pdf");
Image NewImage()
{
return new Image
{
File = Path.Combine("..\\..\\..", "DemoImage"),
Margin = new MarginInfo() { Right = 10 },
Title = new TextFragment("Demo Bild")
{
Margin = new MarginInfo() { Left = 0, Bottom = 10, Right = 10, Top = 3 },
TextState =
{
Font = FontRepository.FindFont("Arial"),
FontSize = 7,
FontStyle = FontStyles.Regular,
LineSpacing = 1,
HorizontalAlignment = HorizontalAlignment.Left
},
VerticalAlignment = VerticalAlignment.Top,
HorizontalAlignment = HorizontalAlignment.Left,
IsFirstParagraphInColumn = false,
IsInLineParagraph = false,
IsInNewPage = false,
IsKeptWithNext = false,
},
//image.Title.TextState.ForegroundColor = Color
FixWidth = 78.75,
FixHeight = 76.5,
ImageScale = 1,
IsApplyResolution = false,
VerticalAlignment = VerticalAlignment.Top,
HorizontalAlignment = HorizontalAlignment.Left,
IsFirstParagraphInColumn = false,
IsInLineParagraph = false,
IsInNewPage = false,
IsKeptWithNext = true,
};
}
Cell NewCell()
{
var c = new Cell
{
Alignment = HorizontalAlignment.Left,
VerticalAlignment = VerticalAlignment.Center,
IsNoBorder = false,
IsOverrideByFragment = false,
IsWordWrapped = true,
Margin = null,
Border = null
};
return c;
}
}
and this is whet I get in the PDF:
grafik.png (42.2 KB)
In the first two cells my text “Bla Bla” is missing completely.
The third seems to be ok.
The forth cell the image caption “Demo Bild” seems to be not aligned with the imagewhat might lead to a problem, if the text before gets longer.
Additionally I found this issue, which I cannot reproduce in a demo code. Here the image caption two or more times:
grafik.jpg (53.2 KB)
Are these already a known issue?
Is there an existing workaround or can you propose a workaround?
Regards
Gerd
PS: meanwhile I can reproduce the double Image caption. If you compile with active the pre-compiler SCENARIO1 . But the images are not displayed. Ditto in SCENARIO2. Only SCENARIO3 is working because of no images in table.
public static void Main()
{
Document doc = new Document();
Page page = doc.Pages.Add();
//var file = HeadingFormat(page);
//var file = ImageFormatMitFehlerBlaVerschwindet(page);
var file = SequenceHorizontalLayoutImage(page);
if (File.Exists(file)) { File.Delete(file);}
doc.Save(file);
Process.Start(file);
}
private static string SequenceHorizontalLayoutImage(Page page)
{
var sequenceTable = new Table
{
RepeatingRowsCount = 0,
Alignment = HorizontalAlignment.Left,
ColumnAdjustment = ColumnAdjustment.Customized,
ColumnWidths = "20 100 330",
//DefaultColumnWidth = "100",
RepeatingColumnsCount = 0,
Broken = TableBroken.IsInNextPage,
IsBroken = true,
DefaultCellPadding = new MarginInfo() { Left = 0, Top = 0, Right = 5, Bottom = 0 },
DefaultCellTextState = new TextState()
{
Font = FontRepository.FindFont("Arial"),
FontSize = 9,
FontStyle = FontStyles.Regular,
LineSpacing = 1,
HorizontalAlignment = HorizontalAlignment.Left
},
Margin = new MarginInfo() { Left = 0, Top = 10, Right = 0, Bottom = 10 },
DefaultCellBorder = new BorderInfo(BorderSide.All, (float)0.5,Color.Aqua)
};
page.Paragraphs.Add(sequenceTable);
//sequenceTable.ColumnWidths
var sequenceRow = sequenceTable.Rows.Add();
var numberCell = sequenceRow.Cells.Add();
var hlCell = sequenceRow.Cells.Add();
var hlCell2 = sequenceRow.Cells.Add();
numberCell.Paragraphs.Add(new TextFragment("1."))
var image = NewImage();
hlCell.Paragraphs.Add(image);
var hlTable = new Table
{
RepeatingRowsCount = 0,
Alignment = HorizontalAlignment.Left,
ColumnAdjustment = ColumnAdjustment.Customized,
ColumnWidths = "100 100 100",
//DefaultColumnWidth = "100",
RepeatingColumnsCount = 0,
Broken = TableBroken.IsInNextPage,
IsBroken = false,
DefaultCellPadding = new MarginInfo() { Left = 0, Top = 0, Right = 5, Bottom = 0 },
DefaultCellTextState = new TextState()
{
Font = FontRepository.FindFont("Arial"),
FontSize = 9,
FontStyle = FontStyles.Regular,
LineSpacing = 1,
HorizontalAlignment = HorizontalAlignment.Left
},
Margin = new MarginInfo() { Left = 0, Top = 10, Right = 0, Bottom = 10 },
DefaultCellBorder = new BorderInfo(BorderSide.All, (float)0.5, Color.Red)
};
hlCell2.Paragraphs.Add(hlTable);
var hlTableRow = hlTable.Rows.Add();
//var c1 = NewCell();
//hlTableRow.Cells.Add(c1);
var c1 = hlTableRow.Cells.Add();
#if SCENARIO1 // Image caption appears twice, following cells are empty
var image1 = NewImage();
c1.Paragraphs.Add(image1);
c1.Paragraphs.Add(new TextFragment("Bla Bla"));
var c2 = NewCell();
hlTableRow.Cells.Add(c2);
var image2 = NewImage();
image2.Title = new TextFragment("Aha");
c2.Paragraphs.Add(image2);
c2.Paragraphs.Add(new TextFragment("Bla Bla") { IsInLineParagraph = true });
c2.Paragraphs.Add(new TextFragment("Bla Bla"));
#elif SCENARIO2 // Image caption appears one time, following cells are empty
//c1.Paragraphs.Add(image1);
c1.Paragraphs.Add(new TextFragment("Bla Bla"));
var c2 = NewCell();
hlTableRow.Cells.Add(c2);
var image2 = NewImage();
image2.Title = new TextFragment("Aha");
c2.Paragraphs.Add(image2);
c2.Paragraphs.Add(new TextFragment("Bla Bla") { IsInLineParagraph = true });
c2.Paragraphs.Add(new TextFragment("Bla Bla"));
#elif !SCENARIO3 // Image caption appears one time, following cells are filled
//c1.Paragraphs.Add(image1);
c1.Paragraphs.Add(new TextFragment("Bla Bla"));
var c2 = NewCell();
hlTableRow.Cells.Add(c2);
//var image2 = NewImage();
//image2.Title = new TextFragment("Aha");
//c2.Paragraphs.Add(image2);
c2.Paragraphs.Add(new TextFragment("Bla Bla") { IsInLineParagraph = true });
c2.Paragraphs.Add(new TextFragment("Bla Bla"));
#endif
return Path.Combine(myDataDir, "SequenceHorizontalLayoutImage.pdf");
var c3 = NewCell();
hlTableRow.Cells.Add(c3);
image = NewImage();
c3.Paragraphs.Add(new TextFragment("Bla Bla"));
c3.Paragraphs.Add(image);
var c4 = NewCell();
hlTableRow.Cells.Add(c4);
image = NewImage();
image.IsInLineParagraph = true;
c4.Paragraphs.Add(new TextFragment("Bla Bla"));
c4.Paragraphs.Add(image);
return Path.Combine(myDataDir, "SequenceHorizontalLayoutImage.pdf");
Image NewImage()
{
return new Image
{
File = Path.Combine("..\\..\\..", "DemoImage"),
Margin = new MarginInfo() { Right = 10 },
Title = new TextFragment("Demo Bild")
{
Margin = new MarginInfo() { Left = 0, Bottom = 10, Right = 10, Top = 3 },
TextState =
{
Font = FontRepository.FindFont("Arial"),
FontSize = 7,
FontStyle = FontStyles.Regular,
LineSpacing = 1,
HorizontalAlignment = HorizontalAlignment.Left
},
VerticalAlignment = VerticalAlignment.Top,
HorizontalAlignment = HorizontalAlignment.Left,
IsFirstParagraphInColumn = false,
IsInLineParagraph = false,
IsInNewPage = false,
IsKeptWithNext = false,
},
//image.Title.TextState.ForegroundColor = Color
FixWidth = 78.75,
FixHeight = 76.5,
ImageScale = 1,
IsApplyResolution = false,
VerticalAlignment = VerticalAlignment.Top,
HorizontalAlignment = HorizontalAlignment.Left,
IsFirstParagraphInColumn = false,
IsInLineParagraph = false,
IsInNewPage = false,
IsKeptWithNext = true,
};
}
Cell NewCell()
{
var c = new Cell
{
Alignment = HorizontalAlignment.Left,
VerticalAlignment = VerticalAlignment.Center,
IsNoBorder = false,
IsOverrideByFragment = false,
IsWordWrapped = true,
Margin = null,
Border = null
};
return c;
}
}