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

Free Support Forum - aspose.com

HtmlFragment at specific x-y position on the page

is it possible to add HtmlFragment at the specific x,y position?
Thanx in advance,
Slava

succeeded, using FloatingBox:
// Instantiate Document object
com.aspose.pdf.Document doc = new com.aspose.pdf.Document();
// Add a page to pages collection of PDF file
Page page = doc.getPages().add();
// Instantiate HtmlFragment with HTML contents
String html_source = “Table”;

HtmlFragment titel = new HtmlFragment(html_source);
// set MarginInfo for margin details
MarginInfo margin= new MarginInfo();
margin.setBottom(1);
margin.setTop(1);
margin.setLeft(1);
// Set margin information
titel.setMargin(margin);
HtmlLoadOptions options = new HtmlLoadOptions();
//titel.setHtmlLoadOptionsOfInstance(options);
// Add HTML Fragment to paragraphs collection of page
PageInfo page_info = new PageInfo();
page_info.setWidth(595);
page.setPageInfo(page_info);
//page.getParagraphs().add(titel);

Graph graph1 = new Graph();

page.getParagraphs().add(graph1);

com.aspose.pdf.FloatingBox box1 = new com.aspose.pdf.FloatingBox(200,300);

box1.getParagraphs().add(titel);
box1.setTop(1);
box1.setLeft(-50);

page.getParagraphs().add(box1);

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

box2.getParagraphs().add(titel);
box2.setTop(400);
box2.setLeft(-80);

page.getParagraphs().add(box2);




com.aspose.pdf.Page pdfPage = doc.getPages().get_Item(1);

com.aspose.pdf.TextFragment textFragment = new com.aspose.pdf.TextFragment(“main text test ü ö ä Ü Ö Ä ß at x,y=100,800”);
textFragment.setPosition(new com.aspose.pdf.Position(100, 800));

//ttf font
Font my_font = FontRepository.openFont(“c:/windows/fonts/times.ttf”);

//set text properties
//textFragment.getTextState().setFont(com.aspose.pdf.FontRepository.findFont(“Verdana”));

textFragment.getTextState().setFont(my_font);


textFragment.getTextState().setFontSize(14);
//textFragment.getTextState().setForegroundColor(com.aspose.pdf.Color.);
//textFragment.getTextState().setBackgroundColor(java.awt.Color.GRAY);


// create TextBuilder object
com.aspose.pdf.TextBuilder textBuilder = new com.aspose.pdf.TextBuilder(pdfPage);
// append the text fragment to the PDF page
textBuilder.appendText(textFragment);

// Save PDF file
doc.save(“c:/output.pdf”);

Hi Slava,


Thanks for using our API’s.

HtmlFragments are added in Flow layout (Top-Left to Bottom-Right) and as per your understanding, in order to add HtmlFragment or any other Paragraph object over specific position on page, you may consider using FloatingBox object which has obsolete positioning and can be placed at any position over page. Should you have any further query, please feel free to contact.