We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

FloatingBox is postioned on next page

Hi Aspose,

your banckle chat asked me to redirect my problem to the forum.
I looking for a workaround of following problem, or maybe I’m doing something wrong.

I put Text into Table.Cell.
I flag some of the Texts with a paragraph relative FloatingBox at the right margin.
The FloatingBox is the successor Paragraph of the upper Table.

I observe that if the content of the cell touches the lower margin, the floating box seems to displayed on the right vertical position on the next page. You can observe this in the table of chapter 1.2.4 in the attached PDF.

I can share only my document and the floating box code which is creating all images in FloatingBoxes on the right margin.

private Paragraph GenerateStatusBoxRight(IPDFSection section, Paragraph parent, SizeF statusIconSize)
{
  <span style="color:#2b91af;">FloatingBox</span> <span style="color:navy;">statusBoxRight</span> = <span style="color:blue;">new</span> <span style="color:#2b91af;">FloatingBox</span>(<span style="color:navy;">section</span>.<span style="color:navy;">Section</span>.<span style="color:navy;">PageInfo</span>.<span style="color:navy;">Margin</span>.<span style="color:navy;">Right</span>, <span style="color:navy;">statusIconSize</span>.<span style="color:navy;">Height</span> + <span style="color:navy;">parent</span>.<span style="color:navy;">Margin</span>.<span style="color:#6f008a;">Top</span>);
  <span style="color:navy;">section</span>.<span style="color:navy;">Section</span>.<span style="color:navy;">Paragraphs</span>.<span style="color:#880000;">Add</span>(<span style="color:navy;">statusBoxRight</span>);

  <span style="color:navy;">statusBoxRight</span>.<span style="color:navy;">PositioningType</span> = <span style="color:#2b91af;">PositioningType</span>.<span style="color:#6f008a;">ParagraphRelative</span>;
  <span style="color:navy;">statusBoxRight</span>.<span style="color:navy;">BoxVerticalPositioning</span> = <span style="color:#2b91af;">BoxVerticalPositioningType</span>.<span style="color:#6f008a;">Paragraph</span>;
  <span style="color:navy;">statusBoxRight</span>.<span style="color:navy;">ReferenceParagraphID</span> = <span style="color:navy;">parent</span>.<span style="color:navy;">ID</span>;

  <span style="color:navy;">statusBoxRight</span>.<span style="color:navy;">BoxHorizontalPositioning</span> = <span style="color:#2b91af;">BoxHorizontalPositioningType</span>.<span style="color:#6f008a;">Page</span>;
  <span style="color:navy;">statusBoxRight</span>.<span style="color:navy;">BoxHorizontalAlignment</span> = <span style="color:#2b91af;">BoxHorizontalAlignmentType</span>.<span style="color:#6f008a;">Right</span>;

  <span style="color:#2b91af;">Image</span> <span style="color:navy;">image</span> = <span style="color:#2b91af;">StatusDisplay</span>.<span style="color:#880000;">StatusToImage</span>(<span style="color:navy;">myReportItemStatus</span>.<span style="color:navy;">Status</span>, <span style="color:blue;">false</span>);
  <span style="color:navy;">image</span>.<span style="color:navy;">ImageInfo</span>.<span style="color:navy;">Alignment</span> = <span style="color:#2b91af;">AlignmentType</span>.<span style="color:#6f008a;">Center</span>;
  <span style="color:navy;">image</span>.<span style="color:navy;">Margin</span>.<span style="color:navy;">Top</span> = <span style="color:navy;">parent</span>.<span style="color:navy;">Margin</span>.<span style="color:#6f008a;">Top</span>;
  <span style="color:navy;">statusBoxRight</span>.<span style="color:navy;">Paragraphs</span>.<span style="color:#880000;">Add</span>(<span style="color:navy;">image</span>);

#if ! SHOWTABLES
statusBoxRight.Border = new BorderInfo((int) BorderSide.All, new Aspose.Pdf.Generator.Color(“MediumBlue”));
#endif

  <span style="color:blue;">return</span> <span style="color:navy;">statusBoxRight</span>;
}

I’m using aspose.pdf 10.5.0.0

Hi Gerd,


Thanks for contacting support.

It appears that you are using legacy Aspose.Pdf.Generator approach for creating PDF files and in order to test the scenario, I tried using new Document Object Model (DOM) of Aspose.Pdf namespace but I am unable to observe the issue (as the code does not seem to be sufficient to reproduce the issue).

Can you please share some sample project to replicate the issue. We are sorry for this inconvenience.

