How to Convert Purchase Order to CSV Asynchronously using PHP

Nov 12, 2024·3 Minutes Read

In this tutorial, we'll guide you through converting a purchase order to CSV format asynchronously using PDF.co and PHP. This approach is especially useful for large PDF files, as asynchronous processing allows your code to run in the background without timing out. We’ll walk you through each step using a sample purchase order PDF.

Sample Purchase Order
Sample Purchase Order

Step 1: PHP Source Code

  • Copy the Sample Code: Start by copying the PHP sample code for the PDF.co PDF to CSV API. Paste it into your preferred editor, such as VS Code, Sublime Text, or PHPStorm.
  • Add Your API Key:Log in to your PDF.co account and retrieve your API Key from your dashboard. Replace the placeholder in the sample code with your actual API key.
  • Input the PDF URL:If your PDF file is available online, use its direct URL in the code. If you are working with a local PDF file, upload it to the PDF.co file storage and use the returned file token as your PDF URL.
  • Enable Asynchronous Processing: Asynchronous mode is ideal for large PDFs, allowing you to monitor the job's progress without risking a timeout. For more details, refer to PDF.co’s Asynchronous Processing Documentation.
PHP Source Code

Step 2: Save the PHP File in the Correct Directory

After editing the code, save the file in the appropriate folder:

  • For XAMPP users, save it in the /htdocs directory.
  • For WampServer users, save it in the /www directory.

This ensures that the PHP file is accessible from your localhost.

Save the PHP File in the Correct Directory

Step 3: Start the Apache Module

To execute the PHP program, ensure that your Apache server is running.

  • Open the XAMPP or WampServer control panel.
  • Click Start on the Apache module to activate the server.
XAMPP Control Panel

Step 4: Run the PHP Program

Now, let's run the program on your local machine:

  • Open your browser and type localhost/your-folder-name/your-file.php in the address bar.
    • Example: localhost/PDF to CSV/pdf-to-csv-async.php
  • Once the program runs, it will return an output URL.
    • Click on the output link to download the CSV file.
Run the PHP Program

Step 5: View Generated CSV Output

Here’s the generated CSV output from the purchase order:

View Generated CSV Output

In this tutorial, you learned how to convert a purchase order into CSV using PHP. You learned how to set up the code samples to get the converted output. You also learned how to use the PDF.co Web API to convert PDF files into CSV.

Related Tutorials

See Related Tutorials