I use iTextSharp 5.5.13 to create pdf file with text AcroFields and in a second step edit the pdf filling the AcroFields with some values.
For some fields i have to set a character spacing, so i use CreateAppearance method. this is the code:
var appearance = writer.DirectContent.CreateAppearance(box.Width, box.Height);
appearance.SetFontAndSize(baseFont, obj.FontSize);
appearance.SetColorFill(new iTextSharp.text.BaseColor(obj.Color));
appearance.SetCharacterSpacing(obj.CharSpacing);
formField.DefaultAppearanceString = appearance;
formField.SetAppearance(iTextSharp.text.pdf.PdfAnnotation.APPEARANCE_NORMAL, appearance);
writer.AddAnnotation(formField);
this code produce expected pdf result with fine character spacing in editable fields.
The problem is when i edit the pdf to fill AcroFields with:
pdfStamper.FormFlattening = true;
pdfStamper.AcroFields.GenerateAppearances = true;
pdfStamper.AcroFields.SetField(fieldName, fieldValue);
the resulting flattened pdf does not mantain the appearence character spacing...
What's wrong with my code?
Thanks
For generating text field appearances iText 5.x only uses the font, font size, and color information from the DA default appearance string (and the color information only if set using the g, rg, or k instructions), cf. the AcroFields method SplitDAelements which is used to extract information from the DA string.
So the iText 5.x appearance generation is quite limited and in particular does not support character spacing.
A possible work-around is for you to explicitly create all the appearances in your own code.
Related
I'm trying to use .NET Core GTK. For WinForms, we can select the form, and then click the Font property to change the font face or size within the Form designer. If we change the top form's font, it is applied to all the child controls on the form.
I wanted to do similar thing in Glade, but I cannot find a "Font" GUI in any of the attribute tabs.
Is this possible with GTK#?
If so, can it be done within Glade?
If the answer to 2 is no, can it be done in the code?
Yes this is possible in both GTK and Glade, although some code will be required to change all the forms font.
In GTK you will be using the GtkFontChooserWidget. This should let you choose between fonts.
In Glade, when you are using the attributes tab you are able to change font size with the Scale attribute. I haven't yet figured out how to change the actual font through those attributes yet. Thankfully there is a workaround. Instead of using Attributes, use Markup. Markup works just fine for both font size and font style.
Markup Example
<span font='36' face='Georgia'>Markup</span>
Assuming you are using a GtkComboBoxText to list possible fonts and button for selecting, you would just need a handler that would go through each of the labels and change the font to the designated one.
def when_visible(window):
"""
This is where per-window initialization takes place.
Values to be displayed are populated into their widgets.
"""
global FONT_FACE
name = Gtk.Buildable.get_name(window) # Window currently on
if 'font_select_screen' = name:
font = BUILDER.get_object('fontEntryCombo')
FONT_FACE = font.get_active_text()
elif 'random_screen' = name:
label1_text = "<span font='36' face='{}'>Label</span>".format(FONT_FACE)
label1 = BUILDER.get_object('label1')
label1.set_markup(label1_text)
How can I find the location and the height of the last object on a PDF page? There is no footer. I'm wanting to stamp a template below the last item. Not in the footer but directly below the last line of text. The amount of text may vary so I need to calculate if there is enough room at the bottom of the page to insert my template.
Thanks for any help,
Aaron
To determine where text and (bitmap) images on a given page end, have a look at the iText in Action, 2nd edition example ShowTextMargins which parses a PDF and adds a rectangle showing the text and (bitmap) images margin.
PdfReader reader = new PdfReader(src);
PdfReaderContentParser parser = new PdfReaderContentParser(reader);
PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(RESULT));
TextMarginFinder finder;
for (int i = 1; i <= reader.getNumberOfPages(); i++) {
finder = parser.processContent(i, new TextMarginFinder());
PdfContentByte cb = stamper.getOverContent(i);
cb.rectangle(finder.getLlx(), finder.getLly(),
finder.getWidth(), finder.getHeight());
cb.stroke();
}
stamper.close();
reader.close();
Be aware, though, that this mechanism ignores vector graphics (often also used for underlining text, colored backgrounds, and decorative separating lines) because the underlying iText parser package still (as of iText version 5.4.5) ignores them.
Update: As of version 5.5.6 iText extends the parser package to also include vector graphics parsing. This allows for an extension of the original TextMarginFinder class implementing the new ExtRenderListener methods as presented in this answer resulting in an analogous class MarginFinder which does not only consider text but also other kind of content, e.g. bitmap images and vector graphics.
I created a .PDF file using Adobe Acrobat Pro. The file has several text fields. Using iTextSharp, I'm able to populate all the fields and mail out the .PDF.
One thing is bugging me - some of the next will not "fit" in the textbox. In Adobe, if I type more that the allocated height, the scroll bar kicks in - this happens when font size is NOT set to auto and multi-line is allowed.
However, when I attempt to set the following properties:
//qSize is float and set to 15;
//auto size of font is not being set here.
pdfFormFields.SetFieldProperty("notification_desc", "textsize", qSize, null);
// set multiline
pdfFormFields.SetFieldProperty("notification_desc", "setfflags", PdfFormField.FF_MULTILINE, null);
//fill the field
pdfFormFields.SetField("notification_desc", complaintinfo.OWNER_DESC);
However upon compilation and after stamping, the scroll bar does not appear in the final .PDF.
I'm not sure if this is the right thing to do. I'm thinking that perhaps I should create a table and flood it with the the text but the documentation makes little or no reference to scroll bars....
When you flatten a document, you remove all interactivity. Expecting working scroll bars on a flattened form, is similar to expecting working scroll bars on printed paper. That's why you don't get a lot of response to your question: it's kind of absurd.
When you fill out a rectangle with text, all text that doesn't fit will be omitted. That's why some people set the font size to 0. In this case, the font size will be adapted to make the text fit. I don't know if that's an option for you as you clearly state that the font size must be 15 pt.
If you can't change the font size, you shouldn't expect the AcroForm form field to adapt itself to the content. ISO-32000-1 is clear about that: the coordinates of a text field are fixed.
Your only alternative is to take control over how iText should fill the field. I made an example showing how to do this in the context of my book: MovieAds.java/MovieAds.cs. In this example, I ask the field for its coordinates:
AcroFields.FieldPosition f = form.GetFieldPositions(TEXT)[0];
This object gives you the page number f.page and a Rectangle f.position. You can use these variables in combination with ColumnText to add the content exactly the way you want to (and to check if all content has been added).
I hope you understand that:
it's only normal that there are no scroll bars on a flattened form,
the standard way of filling out fields clips content that doesn't fit,
you need to do more programming if you want a custom result.
For more info: please consult "iText in Action - Second Edition".
hi guys working on a app which main work is pdf editing.
i understand Apple doesn't provide any api for editing the pdf. but my requirements are like that.
so i thought of extracting the whole contents of the pdf file and create a new pdf after editing. now i need to know how to extract the pdf formatting (header, footer, images, highlighting.,,)
im using Tj operators to extract the pdf text. which operators should i use to extract the other informations of pdf file.
thanks in advance.
Images are painted on the page using the Do operator. Its operand is the image name in the resources dictionary. The Do operator also paints form XObjects (self contained vector graphics) and these are stored also in the resources dictionary. The Subtype key in the image/form XObject dictionary gives you the object type: "Image" for images and "Form" for form XObjects.
The other elements are plain vector graphics and text, the PDF files do not have headers, footers, paragraphs, etc as standalone objects. What you see visually as a page header, inside the PDF file is just plain text painted at the top of the page.
Highlights can be plain semi-transparent yellow rectangles (these are no different from other rectangles on the page) or highlight annotations (these are available in page's Annots array).
I am trying to change the colour theme of an old VB6 application (make it look a bit more modern!).
Can someone tell me how I could change the backcolor of every control on a form without doing it for each and every control (label, button, frame etc!).
I have about 50 forms, all containing such controls and doing this manually for each form in code would take an age!
I am also open to better suggestions and ideas on how I can skin / theme a VB6 application?
Thanks in advance
The .frm files are simply standard ANSI text files. A background color property of a control would look like this:-
BackColor = &H80000005&
(Note the above is a system color but you can specify the RGB color using by using the lower 3 bytes and leaving the high byte 0).
A control such a Label would look like this:-
Begin VB.Label Label1
Caption = "Hello:"
Height = 285
Left = 90
TabIndex = 3
Top = 480
Width = 1305
End
So that task could be done lexically by parsing the .frm files and inserting (or replacing) the BackColor attribute line.
Edit:
Useful link posted in comments by MarkJ : Form Description Properties
You can do a for each and eliminate the controls you don't want.
Dim frmThing as Form
Dim ctlThing as Control
For Each frmThing In Forms
frmThing.BackColor = vbYellow
For Each ctlThing In frmThing.Controls
If (TypeOf ctlThing Is TextBox) Or _
(TypeOf ctlThing Is CheckBox) Or _
(TypeOf ctlThing Is ComboBox) Then
ctlThing.BackColor = vbYellow
End If
Next
Next
you could do this at runtime by looping the Controls collection and setting the background of each. This would give you the flexibility of changing your theme.
You could also work through the source files, parse out the controls and enter/change the background colours that you want. This approach is probably more work, for less reward.
Just for completeness...
ssCheck does not have a BackColor property and will produce an error using the aforementioned methods
~Mike~
It's going back quite a few years now, but wasnt there a 'Transparent' background color?
Set all the labels to have a transparent background, and you only need to set the form color once.