jsPDF.AcroForm TextField new line ignored until clicked on textField of the pdf - jspdf

Using Mr. Rio's pdf generation library as an example for demonstration at https://raw.githack.com/MrRio/jsPDF/master/#
So basically if you copy the code below and paste in the link above you will be able to see what I am talking about. I am attaching the screenshot as well for clarity.
On the sample text myTxt I've two new line so I expect bullet#2 and #3 on new line but it all gets displayed in one line until I click on the textfield and then it recognizes the newline. Is there any solution to this issue or any workarounds?
I've tried using \r\n, \n and \u000a but none of it seems to work.
var { TextField } = jsPDF.AcroForm;
doc.setFontSize(20);
var myTxt = `1. This is my first bullet \
\n2. This is my second bullet \
\n3.A third one`;
doc.text("TextField:", 10, 145);
var textField = new TextField();
textField.Rect = [50, 140, 150, 60];
textField.multiline = true;
textField.value = myTxt;
doc.addField(textField);

Related

TextSelection in a TextField issue

After selecting the whole text in a TextField using TextSelection() it does indeed select the whole text but after pressing a key on the keyboard, it starts adding pressed letters/numbers to the start of the text as opposed to deleting the old one and replacing it with the newly typed letters/numbers.
Is this expected behavior? If so, is there any way I can programatically select the text and then replace it upon pressing a key on the keyboard?
This is how I select the text:
manualEditorNode.addListener(() {
if (manualEditorNode.hasFocus) {
manualInputController.selection = TextSelection(
baseOffset: 0, extentOffset: manualInputController.text.length);
}
});
The following works for me in my program. Maybe you can try something like this?
var cursorPos = textInputController.selection;
setState(() {
textInputController.text = newInput;
if (cursorPos.start > newInput.length) {
cursorPos = new TextSelection.fromPosition(
new TextPosition(offset: newInput.length));
}
textInputController.selection = cursorPos;
});

How to remove conditional formatting in sheets using script

I'm currently using a modified script that allows me to copy an entire line from sheet#1, create a new line at the top of sheet #2, paste the copied line to that sheet, and delete the old line from sheet#1.
This is done often throughout the day by many users. The function is onEdit.
This is the script :
function onEdit(e) {
var ss = e.source;
var activatedSheetName = ss.getActiveSheet().getName();
var activatedCell = ss.getActiveSelection();
var activatedCellRow = activatedCell.getRow();
var activatedCellColumn = activatedCell.getColumn();
var activatedCellValue = activatedCell.getValue();
var URGENCE = ss.getSheetByName("List"); // source sheet
var COMPLET = ss.getSheetByName("Comp"); // target sheet
// if the value in column K is "x", move the row to target sheet
if (activatedSheetName == URGENCE.getName() && activatedCellColumn == 11 && activatedCellValue == "x")
{
COMPLET.insertRows(2,1);// insert a new row at the second row of the target sheet
var rangeToMove = URGENCE.getRange(/*startRow*/ activatedCellRow, /*startColumn*/ 1, /*numRows*/ 1, /*numColumns*/ URGENCE.getMaxColumns());
rangeToMove.moveTo(COMPLET.getRange("A2"));
URGENCE.deleteRows(activatedCellRow,1); // delete row from source sheet
}
}
Recently this has been crashing my sheet. Everytime someone puts an "x" in Column K, the sheet will stall and most of the time, it will crash and chrome will kill the page.
I could be wrong, but the problem I'm guessing is that most of the rows in sheet#1 have conditional formatting. When the line is copied, it also copies the conditional formatting. This results in my sheet#2 having hundreds of repeating conditional formatting: this sheet is VERY slow to open. IT could also be because this document is shared with about 30 people who view it and edit it very often: perhaps onEdit isn't the right function here?
Is there a simple script I could add to my function which would strip the conditional formatting on the pasted line? I don't need the conditional formatting in my sheet#2 and for some odd reason I can't find an answer to this anywhere.
Found this function from here.
clearFormats()
Clears the sheet of formatting, while preserving contents. Formatting
refers to how data is formatted as allowed by choices under the
"Format" menu (ex: bold, italics, conditional formatting) and not
width or height of cells.
Sample code:
function testKillFormatting (nameOfSheet) {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName(nameOfSheet);
sheet.clearFormats();
}

