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);
}