Change font size in text box - apache poi word docx - apache

I found the answer that explains how to insert a new text box into docx document.
create text box in document .docx using apache poi
The problem is that I cannot change the font size inside a newly created text box.
Does anyone know how to do that?

Reference : create text box in document .docx using apache poi
The ctTxbxContent.addNewP() in my code creates a CTP object. The XWPFParagraph has a constructor XWPFParagraph(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTP prgrph, IBody part). So you can get a XWPFParagraph from the CTP object and then use the default apache-poi methods further.
...
CTTxbxContent ctTxbxContent = ctShape.addNewTextbox().addNewTxbxContent();
XWPFParagraph textboxparagraph = new XWPFParagraph(ctTxbxContent.addNewP(), (IBody)doc);
XWPFRun textboxrun = textboxparagraph.createRun();
textboxrun.setText("The TextBox text...");
textboxrun.setFontSize(24);
...

Related

Why the ordinate of SetFixedPosition() in Itext7 .NET not work well in Web Application?

I used itext7 .NET to make a demo of Console project to add text into an existing pdf. the code is below:
PdfDocument pdfTemple = new PdfDocument(new PdfReader(templateFile), new PdfWriter(templeFile));
Document documentTemple = new Document(pdfTemple, PageSize.A4);
Text text = new Text(string.Format(#"{0} / {1} ", month, year))
.SetBackgroundColor(ColorConstants.WHITE)
.SetBold()
.SetFontSize(11);
documentTemple.Add(new Paragraph(text).SetFixedPosition(1, 424, 740, 60));
text = new Text(DateTime.Now.ToString("MM/dd/yyy"))
.SetBackgroundColor(ColorConstants.WHITE)
//.SetBold()
.SetFontSize(10);
documentTemple.Add(new Paragraph(text).SetFixedPosition(1, 503, 710, 60));
documentTemple.Close();
It works well in the Console project demo. But when I use the same code in a web application (MVC, .NET4.7.2), it doesn't work. Only the text with the ordinate between 50 - 350 can display on the created pdf file.
I need to add text to the position on the pdf file with the ordinate between 40 and 740. How can I let it work in my web application (MVC, .NET4.7.2)?
Thanks.
additions:
I found that if I open the template pdf (I write text into it) with photoshop, I will get such screen:
If I write text into the white area shown in the screenshot above, the text will not show on the pdf file. but if I write text into another area, the text will show on the pdf file.

How to identify checkboxes in a flat pdf?

Team,
I have to validate a flattened pdf as part of a requirement. This pdf has checkboxes. I used Apache PDFBOX library to read the contents of this PDF. It is only reading the text but not identifying the checkboxes. Please find attached a screenshot of a similar pdf file that i am using Flat PDF with Checkbox :
Can you please provide me any approach to identify and validate these checkboxes
Code Snippet used
PDFTextStripper stripper = new PDFTextStripper() ;
PDDocument document = new PDDocument() ;
document = PDDocument.load(new File("D:\\test.pdf"));
stripper.setStartPage(1);
stripper.setEndPage(1);
stripper.setSortByPosition(true);
pdfTextContent = stripper.getText(document);
System.out.println(pdfTextContent);

vb parse word from clipboard into html

I want to copy some word text with tables, links and images and paste it into a rich textbox in my vb project. Where I want to parse it to html.
The Questenion is, how can access the copied word in the clipboard. Using
My.Computer.Clipboard.GetText()
just returns text, without the structure for links, tables or images. But there have to be a way to access it, because my rich textbox seems to know the word format. When I paste it into it, tables, images and links are also displayed in there.
You can try to specify text format in GetText's parameter as follow :
Dim htmlText As String = Clipboard.GetText(TextDataFormat.Html)

Adding a checkbox symbol using OOo API VB.NET and UNO

I've been searching for a solution for this for quite some time now but with no luck.
I have a PDF that I am generating using VB.NET, the OpenOffice API and UNO. I am generating a text document and I need to be able to insert a checkbox in code.
One possible solution is to change the font to Wingdings and just type 'o' but that solution is neither elegant nor very easy to implement given my environment (using company created code for text document creation and manipulation, have a Write command that will write to the document (strings)).
If it's possible to just add the checkbox to a string of text then that would be perfect.
Have you tried to use an image of a checkbox (one checked and the other unchecked) and then inject that into your PDF, like this:
Caveat - I have worked with iTextSharp so the following code is relevant to iTextSharp, but the concept should translate to whatever PDF generating library/framework you are using
Method #1 - Put checkbox image into table cell
Dim imgCheckBoxChecked As Image = Image.GetInstance(HttpContext.Current.Server.MapPath("checkbox_checked.gif"))
Dim imgCheckBoxUnChecked As Image = Image.GetInstance(HttpContext.Current.Server.MapPath("checkbox_unchecked.gif"))
Dim table As Table
Dim cell As Cell
cell = New Cell(New Paragraph("", font))
'' Add checked or unchecked here
cell.AddElement(imgCheckBoxChecked)
cell.AddElement(imgCheckBoxUnChecked)
table.AddCell(cell)
Method #2 - Put checkbox image into the document
'' Add checked or unchecked here
pdfDoc.Add(imgCheckBoxChecked)
pdfDoc.Add(imgCheckBoxUnChecked)
Note: You will obviously need to find or create the .gif images for checked and unchecked.

Solr: store Text Layout from extrected pdf with tika / extract request handler

i'm using solr 4 and the extract request handler to index pdf files, which works well.
The text from the pdf is stored in the index in oder to display/provide an text snipped with highlighting.
The problem is, that the layout of the stored text is lost in solrs stored fiels.
For example, if the pdf content is:
left text right text
2nd. line leftr text text at the right side
....the content of the stored field lookes like that:
left text right text
2nd. line leftr text text at the right side
On the other hand: if i extrat the pdf to text (using linux tool pdftotext) followed by indexing the textfile (instead the pdf) using the extract request hendler -> the stored field contains/includes the layout.
So the text snipped (and the content of the stored field in solr) lookes like that:
left text right text
2nd. line leftr text text at the right side
My Question: Is there a way to keept the layout also while indexing an pdf, not only an text file?
Apache Tika would extract all the text from the pdf and index the contents as a text file.
But Instead of using the ExtractHandler with Tika, you can always convert the pdf to text and get it index so that you have the text with layout and have search enabled over it.
You can also check if you can change the default handling of Apache Tika probably using PDFBox to use other converter which holds the text layout.