HTML

PDF URL

<!DOCTYPE html>
<html>
<head>
  <title>Extract Text</title>
</head>
<body>
  <button onclick="extractText()">Extract Text</button>
  <pre id="result"></pre>

  <script>
    async function extractText() {
      try {
        const response = await fetch('https://v1.mlapi.co/pdf/pdf-to-text', {
          method: 'POST',
          headers: {
            'Content-Type': 'application/x-www-form-urlencoded',
          },
          body: new URLSearchParams({
            pdf_url: 'https://example.com/your-pdf.pdf',
            api_key: 'your_api_key',
          }),
        });
        const data = await response.json();
        document.getElementById('result').textContent = data.text;
      } catch (error) {
        console.error('Error:', error);
      }
    }
  </script>
</body>
</html>

Upload PDF file

<!DOCTYPE html>
<html>
<head>
  <title>Extract Text</title>
</head>
<body>
  <input type="file" id="fileInput">
  <button onclick="extractText()">Extract Text</button>
  <pre id="result"></pre>

  <script>
    async function extractText() {
      const fileInput = document.getElementById('fileInput');
      const file = fileInput.files[0];

      const formData = new FormData();
      formData.append('file', file);
      formData.append('api_key', 'your_api_key');

      try {
        const response = await fetch('https://v1.mlapi.co/pdf/pdf-to-text', {
          method: 'POST',
          body: formData,
        });
        const data = await response.json();
        document.getElementById('result').textContent = data.text;
      } catch (error) {
        console.error('Error:', error);
      }
    }
  </script>
</body>
</html>

Last updated