I have a 100 page PDF document that my app opens up. In my document there are various textfield that I have added to allow the user to add comments. I have tried various ways to save the text in the textboxes to allow the user to return tp editing/marking up the document, but I am without luck. How can I save the text in the PDFAnotoation TextBox as an annotated string to allow the user to pickup where they left off when editing?
Here is my original:
var textFieldMultiline21 = PDFAnnotation()
let textFieldMultilineBounds21 = CGRect(x: 27, y: 58+2, width: 339, height: 508)
textFieldMultiline21 = PDFAnnotation(bounds: textFieldMultilineBounds21, forType: PDFAnnotationSubtype(rawValue: PDFAnnotationSubtype.widget.rawValue), withProperties: nil)
textFieldMultiline21.widgetFieldType = PDFAnnotationWidgetSubtype(rawValue: PDFAnnotationWidgetSubtype.text.rawValue)
textFieldMultiline21.backgroundColor = UIColor.clear
textFieldMultiline21.font = UIFont.systemFont(ofSize: 18)
textFieldMultiline21.isMultiline = true
page.addAnnotation(textFieldMultiline21)
Here I say attempt in saving the text inside the text boxes:
document.page(at: 21)?.annotations[0].contents = "Sample text"
textFieldMultiline21.caption = "sampletext"
Somewhat of a simple answer that was hiding in plain sight
Reading Text
pdfAnnotationTextField.value(forAnnotationKey: .widgetValue)
returns a string value with attributes
Setting Text
pdfAnnotationTextField.setValue("Enter Text", forAnnotationKey: .widgetValue)
Related
I can't find a way to increase the label width of EditorGUILayout.Toggle. Here's my code, it doesn't do anything and Unity clips the text and cuts it short.
GUILayoutOption[] options = new GUILayoutOption[] {
GUILayout.Width(400.0f),
GUILayout.MinWidth(250.0f),
GUILayout.ExpandWidth(true)
};
MyBoolValue = EditorGUILayout.Toggle("My Long Description Text Here", MyBoolValue, options);
I did try wrapping the Toggle button with
EditorGUILayout.BeginHorizontal();
EditorGUILayout.EndHorizontal();
But it also didn't do anything. What can I do remove clipping from the text?
Set EditorGUIUtility.labelWidth before doing your Toggle, and then restore it to its original value so you don't mess up any subsequent controls.
float originalValue = EditorGUIUtility.labelWidth;
EditorGUIUtility.labelWidth = 400;
MyBoolValue = EditorGUILayout.Toggle("My Long Description Text Here", MyBoolValue);
EditorGUIUtility.labelWidth = originalValue;
I am trying to send Base64 data as string to another page using NavController using below code:
ConvertHTMLToPDF = () => {
let htmlGrid = document.getElementById('customContent');
const options = {background: "white", height: htmlGrid.clientHeight, width: htmlGrid.clientWidth};
html2canvas(htmlGrid, options).then((canvas) => {
let doc = new jsPDF("p", "mm", "a4");
let imgData = canvas.toDataURL("image/PNG");
//Add image Canvas to PDF
doc.addImage(imgData, 'PNG', 20, 20);
let pdfData = doc.output('datauri');
let obj = {PDFSrc: pdfData};
this.navCtrl.setRoot('SaveConsentLetterPage', obj);
});
};
This is perfectly working when the Base64 data is small in size like 3Kb or 4Kb. But, when the data is like 1.2Mb, the NavController can redirect to SaveConsentLetterPage. It crashes the application.
Why is that? Is there any limit to send data with setRoot to another page in Ionic 2/3?
Actually the problem was with below line:
let pdfData = doc.output('datauri');
This opens the data uri/pdfData in current window and as a result, preventing to go the next page.
But, below line returns only the data uri string and as a result, can easily pass the data to next page.
doc.output('datauristring');
Wow, I've really fallen down the rabbit hole. I'm trying to have text on the background of part of a UI and a text field as another part, e.g. the birthday in:
I then want to repurpose that text filed to allow text entry. So I do something like:
myTextFieldName.editable = true
myTextFieldName.backgroundColor = NSColor.textBackgroundColor()
and I get something like:
Which is all well and good, but then I note the nice thin border around the text field below it. So I think, I need a border! I add one with:
myTextFieldName.bordered = true
...and I get:
Pow! What a hideous strange thick border! It doesn't look like the default text field border at all! For the life of me, I can't figure out how to make the border of my "activated" text field match that of the default. Any ideas?
Many thanks in advance!
Need to set border and border color:
myTextFieldName.wantsLayer = true
myTextFieldName.layer?.borderColor = NSColor(red:204.0/255.0, green:204.0/255.0, blue:204.0/255.0, alpha:1.0).cgColor
myTextFieldName.layer?.borderWidth = 1.0
myTextFieldName.layer?.cornerRadius = 0.0
Set corner radius if you want rounded corner.
You can add borders to NSTextfield and customise it according how you want it.
let border = CALayer()
border.borderColor = NSColor.gray.cgColor
border.autoresizingMask = [.layerHeightSizable, .layerWidthSizable]
border.borderWidth = 1.0
myTextFieldName.wantsLayer = true
myTextFieldName.layer?.addSublayer(border)
myTextFieldName.layer?.masksToBounds = true
Setting usesSingleLineMode to true for a non-system font causes the top of the text to be clipped.
I've created 3 very simple test cases that illustrate this:
good : non-system font, with usesSingleLineMode = false. Works fine.
bad : non-system font with usesSingleLineMode = true. Does not work.
system : system font with usesSingleLineMode = true. Works fine.
Add the following to the viewDidLoad() method of a new Cocoa OSX application:
// Do any additional setup after loading the view.
let good = NSTextField(frame: NSRect(x: 0, y: 0, width: 800, height: 55))
good.usesSingleLineMode = false
good.font = NSFont(name: "HelveticaNeue-UltraLight", size: 24)
good.stringValue = "Good usesSingleLineMode false "
self.view.addSubview(good)
let bad = NSTextField(frame: NSRect(x: 0, y: 100, width: 800, height: 55))
bad.usesSingleLineMode = true
bad.font = NSFont(name: "HelveticaNeue-UltraLight", size: 24)
bad.stringValue = "Bad usesSingleLineMode true"
self.view.addSubview(bad)
let system = NSTextField(frame: NSRect(x: 0, y: 200, width: 800, height: 55))
system.usesSingleLineMode = true
system.font = NSFont.systemFontOfSize(24)
system.stringValue = "Good usesSingleLineMode true, System Font"
self.view.addSubview(system)
If I create the same bad NSTextField using Interface Builder in a storyboard, set the font in IB and check Uses Single Line Mode in IB it works fine! But, it would be impractical to build the overall view in IB, thus I want to programmatically create it.
Why is this happening? Have I missed some important setting (I've tried adjusting many NSTextField and NSTextFieldCell parameters to no avail? Is there a workaround?
According to Apple themselves, this is correct and even desired behavior:
Engineering has determined that this issue behaves as intended based
on the following information:
This behaves correctly according to the documentation for NSCell:
Cells in the single line mode use the fixed baseline layout. The text
baseline position is determined solely by the control size regardless
of content font style or size.
Source: http://www.openradar.me/13813516
What the documentation says is really correct but the important detail here is what the documentation does not say. It does say that the "text baseline position is determined solely by the control size" but it does not explain in detail how this is done. And it is a known fact, that the baseline always seems to fit correctly to the system font, yet it hardly ever fits to any other font on your system. The problem is that Apple speaks of "the fixed baseline layout", as if that would be something known and well documented, but it isn't. I haven't found any document, not even among the legacy ones, that would explain the fixed baseline layout.
I solved it the problem by setting usesSingleLineMode to false.
Quick one for any developers using appcelerator out there. I have two labels (This may even bew wrong) which are populated from an RSS feed. One label houses the title and another the description. The content for these comes from an RSS list which all works fine. THe issue I'm having is that some titles are longer than others so I cant fix label heights or it just wont work.
So with that in mind I set the titles height to be auto. The only problem is I cant reference this height from my second label to use the top: property to space it correctly.
Has anyone got any good suggestions?, Am I using the wrong type of Titanium UI method?
My current code is as follows
try
{
var current = Titanium.UI.currentWindow;
var selectedItem = current.item;
var description = selectedItem.getElementsByTagName("description");
var story = description.item(0).text;
var label = Ti.UI.createLabel({
text:selectedItem.getElementsByTagName("title").item(0).text,
left:5,
top:0,
height:"auto",
font:{fontSize:40}
});
current.add(label);
var story = Ti.UI.createLabel({
text:story,
left:5,
top:label.height,
height:"auto"
});
label.add(story);
}
catch(E)
{
alert(E)
}
minimumFontSize
the minimum size of the font when the font is sized based on the contents. Enables font scaling to fit and forces the label content to be limited to a single line
On the containing window / view, set the layout property to 'vertical' - this means the views are stacked on top of one another so your top value doesn't have to know the height of the previous component.
// Windows
var window = Ti.UI.createWindow({
layout: 'vertical',
backgroundColor: '#FFF'
});
var label = Ti.UI.createLabel({
width: 200,
height: 'auto',
text: 'some long text'
});
var label2 = Ti.UI.createLabel({
width: 200,
height: 'auto',
text: 'more long text',
top: 10 // This just adds some padding between the two labels
});
window.add(label);
window.add(label2);
window.open();