Q:

How can I convert a string of pdf code into a blob? 

I briefly summarize my problem:
I'm calling an API that returns a pdf like 
"% PDF-1.4%%1 0 obj
<<
/ Type / Catalog/ PageLayout / OneColumn/ 
Pages 2 0 R/ PageMode / UseNone 
......... " 
currently, I receive it in string format to be able to make changes and so far so good, but after making changes I would like to convert the string to blob to download the pdf.  In doing this I am having problems, the text string converted to blob does not generate the correct pdf, or rather the pdf once opened is white, when in reality it should have data. 
The code I'm using now is the following:
response.text().then((content) => {
   //...TODO: Modify pdf
   var blob = new Blob([content], { type: "application/pdf" });
   saveAs(blob, "invoice.pdf");
}).catch(error => {
   console.log(error);
});

The pdf is downloaded but if I open it it is empty. 
I would like to be able to modify the pdf string and convert it back into a blob to be able to download it. 
Does anyone have an idea how I could do it? 

A:

A PDF consists of a set of objects in a non-trivial fashion.   If you are receiving it as a string and are using standard string manipulation functions on it, e.g. find and replace you are most likely going to corrupt it.   You would have to edit in accord with the standards laid out in the PDF specification and not violate the syntax.   This is a very fragile approach, you need to use a PDF library instead to edit your PDF content.