Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

289
Views
How to create rtf file from a Blob in Javascript

I'm trying to create a rtf from my state variables, the file is created but it's corrupted I can't open it. How can I convert string into rtf file?

enter image description here

const Example = () => {
  const [headers, setHeaders] = React.useState(['Header 1', 'Header 2', 'Header 3']);
  const [content, setContent] = React.useState([['Content 1', 'Content 2', 'Content 3'], ['Content 4', 'Content 5', 'Content 6']])
  const [downloadUrl, setDownloadUrl] = React.useState('');
  
  
  const createDownUrl = () => {
    const fileHeaders = headers.join(' ');
    const fileContent = content.map(i => i.join(' ')).join('\r\n');
  
    const data = new Blob([`${fileHeaders}\r\n${fileContent}`]);
    setDownloadUrl(URL.createObjectURL(data))
  }
  
    return (
      <div>
        <button onClick={() => createDownUrl()}>
          Create download link
        </button>
        
        {downloadUrl && <a download={'Example.rtf'} href={downloadUrl}>Download</a>}
      </div>
    );
  };
  
  // Render it
  ReactDOM.render(
    <Example  />,
    document.getElementById("react")
  );
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/17.0.1/umd/react.production.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/17.0.1/umd/react-dom.production.min.js"></script>
<div id="react"></div>

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!