1
votes

I am attempting to create a password protected way to place my signature in google docs and create a PDF. I was able to complete the password protection, add the signature, and send to PDF. This is not shown below but I use a term "{{Sig}}" already in the document to be replaced by the image file. I don't want the image to remain in the google doc. the code below removes the signature image. However, I want to put the "{{Sig}}" term back in to allow for future signatures if needed. I am able to do that by searching for "Sincerely," immediately before where "{{Sig}}" should be. However, there ends up being one additional blank line in between "{{Sig}}" and my name. Is there a method of finding and removing that line?

function DelSig(fileID)  {
  var docTarget = DocumentApp.openById(fileID);
  var docBody = docTarget.getBody();
  var docImages = docBody.getImages();
  var docText = docBody.getText();
  var docImage = docImages[0];
  docImage.removeFromParent();
  myFunction = docReplace(docTarget, "Sincerely,", "Sincerely,\n{{Sig}}");
  docTarget.saveAndClose();
  docTarget = DocumentApp.openById(fileID);
  docBody = docTarget.getBody();
}

Also, here is my docReplace function:

function docReplace(docTarget,oldStr,newStr) {
  var docBody = docTarget.getBody();
  docBody.replaceText(oldStr,newStr);
}
How do I bring the text below the letter S up one line? Also, this is in the Google Doc file. I am not wanting to change the PDF. Thank you for your input, it is much appreciated.sh529
Actually the \n is not taking it down 2 lines. The problem is when I delete the signature image it leaves the line there which I did not have before I placed the signature image. I am wanting to delete the line the image was on as it is now an empty line. I am actually wanting to delete that line that is under {{Sig}}. If there was a character for the empty line I could include it in my replace.sh529
As i said before there is unlikely to be a "blank" line, just the absence of one, I am struggling to understand how google is detecting related placement other tan the sig was spanning the void approximately equal to two conventional lines of text. e.g. did adding the {sig} image push sincerely down to a lower Y value at that time, if so that cant be re-undoneK J
3 small images showing the last line(s) of text before sig is applied, when sig is added and after removal would clarify exactly what may be happening even better dummy files with a false sig image same size.K J
Can you share an example doc which demonstrates this?Rafa Guillermo