iTextSharp - Checkbox wont print - itext

I am new to iTextSharp, and would appreciate some help.
I am creating some checkboxes, an example of the code is below:
var rec = new Rectangle(PageSize.A4);
var fs = new FileStream(path, FileMode.OpenOrCreate, FileAccess.Write, FileShare.None);
var doc = new Document(rec);
var writer = PdfWriter.GetInstance(doc, fs);
PdfFormField checkbox1 = PdfFormField.CreateCheckBox(writer);
checkbox1.SetWidget(new Rectangle(524, 600, 540, 616), PdfAnnotation.HIGHLIGHT_INVERT);
checkbox1.ValueAsName = ("Off");
checkbox1.AppearanceState = ("Off");
checkbox1.FieldName = ("UsersNo");
checkbox1.SetAppearance(PdfAnnotation.APPEARANCE_NORMAL, "Off", chkOff);
checkbox1.SetAppearance(PdfAnnotation.APPEARANCE_NORMAL, "On", chkOn);
writer.AddAnnotation(checkbox1);
Everything looks great and is working well, until it comes to printing the actual PDF, when I click on File and Print, the checkboxes do not show in the print preview, and also do not print.
Is there anything anyone could point me to?
Appreciate the help in advance.
Jason

There are two ways to create a check box.
There is the easy way, using the RadioCheckField class.
There is the hard way, using the PdfFormField class.
For some reason you have chosen the hard way.
You are now complaining that the visibility is set to "Show on screen, not in print" instead of "Show on screen and in print".
The former ("Show on screen, not in print") is the default visibility setting when you create a check box the hard way. It corresponds with no flags being set.
The latter ("Show on screen and in print") is the default when creating a check box the easy way. In this case, the following flag is set automatically for your convenience.
As you have chosen the hard way to create a check box, you need to add the line that add the "Print flag" to your code yourself:
checkbox1.Flags = PdfAnnotation.FLAGS_PRINT;

Related

Unity editor - How to stop field from turning blue when its edited

I am making a tool in Unity to build your project for muliple platforms when you press a button.
I started with the preferences window for the tool, and came up with an anoying thing. Whenever I change the enum value of the EnumPopup field, the field turns blue in the editor window. Is there a way to disable this?
See how in the 2nd picture the field is not blue, and in the 3rd picture the field has changed to blue? How do I prevent this from happening?
Thanks in advance!
Difficult to help without having the rest of your code.
This is Unity built-in behaviour. I tried a lot of stuff see here to disable / overwrite the built-in coloring of prefix labels but had no luck so far.
A workarround however might be to instead use an independent EditorGUI.LabelField which will not be affected by the EnumPopup together with the EditorGUIUtility.labelWidth:
var LabelRect = new Rect(
FILEMANAGEMENT_ENUMFIELD_RECT.x,
FILEMANAGEMENT_ENUMFIELD_RECT.y,
// use the current label width
EditorGUIUtility.labelWidth,
FILEMANAGEMENT_ENUMFIELD_RECT.height
);
var EnumRect = new Rect(
FILEMANAGEMENT_ENUMFIELD_RECT.x + EditorGUIUtility.labelWidth,
FILEMANAGEMENT_ENUMFIELD_RECT.y,
FILEMANAGEMENT_ENUMFIELD_RECT.width - EditorGUIUtility.labelWidth,
FILEMANAGEMENT_ENUMFIELD_RECT.height
);
EditorGUI.LabelField(LabelRect, "File relative to");
QuickBuilder.Settings.Relation = (QuickBuilder.Settings.PathRelation)EditorGUI.EnumPopup(EnumRect, QuickBuilder.Settings.Relation);
As you can see the label is not turned blue while the width keeps being flexible
Sidenotes
Instead of setting values via edito scripts directly like
QuickBuilder.Settings.Relation = you should always try and use the proper SerializedProperty. It handles things like Undo/Redo and also marks the according objects and scenes as dirty.
Is there also a special reason why you use EditorGUI instead of EditorGUILayout? In the latter you don't need to setup Rects.
EditorGUILayout.BeginHorizontal();
{
EditorGUILayout.LabelField("File relative to", GUILayout.Width(EditorGUIUtility.labelWidth));
QuickBuilder.Settings.Relation = (QuickBuilder.Settings.PathRelation)EditorGUILayout.EnumPopup(QuickBuilder.Settings.Relation);
}
EditorGUILayout.EndHorizontal();

How to show / hide a button on a sheet in libreoffice calc using macros?

I face a little problem with libreoffice calc v5.1.6.2 as I didn't managed to find how to show / hide a button on a sheet using macros.
I'm talking about buttons directly on the sheet, not the dialog ones (haven't tested on dialogs yet, maybe it will be the same problem...).
So I can enable / disable them by using something like:
MyButton.enabled = True (or False)
after I populated "MyButton" with the right object, but there is no
MyButton.visible = False
or
MyButton.isVisible = False
Despite the fact the "visible" property exists in the editor, right below the "enabled" line in design mode. So how can I acheive that dynamically?
XrayTool shows a property with the somewhat unusual name of EnableVisible.
oSheet = ThisComponent.CurrentController.ActiveSheet
oButton = oSheet.DrawPage.Forms.getByIndex(0).getByName("Push Button 1")
oButton.EnableVisible = False 'Hide the button
For this to work, Calc's Design Mode must be off. If it is on, then all buttons will be shown regardless of their visibility setting.
Note: I could not find this property in the API docs.

Expand Unity Text Window Size In Inspector

