Create FloatingBox Object & Add Table inside FloatingBox in Android Apps
This technical tip shows how developers can create a simple FloatingBox object and then add a TextFragment to its paragraphs collection inside their Android application. As a sub-class of Paragraph, a FloatingBox is a box that contains one or more paragraphs. It can be positioned by a developer but not by the page render engine. There are methods which can be used to control the position of a floating box. The positioning of FloatingBox is absolute rather than relative. A code snippet depicts the behavior of adding table inside FloatingBox is also provided this post. The First part of code snippet shows how to create a simple FloatingBox object and then add a TextFragment to its paragraphs collection. As table is a paragraph level object, so it can also be added to the FloatinBox class' paragraphs collection. The 2nd part of the code snippet depicts the behavior of adding table inside FloatingBox.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
//your code here...TextFragment in FloatingBox
// Instantiate Document object
Document doc = new Document();
// Add page to PDF document
Page page = doc.getPages().add();
// Create FloatingBox object
FloatingBox aBox = new FloatingBox(40, 60);
// Set left position for FloatingBox
aBox.setLeft(40);
// Set Top position for FloatingBox
aBox.setTop(80);
// Set the vertical alignment for FloatingBox
aBox.setVerticalAlignment(com.aspose.pdf.VerticalAlignment.Bottom);
// Set Horizontal alignment for FloatingBox
aBox.setHorizontalAlignment(com.aspose.pdf.HorizontalAlignment.Center);
// Add text fragment to paragraphs collection of FloatingBox
aBox.getParagraphs().add(new TextFragment("main text"));
// Set border for FloatingBox
aBox.setBorder(new BorderInfo(15 /*BorderSide.Box*/));
// Set background color for FloatingBox
aBox.setBackgroundColor(com.aspose.pdf.Color.getYellow());
// Add FloatingBox to paragraphs collection of page object
page.getParagraphs().add(aBox);
// Set background of PDF page
page.setBackground(com.aspose.java.awt.Color.LIGHT_GRAY);
// Save the PDF document
doc.save(Environment.getExternalStorageDirectory().getAbsolutePath()+"/FloatingBox.pdf");
//Table inside FloatingBox
// Instantiate Document object
Document doc = new Document();
// Add page to PDF document
Page page = doc.getPages().add();
// Create FloatingBox object
FloatingBox aBox = new FloatingBox(200, 100);
// Trim the contents exceeding FloatingBox dimensions
aBox.isExtraContentClip(true);
// Specify if you need to repeat the FloatingBox
aBox.isNeedRepeating(false);
// Set left position for FloatingBox
aBox.setLeft(40);
// Set top position for FloatingBox
aBox.setTop(80);
// Set the vertical alignment for FloatingBox
aBox.setVerticalAlignment(com.aspose.pdf.VerticalAlignment.Bottom);
// Set horizontal alignment for FloatingBox
X
Url: http://www.aspose.com/android/pdf-component.aspx
Language: Java | User: Sheraz Khan | Created: Mar 12, 2014 | Tags: Create simple Floating Box object Working with FloatingBox add a TextFragment into FloatingBox object, control the position of a floating box, add Table inside FloatingBox, Android PDF API add a TextFragment into FloatingBox control the position of a floating box add Table inside FloatingBox Android PDF API