Y-offset at the end of text of an added Paragraph

Hi Aspose support team,
we are creating PDF dynamically, tested Aspose and would purchase it if it is possible to get the Y offset over the page at the end of an added text or html block in order to place the next object at x,y coordinate with a custom y-gap; is it possible to determine this y-position to manage the y-gaps between the objects?
i.e. if I define a FloatingBox with (width,height) of (500,100) and place it at (50,100) is it possible to get the y-offset of HtmlFragment-end added to FloatingBox since the HtmlFragment depending on its content could be less or greater as 200?

Thanks in advance
Slava

Hi Slava,


Thanks for your inquiry. As per my understanding you are creating a PDF from scratch and want to add new text line with specific y-gap. You may consider using linespacing property for the purpose. Please check following sample code for the purpose. However if there is any difference in my understanding and your requirement then please share some more details. We will appreciate it if you please share your sample code and intended PDF document. So we will look into it and guide you accordingly.

Document doc = new
Document();

Aspose.Pdf.Text.Font font = Aspose.Pdf.Text.FontRepository.FindFont(“Arial”);

doc.PageInfo.DefaultTextState.Font = font;

Aspose.Pdf.Page page = doc.Pages.Add();

Aspose.Pdf.FloatingBox fb = new Aspose.Pdf.FloatingBox();

fb.Margin.Top = 72;

Aspose.Pdf.Text.TextFragment textFragment = new Aspose.Pdf.Text.TextFragment();

textFragment.Text = "Aspose.Pdf";

//frag.TextState.Font = font;

textFragment.TextState.FontSize = 9;

textFragment.TextState.LineSpacing = 12f;

textFragment.IsInLineParagraph = true;

fb.Paragraphs.Add(textFragment);

Aspose.Pdf.Text.TextFragment textFragment1 = new Aspose.Pdf.Text.TextFragment();

textFragment1.IsInLineParagraph = false;

textFragment1.Text = "For .NET 10.8.0";

//frag1.TextState.Font = font;

textFragment1.TextState.FontSize = 12;

textFragment1.TextState.LineSpacing = 25f;

fb.Paragraphs.Add(textFragment1);

page.Paragraphs.Add(fb);

Aspose.Pdf.Text.TextFragment textFragment2 = new Aspose.Pdf.Text.TextFragment();

textFragment2.Text = "y-offset at the end of text of an added Paragraph";

//frag.TextState.Font = font;

textFragment2.TextState.FontSize = 9;

textFragment2.TextState.LineSpacing = 12f;

textFragment2.IsInLineParagraph = true;

page.Paragraphs.Add(textFragment2);

doc.Save(myDir + "Text_LineSpacing.pdf");

Please feel free to contact us for any further assistance.

Best Regards,

Hi Tital,
thanks a lot for your prompt reply,
here is the sample code I use:
HtmlFragment titel = new HtmlFragment(a_pretty_big_html_content);
com.aspose.pdf.FloatingBox box2 = new com.aspose.pdf.FloatingBox(580,10);
box2.getParagraphs().add(titel);
box2.setTop(400);
box2.setLeft(-80);
page.getParagraphs().add(box2);

the problem is that the FloatingBox here defined with height of 10 points (actually I could make 2 or 200); but the html content is placed dynamically over the defined y-boundry of the box so I need to know the y-coordinate or current y-offset at the end of html-block in order to place the next object right beneath the html-block, i,e.:

html_content = “abc def ghi jkl mno pqr stu vwx”;
ready pdf:
-----------------------------
abc def
ghi jkl
mno pqr
stu vwx <-here I need the y-offset of this line to place the next object right beneath it with no gap or overlapping

may be there are some low level API methods to get this information?

bst rgds
Slava

Hi Slava,


Thanks for sharing additional information. I am afraid you can not get coordinates of text while creating a PDF. However for existing PDF document you can search some text and get its coordinates.

I have tried to add HTML text after your shared code, it is reflecting right after the floating box text. We will appreciate it if you please share code to show the exact issue you are facing to add next text(next object) and a sample intended PDF document. So we will look into and will either provide you some solution or log an enhancement ticket in API accordingly.

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

Page page=doc.getPages().add();

String html_content = "abc def ghi jkl mno pqr stu vwx";

HtmlFragment titel = new HtmlFragment(html_content);

com.aspose.pdf.FloatingBox box2 = new com.aspose.pdf.FloatingBox(580, 10);

box2.getParagraphs().add(titel);

box2.setTop(400);

box2.setLeft(-80);

page.getParagraphs().add(box2);

page.getParagraphs().add(new HtmlFragment("2abc def ghi jkl mno pqr stu vwx"));

doc.save("E:/Data/floatingbox_output.pdf");


We are sorry for the inconvenience caused.

Best Regards,

Hi Tilal,
my problem is that by printing an invoice constiting of many positions containing HTML-Texts I cannot procceed to that next page without knowing the current end position of a printed object :frowning:

Hi Slava,


Thanks for your feedback. As requested earlier please share your intended PDF document and your business logic, i.e. why you want to know the position of last object on the page before moving to next page. I am afraid I still do not have enough information to log a ticket for your requirement.

I am truly sorry for the inconvenience caused.

Best Regards,