Clip the text in a floating box

I would like to implement the floowing functionlaity to clip the size of the text in a floating box however the API

aBox.isExtraContentClip(true);
does not seem to exist anymore, what do I do to replace the functionality?

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);

it turns out that when we have a TextFragment in a cell inside a FloatingBox that exceeds the size of the cell our process hangs on a Doc.save(). is there a way to tell the cell to clip?

We have a FloatingBox that contains a table with a few cells, when the TextFragment we put in the cell contains more text than the cell can handle the doc.save() hangs forever. how can we tell the cell to just clip the extra contents?


mkyes:
it turns out that when we have a TextFragment in a cell inside a FloatingBox that exceeds the size of the cell our process hangs on a Doc.save(). is there a way to tell the cell to clip?
Hi Mark,

Thanks for contacting support.

I have tested the scenario using Aspose.Pdf for Java 11.0.0 where I have used following code snippet and I am unable to notice any hanging issue. Furthermore, I have also observed that text is auto wrapping when reaching right border of FloatingBox. Can you please share the code snippet which you are using, so that we can again test the scenario.

[Java]

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

// Add page to PDF document

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

// Create FloatingBox object

com.aspose.pdf.FloatingBox aBox = new com.aspose.pdf.FloatingBox(200, 100);

// Trim the contents exceeding FloatingBox dimensions

//aBox..isExtraContentClip(true);

aBox.getParagraphs().add(new com.aspose.pdf.TextFragment("A very long string to exceed FloatingBox borders and to observe hanging issues of application.. Tested with Aspose.Pdf for Java 11.0.0, which is the latest release versions in download section."));

page.getParagraphs().add(aBox);

doc.save(“c:/pdftest/FloatingBox.pdf”);

mkyes:
I would like to implement the floowing functionlaity to clip the size of the text in a floating box however the API
aBox.isExtraContentClip(true);
does not seem to exist anymore, what do I do to replace the functionality?

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);
Hi Mark,
Thanks for using our API's. Can you please share the version of API you are using and meanwhile we are 
also looking into this matter and will keep you posted with our findings. We are sorry for this inconvenience.

Here is a snippet I garnered from our code, not sure that everything is in here that should be for compilation, but I think it is a good framework of where we are seeing the problem


public class BuyerInvoicePDFCreate {
public static final int DEFAULT_TXT_CHARS = 20;
public void createInvoicePDF( Connection connection) throws IOException, SQLException{
Document doc = new Document();
doc.setFitWindow(true);
doc.setCenterWindow(true);
double zoom = 1;
com.aspose.pdf.GoToAction action = new com.aspose.pdf.GoToAction(1);
action.setDestination(new com.aspose.pdf.XYZExplicitDestination(doc, 0, 0, 0, zoom));
doc.setOpenAction(action);

Page page = doc.getPages().add();
PageInfo info = page.getPageInfo();

info.setMargin(getPageMargin());
page.setPageInfo(info);
page.getParagraphs().add(createInvoiceBox(vendorId));
// where output is a buffered output stream
doc.save(output);
}
private FloatingBox createInvoiceBox(String vendorId){
FloatingBox invoiceBox = new FloatingBox(580,10);
invoiceBox.setLeft(0);
invoiceBox.setTop(0);
invoiceBox.setVerticalAlignment(VerticalAlignment.Center);
invoiceBox.setHorizontalAlignment(HorizontalAlignment.Center);

Table table = new Table();
table.setColumnWidths(“120 338 120”);
Row row = table.getRows().add();

Cell invoiceNumber = row.getCells().add();
invoiceNumber.setMargin(getTxtMargin());
// if this is set to something greater than the default of 20 characters then the doc.save() will hang
TextFragment invoiceId = getTextFragment(invoice.getInvoiceNumber());
invoiceId.setHorizontalAlignment(HorizontalAlignment.Left);
invoiceNumber.getParagraphs().add(invoiceId);

Cell invoiceCell = row.getCells().add();
TextFragment InvoiceTag = getTextFragment(50,fieldMaster.getDisplayText(BuyerInvoice_ConfigureMainDocuments_Fields.INVOICE_NAME));
InvoiceTag.setHorizontalAlignment(HorizontalAlignment.Center);
invoiceCell.getParagraphs().add(InvoiceTag);

Cell pageNumber = row.getCells().add();
TextFragment page = getTextFragment(“Page 1”);
page.setHorizontalAlignment(HorizontalAlignment.Right);
pageNumber.getParagraphs().add(page);

invoiceBox.getParagraphs().add(table);
invoiceBox.setBorder( new BorderInfo(15));
return invoiceBox;
}
public static TextFragment getTextFragment(int size, String text){
text = “012345678901234567890123456789012345678901234567890”;
String s = text.substring(0, Math.min(text.length(),size));
return new TextFragment(s);
}

public static TextFragment getTextFragment( String text){
text = “012345678901234567890123456789012345678901234567890”;
String s = text.substring(0, Math.min(text.length(),DEFAULT_TXT_CHARS));
return new TextFragment(s);
}
private MarginInfo getPageMargin(){
MarginInfo pageMarginInfo = new MarginInfo();
pageMarginInfo.setLeft(5);
pageMarginInfo.setRight(5);
pageMarginInfo.setTop(5);
pageMarginInfo.setBottom(5);
return pageMarginInfo;

}

private MarginInfo getTxtMargin(){
MarginInfo txtMarginInfo = new MarginInfo();
txtMarginInfo.setTop(0);
txtMarginInfo.setLeft(5);
txtMarginInfo.setRight(0);
txtMarginInfo.setBottom(0);
return txtMarginInfo;
}
}

Hi Mark,


Thanks for sharing the code snippet.

I
have tested the scenario and I am able to notice the same process hang problem. For the sake
of correction, I have logged this problem as PDFNEWJAVA-35411 in
our issue tracking system. We will further look into the details of this
problem and will keep you updated on the status of correction. Please be
patient and spare us little time. We are sorry for this inconvenience.

Hi Mark,


Thanks for your patience.

I have further discussed with product team and we removed isExtraContentClip(…) method in Aspose.Pdf for Java 10.8.0 release. We don’t need this method anymore, as FloatingBox doesn’t allow object to be out of the bound. You may consider skipping using this method.