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

PHP

PDF url

<?php
$api_key = "your_api_key";
$pdf_url = "https://example.com/your-pdf.pdf";

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => "https://v1.mlapi.co/pdf/pdf-to-text",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "POST",
  CURLOPT_POSTFIELDS => http_build_query(array('pdf_url' => $pdf_url, 'api_key' => $api_key)),
));

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
  echo "cURL Error #:" . $err;
} else {
  echo $response;
}
?>

Upload PDF file

<?php
$api_key = "your_api_key";
$file_path = "path/to/your-pdf.pdf";

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => "https://v1.mlapi.co/pdf/pdf-to-text",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "POST",
  CURLOPT_POSTFIELDS => array('file' => new CURLFile($file_path), 'api_key' => $api_key),
));

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
  echo "cURL Error #:" . $err;
} else {
  echo $response;
}
?>

PreviousHTMLNextRust (with Active-Web)

Last updated 9 months ago