I am using itext and want to make my acrofields curved. Say textfield with rounded corners,
and apply the same to buttons and imageField(pustButtonField).
Is it possible in itext or by using some other api.
Thanks in advance for everybody valuable reply...
Depending on what you're actually asking, there are three possible answers to this question:
ISO-32000 only allows you to define a rectangle as the clickable area of AcroForm fields. This is the area that is highlighted when you select highlight fields. You can define a border for this rectangle consisting of an array containing at least 3 values: the horizontal corner radius, the vertical corner radius and the border width. An optional fourth value allows you to define the dash pattern.
Apart from this you can create any appearance for a widget annotation that corresponds with an AcroForm field. The appearance is stored in the /AP entry of the annotation dictionary. This is quite common for button fields (see for instance the createAppearance() method in the Calculator example). This is not done for text fields, as the appearance will disappear the moment somebody changes the value of the text field.
Maybe you are asking to create a rectangular border that is part of the content stream of the page as opposed to a shape that is defined at the AcroField level (see for instance how Open Office adds border to form fields: these borders don't disappear when you remove the field dictionary).
If I had to guess, I'd say you're looking for answer 2 regarding buttons and for answer 3 regarding text fields.
Update: thank you for accepting the answer even though I misunderstood the question. You were asking for a field where you define a path (not necessarily a straight line) that will be used to position the value of the field (for instance: a word written in a way that the characters form a circle). That's not possible with AcroForm fields.
Related
File example: file.
Problem - when extracting text using PdfTextStripper, there is token "9/1/2017" and "387986" after "ASSETS" in the page start which should be removed, and some others hidden tokens.
I have already applied this solution (so I do not copy-paste it here, because actually problem is exactly the same) and still that hidden text is appearing on page. Could it be hidden by something else except clip path?
thanks!
Could it be hidden by something else except clip path?
Yes. In case of your new document the text is written in white on white, e.g. the 387986 after ASSETS is drawn like this:
1 1 1 rg
/TT0 16 Tf
-1011.938 115.993 Td
(#A,BAC)Tj
The initial 1 1 1 rg sets the fill color to RGB WHITE. (Additionally that text is quite tiny but would still be visible if drawn in e.g. BLACK.)
The solution you refer to was implemented for documents like the sample document presented in that issue in which the invisible text is made invisible by defining clip paths (outside the bounds of which the text is) and by filling paths (hiding the text underneath). Thus, your white text won't be recognized by it as hidden.
Unfortunately recognizing invisibility of WHITE on WHITE text is more difficult to determine than that of clipped or covered text because one not only needs to know the a property of the current graphics state (like the clip path) or remove all text inside a given path, one also needs to know the color of the part of the page right before the text is drawn (to check the on WHITE detail).
If, on the other hand, you assume the page background to be essentially WHITE, it is fairly simple to ignore all white text: Simply also detect the current fill color in processTextPosition:
PDColor fillColor = gs.getNonStrokingColor();
and compare it to the flavors of WHITE you want to consider invisible. (Usually it should suffice to compare with RGB, CMYK, and Grayscale WHITE; in seldom cases you'll also have to correctly interpret more complex color spaces. Additionally you might also consider nearly WHITE colors invisible, (.99, .99, .99) RGB can hardly be distinguished from WHITE.)
If you find the current color to be WHITE, ignore the current TextPosition.
Be aware, though, just like the solution you referenced this is not yet the final solution recognizing all WHITE text: For that you'll also have to check the text rendering mode: If it is just filling (the default), the above holds, but if it is (also) stroking, you'll (also) have to consider the stroking color; if it is rendered invisible, there is no color to consider; and if the text rendering mode includes adding to path for clipping, you'll have to wait and determine what will be later drawn in this part of the page as long as the clip path holds, definitely not trivial!
Referring to Build text callout with PDF Clown - Is there a possibility to change the font color of the text within the callout note?
I haven't found a suitable method yet, can someone please give me a hint?
There is no explicit PDF Clown method to set the text color. This might be related to the fact that there is no explicit entry in the PDF annotation dictionary for it either.
There are two options, though:
There is a default appearance (DA) entry for variable text in annotations in general. As PDF Clown does not hide generic object methods, you can extend the original callout sample like this:
// Callout.
composer.showText("Callout note annotation:", new Point(35, 85));
new StaticNote(
page,
new Rectangle(250, 90, 150, 70),
"Text of the Callout note annotation"
).withLine(
new StaticNote.CalloutLine(
page,
new Point(250,125),
new Point(150,125),
new Point(100,100)
)
)
.withLineEndStyle(LineEndStyleEnum.OpenArrow)
.withBorder(new Border(1))
.withColor(DeviceRGBColor.get(Color.YELLOW))
.getBaseDataObject().put(PdfName.DA, new PdfString("1 0 1 rg /Ti 12 Tf"));
You have to use plain PDF instructions there, though, rg sets a RGB color defined by the three preceding values, and Tf sets font and size according to the preceding two values. The result of the above is:
As you see, the text now is purple (red 100%, green 0%, blue 100%). A side effect is, though, that the callout line and the frame around the callout box also are purple.
Alternatively a PDF can bring along an own appearance stream defining the whole appearance of the annotation in question. This means, though, that you really have to draw everything yourself including lines, frames, backgrounds, and text.
PDF Clown allows you to set the appearance of an annotation using the setAppearance and withAppearance methods.
I have a requirment to embed a image into PDF. The PDF size and image size are the same (I have everything working up to this point). The difficult part is the end user has some text that they need to enter above some areas of the image, these areas will be predefined, but the text that goes in those positions are not. I know its possible to create fillable fields using tools like iText.. I have searched for days on how to use iText to accomplish setting up fillable field and positioning text of any kind to an absolute position, but frustratingly have made zero progress. So I could really use someones expertise on this subject.
Thanks
Your question isn't entirely clear, and the answer is different if you make different assumptions.
Assumption 1: Suppose that you have a PDF that consists of an image that fills the complete page. You now want to add text fields at positions that you know in advance.
In this case, you'd use PdfStamper and the addAnnotation() method as is done in the answer to the StackOverflow question How can I add a new AcroForm field to a PDF?
PdfReader reader = new PdfReader(src);
PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(dest));
// create a field for which you define the coordinates using a Rectangle
stamper.addAnnotation(field, 1);
stamper.close();
Here we add field to page 1 using the addAnnotation() method.
Now for the question: how to create that field object. That's easy. See for instance the ReadOnlyField example:
Rectangle rect = new Rectangle(36, 720, 144, 806);
TextField tf = new TextField(stamper.getWriter(), rect, "text");
tf.setOptions(TextField.MULTILINE);
PdfFormField field = tf.getTextField();
Note that I use the coordinate of the lower-left corner (36, 720) and the upper-right corner (144, 806) to create a Rectangle object. I create a TextField using the stamper's PdWriter instance, that rect and I give that field the name text. Assuming that you want the text that is entered to be wrapped, I made the text field a MULTILINE field. I then obtain a PdfFormFieldinstance from the TextField object.
Assumption 2: you are creating a PDF document from scratch in which you create a page to which you add an image with the same size of the page. Now you just want to add form fields to add text. There are many examples on how to define and add a text field on the official iText web site: MultiLineField, TextFields, GenericFields, CreateFormInTable, and many more.
You'll also find a good example in the question How to add a hidden text field?. The example in the question shows how to add a visible text field; the answer shows how to hide it.
In this example, x and y are the coordinates of the lower-left corner, whereas w and h are the width and the height of the field:
TextField field = new TextField(writer, new Rectangle(x, y - h, x + w, y), name);
field.BackgroundColor = new BaseColor(bgcolor[0], bgcolor[1], bgcolor[2]);
field.BorderColor = new BaseColor(
bordercolor[0], bordercolor[1], bordercolor[2]);
field.BorderWidth = border;
field.BorderStyle = PdfBorderDictionary.STYLE_SOLID;
field.Text = text;
writer.AddAnnotation(field.GetTextField());
This is an iTextSharp example (written in C#), but it's very easy to port it to Java.
Finally: maybe you already knew all of this. Maybe you were just wondering what all these coordinates are about. The answer to this question can also be found on the official iText web site:
Where is the origin (x,y) of a PDF page?
How should I interpret the coordinates of a rectangle in PDF?
Almost all of the links in my answer refer to examples and answers that were written in answer to previous questions on StackOverflow. Please refrain from saying things like I have searched for days on how to use iText to accomplish setting up fillable field and positioning text of any kind to an absolute position because it is hard to believe for people who know that all the answers can be found on the official iText web site. Your boss might wonder which sites you were searching for all those days.
I found out there is a new component in LibGDX in nightly builds - TextArea which is part of the scene2d.ui package. It's nice to have a component like this, very easy to use, but what I'm missing is some support for a multi-colored text.
I want to highlight some keywords in a text with a different color but I don't know how to do it with current api. There is one method in BitmapFontCache class:
public void setColors (Color tint, int start, int end)
Javadoc for this method says following:
Sets the color of the specified characters. This may only be called after setText(CharSequence, float, float) and is reset every time setText is called.
But I don't know how to use it through TextArea object or if it's even possible to do it that way. Someone who tried to figure it out? Every hint will be appreciated.
Libgdx offers color markup, which must first be enabled on the BitmapFont with
font.getData().markupEnabled = true;
Text rendered with that font will look for color markup, where colors are surrounded in brackets. Each used color is pushed onto a stack.
Named colors (case sensitive): [RED]red [ORANGE]orange
Hex colors with optional alpha: [#FF0000]red [#FF000033]transparent
A set of empty brackets pops a color off the stack: [BLUE]Blue text[RED]Red text[]Blue text
A double bracket [[ represents an escaped bracket character, however it will not work as expected when followed by a closing bracket.
Named colors are defined in the class com.badlogic.gdx.graphics.Colors, and can be added with Colors.put("NAME", color);.
Hopefully this isn't super late.
I haven't tried it your way, but I bet you would have to overwrite the setText method and then set the colors for the specific points you want. start and end are indices for the pieces of text you want in that particular color.
I have implemented a MulticolorTextArea here: https://github.com/AnEmortalKid/MulticolorTextArea/tree/mta-release
Hopefully this helps out.
First I have created a pdf using itext and java and put a table and tableCell
PdfPTable table = new PdfPTable(2);
table.setWidths(new int[]{1, 2});
PdfPCell cell;
table.addCell("Address:");
cell = new PdfPCell(new Phrase(""));
cell.setFixedHeight(60);
table.addCell(cell);
I have another Program Which read this pdf File
PdfReader reader = new PdfReader("path_of_previously_created_pdf");
Now i want to get TableCell cell and want to Change cell height cell.setFixedHeight(new_Fixed_Height);
It is possible... if Yes .
How??
Thanx in advance
If your PDF contains just that simple 1x2 table, it of course would be possible to implement something that gives you the PDF with a cell hight of you choice.
But I assume it eventually is meant to contain more. Already the code you provided via your google drive included more (more table cells plus form elements), and that code, too, does look unfinished concerning the PDF construction. Thus,...
The direct answer
It is not possible.
First of all the table and cell objects you have while creating the PDF are not present as such in the resulting file, they merely are drawn as a number of lines and some text (or whatever you put into the cells).
Thus, you cannot even retrieve the cells you want to change, let alone change it.
The twisted answer
You could, of course, try and parse the page content stream to find the commands for drawing lines, find those ones among them which were drawn for the cell you are interested in, and try to derive the original cell dimension attributes from the line coordinates. Afterwards you can attempt to move everything below the cell down to create the extra space you want.
Depending on the information you have (Do you know the approximate position of the cell? If not, do you at least know some unique content of it?) reading the current cell height will include some guesswork and much coding because unfortunately the iText parser framework does not yet support parsing path operations.
Essentially you have to enhance the classes in the PDF parser package to also process and emit events for PDF path operators (if you know your way around in iText and the PDF specification that should not take more than a week or two) and create an appropriate event listener to find the lines surrounding the cell position you already know (not more than one day of work). Some iText code analysis will show how the fixed cell height and the distance of the surrounding lines relate.
Most likely, though, this is the smaller part of your work. The bigger part is actually manipulating the page content:
If you are lucky, all your page content is located in a single content stream. In that case you merely have to analyse all the page content again but this time to actually change it. The easiest way would be to enhance the classes in the parser package once again (because they already do much of the necessary math and book-keeping) to signal every command from the content stream with normalized coordinates (this might take a week or two). Based on this information signaled to you built an all new content stream in which you leave everything above your cell, move down everything below, and stretch everything crossing the line on which the bottom border of your cell lies (another week maybe).
If you are less lucky you have to fight with multiple included form xobjects crossing the line. As those xobjects may be used from other streams also, you cannot change them but have to either change a copy or include the xobject content in your newly created stream.
Then what about images crossing the line? or interesting patterns? In that case stretching the cell will utterly distort everything.
And then there are annotations, e.g. your form fields. You need to shift and stretch them, too.
Thus, while this approach is possible to follow, please be aware that (depending on how generic the solution has to become) its implementation will take someone knowing iText and PDF some months.
An alternative approach
You say in a comment
I am working on Pdf Form.I have created itext form using TextField(MULTILINE TEXT) once. After read this pdf and fill up the form but when the content increases it shows scroll Bar and content hide. My problem is Once i print the pdf it did't print hide content.
Why don't you simply for each set of data build an individual PDF with all the cells big enough for the form contents of the respective data set and copy the field values into this new PDF. This is a fairly simple approach, yet flexible enough to not waste too much space but at the same time not hide content.