Getting duplicate pdf with jsPDF

I have just started using jsPDF for creating PDF. When I am saving it, it generates two PDF files at that time. The first PDF name is the same as I gave in the code but the second PDF name is any text (like: DXTRE5.pdf). I need only one PDF with the given file name. Please help me.
$('#print').click(function () {
var doc = new jsPDF();
var chartHeight = 80;
doc.setFontSize(15);
doc.text(35, 25, "Prospect Report Graph");
$('.myChart').each(function (index) {
var imageData = $(this).highcharts().createCanvas();
doc.addImage(imageData, 'JPEG', 45, (index * chartHeight) + 40, 120, chartHeight);
});
doc.save('reports_graph.pdf');
});
The code looks fine. This won't trigger any PDF export twice. It should be somewhere else where click binding of the #print should exist in your code. Check and find the code you could fix that issue.
That duplicate click binding may have line like doc.save('DXTRE5.pdf'); find and remove that binding.

UILabel - Multi lines are indented with firstLineHeadIndent

I've been wanted to indent only the first line of a paragraph.
I've been using firstLineHeadIndent as following :
let comment_message_style = NSMutableParagraphStyle()
comment_message_style.firstLineHeadIndent = 50.0
comment_message_style.headIndent = 0.0 // Tried to force other lines to 0 indent
var comment_message_indent = NSMutableAttributedString(string: "HELLO\nTest1\nTest Long Line so that it will break without adding the new line char to the string.")
comment_message_indent.addAttribute(NSParagraphStyleAttributeName, value: comment_message_style, range: NSMakeRange(0, comment_message_indent.length))
self.commentMessageLabel.attributedText = comment_message_indent
However, whenever I run the simulator, the indent is apply on all new lines. (see screenshot below)
I'm using the last version of Xcode 6.1 and running my project on iOS 8.0.
Any idea anyone?
The problem is Xcode is not able to recognize where is the end of the first line even if you used "\n" and I don't know why that's the case.
However the alternative way is to replace
var comment_message_indent = NSMutableAttributedString(string: "HELLO\nTest1\nTest Long Line so that it will break without adding the new line char to the string.")
with
var comment_message_indent = NSMutableAttributedString(string: "HELLO Test1\nTest Long Line so that it will break without adding the new line char to the string.")
the length of space = the total characters of your first line - 5.
This should do the work and your non-first lines will be indented properly and you don't have to add headIndent either.

TextArea scrolling not working [Titanium]

I am creating an iOS app in which the user clicks an image and letter "A" is concatenated to a string variable.
Now, I have a text area with value of the variable string. The text area value is updated every time a new letter is concatenated to the variable string.
The problem is that when the width of the text area; the letters that are added after that cannot be seen. How can I make the last character entered to be always visible once the string length has exceeded the width of the text area?
Need a fix for this !
Code :
var image = Ti.UI.createImageView({
backgroundColor:'red',
width: 200,
height:100
});
win.add(image);
var scroll = Ti.UI.createScrollView({
top:40,
left:230,
width:290,
height:50,
borderRadius:10,
backgroundColor:'transparent',
scrollType:'horizontal',
scrollingEnabled : 'true',
showVerticalScrollIndicator:true,
showHorizontalScrollIndicator:true,
});
win.add(scroll);
var textType = Ti.UI.createTextArea({
backgroundColor:'#E6E6E6',
borderColor:'blue',
borderRadius:10,
top:0,
left:-70,
width:390,
height:50,
font:{fontSize:26, fontFamily:customFont},
editable:true,
enabled:false,
textAlign:'right',
scrollable:true,
horizontalScroll : true,
scrollType:'horizontal'
});
scroll.add(textType);
image.addEventListener('click, function(e){
string = string + "A";
textType.setValue(string);
}
You could try setting horizontalWrap:true;, which would make the text appear on the next line rather than off screen.
Or alternatively, set scroll.contentOffset.x = textType.width - scroll.width if textType.width > scroll.width. I'm not sure about the syntactical nuances of Titanium, but this is how you would do it in regular Objective-C / iOS programs.

Resources