[C#]

Aspose.Pdf.Document
doc = new Document();<o:p></o:p>

doc.Pages.Add();

Aspose.Pdf.FloatingBox statusBoxRight = new Aspose.Pdf.FloatingBox(400,400);

doc.Pages[1].Paragraphs.Add(statusBoxRight);

//statusBoxRight.PositioningType = PositioningType.ParagraphRelative;

//statusBoxRight.BoxVerticalPositioning = BoxVerticalPositioningType.Paragraph;

//statusBoxRight.ReferenceParagraphID = parent.ID;

//statusBoxRight.BoxHorizontalPositioning = BoxHorizontalPositioningType.Page;

statusBoxRight.HorizontalAlignment = Aspose.Pdf.HorizontalAlignment.Right;

Aspose.Pdf.Image image = new Aspose.Pdf.Image();// StatusDisplay.StatusToImage(myReportItemStatus.Status, false);

image.File = "c:/pdftest/Adobe Acrobat App.jpg";

image.HorizontalAlignment = Aspose.Pdf.HorizontalAlignment.Center;

image.Margin.Top = 100;

statusBoxRight.Paragraphs.Add(image);

#if ! SHOWTABLES

statusBoxRight.Border = new Aspose.Pdf.BorderInfo(Aspose.Pdf.BorderSide.All, Aspose.Pdf.Color.MediumBlue);

#endif

doc.Save(“c:/pdftest/FloatingBox_RenderingIssue.pdf”);

Hello,

thanks for your response.
Yes, I still use the Generator API, and I know that you do not fix problems there anymore.
I was asking for a workaround, if there is one.
Maybe this problem is known to you or also existing in the new API. I assume that the PDF rendering engine did not change.

Let me explain more detailed what I obseserved:
The problem appears when I use paragraph relative positioning, other than in your examble above.
It appears only if the related paragraph appears in a table and the cell content touches the end of the page.
In all other cases the box is positioned correctly.

I will try to reproduce, but I cannot share more original code.
When I re-open the PDF (with the new API) I cnnot find a relation between the content of FloatingBox and the related paragraph. Is there none aanymore?

Regards
Gerd



Gerd:
Yes, I still use the Generator API, and I know that you do not fix problems there anymore.
I was asking for a workaround, if there is one.
Maybe this problem is known to you or also existing in the new API. I assume that the PDF rendering engine did not change.
Hi Gerd,

Thanks for sharing the details.

The solution to problems appearing in Generator approach are fixed in latest DOM approach.

Gerd:
Let me explain more detailed what I observed:
The problem appears when I use paragraph relative positioning, other than in your example above.
It appears only if the related paragraph appears in a table and the cell content touches the end of the page.
In all other cases the box is positioned correctly.
The paragraph relative positioning is not currently supported in new DOM. However can you please update the earlier shared code, so that we are able to notice the problem using new DOM.

Gerd:
I will try to reproduce, but I cannot share more original code.
When I re-open the PDF (with the new API) I cnnot find a relation between the content of FloatingBox and the related paragraph. Is there none aanymore?
Do you mean if the PDF file is generated with Generator and you open the document using DOM approach, you need the capabilities to manipulate FloatingBox and its elements ?
Or do you mean you cannot find the relation between FloatingBox and elements/objects placed inside it. Please share some details, so we may reply accordingly.

Hello,

I could reproduce the behavior. The content of the floating box which I put in the row 32 appears on exactly the right position on the next page.
Is there any workaround?

private static void Main(string[] args)
{
Aspose.Pdf.Generator.Pdf document = new Aspose.Pdf.Generator.Pdf();
Section section = document.Sections.Add();
section.PageInfo.Margin.Left = 72;
section.PageInfo.Margin.Right = 72;
section.PageInfo.Margin.Top = 200;
section.PageInfo.Margin.Bottom = 200;
Table ta = new Table();
ta.ColumnAdjustment = ColumnAdjustmentType.AutoFitToWindow;
ta.DefaultCellBorder = new BorderInfo((int)BorderSide.All, 1, new Color(“HotPink”));

for ( int x = 1 ; x < 50;x++)
{
Row r = ta.Rows.Add();
Cell c = new Cell(r);
c.ID = Guid.NewGuid().ToString();
r
.Cells.Add(“HAllo”);
r.Cells.Add(“HAllo”);
r.Cells.Add(x.ToString());
r.Cells.Add(“HAllo”);
r.Cells.Add(“HAllo”);
foreach (Cell cell in r.Cells)
{
cell.Paragraphs[0].ID = Guid.NewGuid().ToString();
}
}
section.Paragraphs.Add(ta);
Paragraph f = GenerateStatusBoxRight(section, ta.GetCell(32, 3, true).Paragraphs[0], new SizeF(100, 100));
document.Save(args[0]);
}

private static Paragraph GenerateStatusBoxRight(Section section, Paragraph parent, SizeF statusIconSize)
{
FloatingBox statusBoxRight = new FloatingBox(section.PageInfo.Margin.Right, statusIconSize.Height);
section.Paragraphs.Add(statusBoxRight);
statusBoxRight.IsKeptWithNext = true;

statusBoxRight.PositioningType = PositioningType.ParagraphRelative;
statusBoxRight.BoxVerticalPositioning = BoxVerticalPositioningType.Paragraph;
statusBoxRight.ReferenceParagraphID = parent.ID;

statusBoxRight.BoxHorizontalPositioning = BoxHorizontalPositioningType.Page;
statusBoxRight.BoxHorizontalAlignment = BoxHorizontalAlignmentType.Right;

Image image = new Image();
image.ImageInfo.ImageStream = SmallImageMemoryStream;
image.ImageInfo.Alignment = AlignmentType.Center;
image.ImageScale = 0.5f;
image.Margin.Top = parent.Margin.Top;
statusBoxRight.Paragraphs.Add(image);

statusBoxRight.Border = new BorderInfo((int)BorderSide.All, new Aspose.Pdf.Generator.Color(“MediumBlue”));
return statusBoxRight;
}

Hello,

my goal is to place the icon on the same PDF line as the related Paragraph is located in. In my example below it is the content of cell (32|3).
My idea is to open the PDF with DOM. The I could find the cell’s content by reading any metadata and to locate the related icon. Then I could move it to the right page.
Or vice versus.
In my example I put GUIDs on the ID, but these metadata seem not to be stored in the PDF.

Do you have any good idea?

Regards
Gerd



Gerd:
Hello,

I could reproduce the behavior. The content of the floating box which I put in the row 32 appears on exactly the right position on the next page.
Is there any workaround?

private static void Main(string[] args)
{
Aspose.Pdf.Generator.Pdf document = new Aspose.Pdf.Generator.Pdf();
Section section = document.Sections.Add();
section.PageInfo.Margin.Left = 72;
section.PageInfo.Margin.Right = 72;
section.PageInfo.Margin.Top = 200;
section.PageInfo.Margin.Bottom = 200;
Table ta = new Table();
ta.ColumnAdjustment = ColumnAdjustmentType.AutoFitToWindow;
ta.DefaultCellBorder = new BorderInfo((int)BorderSide.All, 1, new Color(“HotPink”));

for ( int x = 1 ; x < 50;x++)
{
Row r = ta.Rows.Add();
Cell c = new Cell(r);
c.ID = Guid.NewGuid().ToString();
r
.Cells.Add(“HAllo”);
r.Cells.Add(“HAllo”);
r.Cells.Add(x.ToString());
r.Cells.Add(“HAllo”);
r.Cells.Add(“HAllo”);
foreach (Cell cell in r.Cells)
{
cell.Paragraphs[0].ID = Guid.NewGuid().ToString();
}
}
section.Paragraphs.Add(ta);
Paragraph f = GenerateStatusBoxRight(section, ta.GetCell(32, 3, true).Paragraphs[0], new SizeF(100, 100));
document.Save(args[0]);
}

private static Paragraph GenerateStatusBoxRight(Section section, Paragraph parent, SizeF statusIconSize)
{
FloatingBox statusBoxRight = new FloatingBox(section.PageInfo.Margin.Right, statusIconSize.Height);
section.Paragraphs.Add(statusBoxRight);
statusBoxRight.IsKeptWithNext = true;

statusBoxRight.PositioningType = PositioningType.ParagraphRelative;
statusBoxRight.BoxVerticalPositioning = BoxVerticalPositioningType.Paragraph;
statusBoxRight.ReferenceParagraphID = parent.ID;

statusBoxRight.BoxHorizontalPositioning = BoxHorizontalPositioningType.Page;
statusBoxRight.BoxHorizontalAlignment = BoxHorizontalAlignmentType.Right;

Image image = new Image();
image.ImageInfo.ImageStream = SmallImageMemoryStream;
image.ImageInfo.Alignment = AlignmentType.Center;
image.ImageScale = 0.5f;
image.Margin.Top = parent.Margin.Top;
statusBoxRight.Paragraphs.Add(image);

statusBoxRight.Border = new BorderInfo((int)BorderSide.All, new Aspose.Pdf.Generator.Color(“MediumBlue”));
return statusBoxRight;
}

Hi Gerd,


Thanks for sharing the details.

I have tested the scenario and have observed the same issue that image is appearing in subsequent page on Right margin of page. However as per my observations, its happening because once the table object is placed inside paragraphs collection of Section, then you are trying to get access of particular paragraph inside table cell and placing image inside it. I think the better approach is to add image while table cells are being created and add image as inline paragraph to Text added inside table cell. For further details, please visit Inline Text and Image paragraphs.

For your reference, I have also attached the problematic PDF document being generated over my end. We are sorry for this inconvenience.

Hi Nayyer,

Placing icons inside of the table is not my requirement and there is no difference when the icons are created. They are misslocated anytime.
Inline-images are working fine.

It would be helpful to me to know where misslocated icons are going to, because I can locate icon when using the ImageAbsorber. Then I will relocate them in PDF to the right position.

Could you please find out this?

Regards
Gerd


Hi Gerd,


Thanks for sharing the details.

I
have logged the above stated incorrect positioning of paragraphs issue in our issue tracking system as PDFNEWNET-3107. We will investigate this
issue in details and will keep you updated on the status of a correction. <o:p></o:p>

We apologize for your inconvenience.