Hi,
we would like to place a Textbox on a PDF with some size. The text inside the Textbox can be larger or have more line than actually the size allow it. With my implementation the Textbox shows the correct size with its content, but an additional page is produced with the conntent which did not had space in the original Textbox. How can I prevent of happening this.
In the attachment you can see how it creates a second page.
public class AnnotationTextBoxExample {
static String inputFile = "/home/igb/sandbox/git/micros/msc-dcpcs/testdata/annotationen/Original_Grid.pdf";
static String outputFile = "/home/igb/sandbox/git/micros/msc-dcpcs/testdata/annotationen/testAnnotationen_output.pdf";
public static final String F_TOP = "F_TOP";
public static final String F_LEFT = "F_LEFT";
public static final String F_HEIGHT = "F_HEIGHT";
public static final String F_WIDTH = "F_WIDTH";
public static final String F_CLASSNAME = "F_CLASSNAME";
public static void main(String[] args) throws UnsupportedEncodingException, DecoderException {
// open document
com.aspose.pdf.Document pdfDocument = new com.aspose.pdf.Document(inputFile);
Page pdfPage = pdfDocument.getPages().get_Item(Integer.parseInt(1));
pdfPage.getPageInfo().setMargin(new MarginInfo(0, 0, 0, 0));
TextFragment textFragment = createTextFragment(pdfPage);
pdfPage.getParagraphs().add(createFloatingBox2(textFragment));
// save updated PDF file
pdfDocument.save(outputFile);
}
private static TextFragment createTextFragment(Map<String, String> annotationen, Page pdfPage) {
String text = "Text-Anno3 (4x4) (R12;C1)\r\n-F_Type: Mono\r\n-F_Size: 12\r\n\r\n"This string should overflow vertically the box (7newlines)\r\n-newline1\r\n-newline2\r\n-newline3\r\n-newline4\r\n-newline5\r\n-newline6\r\n-newline7"
TextFragment textFragment = new TextFragment(text);
return textFragment;
}
private static FloatingBox createFloatingBox2(TextFragment textFragment) {
FloatingBox box = new FloatingBox();
box.setTop(200.0);
box.setLeft(200.0);
box.setHeight(100.0);
box.setWidth(100.0);
box.setHorizontalAlignment(HorizontalAlignment.Left);
box.setVerticalAlignment(VerticalAlignment.Top);
textFragment.setMargin(new MarginInfo(0, 0, 0, 0));
box.getParagraphs().add(textFragment);
return box;
}
testAnnotationen_output.pdf (88.0 KB)