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);
}
The three images below show what is happening. The image to the left shows how I have it to begin in the Google Doc. The center image is a screenshot of the PDF with the rectangle representing the signature. The image to the right is how it ends up in the Google Doc. The code deletes the signature image but leaves a blank line (or empty paragraph?). That empty paragraph would have a different index depending on the document. Is there any way to search for and replace that empty paragraph?