I have a custom string field in the inspector and I want to give it a large box.
Currently its this:
and I want it to be this:
I looked through https://docs.unity3d.com/ScriptReference/EditorGUILayout.html but didn't seem to find anything that increases inspector window size.
Since you didn't mention what type of Input field you are using for the custom Editor and no code at-all, I will provide the possible solution. You sort it out yourself.
Simply enable wordWrap.
Depending on what you are using:
GUI.skin.textArea.wordWrap = true;
or
EditorStyles.textField.wordWrap = true;
You can even do this with the TextArea attribute.
[TextArea(3,10)]
public string text = "blah blah blah";

Set TextArea text dynamically by script

This a follow-up question to Console output on Installation screen?
I've configured a screen that contains a Text area component ("log.display") that should display what happened during my installation. The installation runs in a script that is attached to this screen. After finishing an installation step I do something like this (displayLog is initialized before):
displayLog = displayLog + currentStep + " done. \n";
context.setVariable("log.display",displayLog);
Unfortunatelly the Text area component is not updated by this. What can (must) I do to update the Text area dynamically from my script?
EDIT:
I found:
formPanelContainer = (FormPanelContainer)context.getScreenById(<screenID>);
formPanelContainer.getFormEnvironment().reinitializeFormComponents();
this seems to work, but there is one problem with that: If the "log" displayed with this solution contains more lines than the Text area can display, it shows the vertical scrollbar but doesn't scroll to the last line automatically. Is there a way to let the Text area do that?
And another question: Is it possible to ask context for the current screen without specifying a screenID (what can change)?
thanks!
Frank
The solution for my problem seems to be: get the ConfigurationObject of the TextArea component:
FormPanelContainer formPanelContainer = (FormPanelContainer)context.getScreenById(<ScreenID>);
FormEnvironment formEnvironment = formPanelContainer.getFormEnvironment();
FormComponent logComponent = formEnvironment.getFormComponentById(<TextAreaComponentID>);
JTextArea logComponentObject = (JTextArea)logComponent.getConfigurationObject();
and each time, something has to be logged:
logComponentObject.append("Text to log" + "\n");
logComponentObject.setCaretPosition(logComponentObject.getDocument().getLength());
This works fine in my setup.

gtkmm button not maintaining size and location

I have created two gtkmm button and added to HBox object. I called pack_end, and maintained the size as 21,20. But, the sizes are not maintained. Here is the code i have written and the window that i got while running the program.
Note: MYWindow is subclass of Gtk::Window
void MYWindow::customizeTitleBar()
{
//create a vertical box
Gtk::VBox *vBox = new Gtk::VBox(FALSE,0);
//create a horizontal box
Gtk::HBox *hBox = new Gtk::HBox(TRUE,0);
hBox->set_border_width(5);
//create title bar image
Gtk::Image *titleBarImage = new Gtk::Image("src/WindowTitleBar.png");
titleBarImage->set_alignment(Gtk::ALIGN_LEFT);
// hBox->pack_start(*titleBarImage,Gtk::PACK_EXPAND_WIDGET,0);
//create cloze button for window
mButtonClose = new Gtk::Button;
(*mButtonClose).set_size_request(21,20);
Gtk::Image *mImage = new Gtk::Image("src/Maximize.jpeg");
(*mButtonClose).add(*mImage);
(*mButtonClose).set_image_position(Gtk::POS_TOP);
// connecting close window function when cliked on close button
//(*mButtonClose).signal_clicked().connect( sigc::mem_fun(this, &MYWindow::closeWindow));
hBox->pack_end(*mButtonClose,Gtk::PACK_EXPAND_WIDGET,0);
Gtk::Button * mBtton = new Gtk::Button;
mBtton->set_size_request(21,20);
Gtk::Image *img = new Gtk::Image("src/Maximize.jpeg");
mBtton->add(*img);
mBtton->set_image_position(Gtk::POS_TOP);
hBox->pack_end(*mBtton,Gtk::PACK_EXPAND_WIDGET,0);
vBox->add(*hBox);
//drawing area box
Gtk::HBox *hBoxDrawingArea = new Gtk::HBox;
Gtk::DrawingArea *mDrawingArea = new Gtk::DrawingArea;
hBoxDrawingArea->pack_start(*mDrawingArea,Gtk::PACK_EXPAND_WIDGET,0);
vBox->add(*hBoxDrawingArea);
//status bar hBox
Gtk::HBox *hBoxStatusBar = new Gtk::HBox;
vBox->add(*hBoxStatusBar);
this->add(*vBox);
this->show_all();
}
I am not yet a gtk expert (but I'm learning), here's one thing you can try, which is what I've been doing.
Make a little standalone project using glade. Glade makes it really easy to screw around with all the packing settings so you can immediately see the effects of your changes.
I think in the case of resizing the window, you'll have to save the glade file and run your program (using gtkbuilder to render the glade file) and manually resize the window to see the effect, but once you make the standalone project, you can use it for other gtk testing.
And if you're like me, you'll get swayed by the wonderfulness that is glade and build your whole system that way.
But basically, it sounds like a packing issue, because I've got buttons that don't resize all over the place.
As for not moving, I'm not sure you can do that, but again I'm not an expert. I think you should be able to pin the size of some if not all of the hbox pieces so that the button inside them will not move, but I'm not sure what happens if you don't have any hbox parts that can't be variably sized to take up the slack when you grow the window.
Again, sounds like something fun to try in glade. :-)
I think you pack to FALSE , Maybe this is the problem :
Gtk::HBox *hBox = new Gtk::HBox(TRUE,0)
I use python gtk with something like this:
box1.pack_start(box2,False)