mlapi
HomeBlog
  • Welcome
  • Extract Text from PDF
    • Parameters
    • Supported File types
    • Error Responses
    • Programming Languages
      • Python
      • Javascript
      • Curl
      • Java
      • Go
      • Rust
      • C++
    • Web and Mobile frameworks
      • React
      • React Native (Javascript)
      • HTML
      • PHP
      • Rust (with Active-Web)
      • Angular
      • Flutter
      • Andriod Development (Java)
      • Swift
      • Vue.js
      • Svelte
    • Pricing
    • On Premise Deployment
Powered by GitBook
On this page
  1. Extract Text from PDF
  2. Web and Mobile frameworks

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>

PreviousReact Native (Javascript)NextPHP

Last updated 9 months ago