If your PDFs deal with invoices, receipts, passports or driver's licenses, check out Nanonets' PDF scraper or PDF to XML converter to convert PDF documents to XML for free. Click below to learn more about Nanonets' PDF scraper.


Why Convert PDF to XML?

XML format

The PDF file format is convenient for visualizing & sharing data. But PDFs are not machine readable! The data contained in PDFs isn’t structured in a format that computers can “read” or “understand”.

Converting a PDF to XML or any other structured format (CSV, JSON, Excel etc.) allows computers to process data easily. This is especially crucial for organizations that look to embrace end-to-end digital workflows.

This article covers various options to convert PDF to XML. It also touches upon the structural merits of the XML format as well as challenges in converting PDFs to XML.

Table of Contents


Want to extract text from PDF documents or convert PDF table to Excel? Check out Nanonets PDF scraper or PDF parser to scrape PDF data or parse PDFs at scale!


What is XML & Why Convert PDF to XML

The XML file format

XML or Extensible Markup Language is a popular text-based markup language. It defines rules for encoding documents in a format that is accessible (readable) to machines (computers) as well as humans.

The XML format provides a tag hierarchy to store, identify & organize data. Users can define their own tags & hierarchy; nothing is predefined. XML is widely used in web applications & text/word processors to define document structures.

Developers, web designers or database engineers often receive data as PDF files. While PDFs ensure a standard of visualization across any device, they are not machine readable! Converting a PDF document to XML provides structure & hierarchy to an otherwise “flat” document. Data can be ordered & defined with tags to facilitate convenient processing by computers.

PDF to XML conversion allows businesses to digitize & automate document processing workflows to a great extent.


Want to rename PDF files based on content or convert PDF bank statements to Excel?


How to convert PDF to XML

Convert PDF to XML
PDF to XML conversion

Converting a PDF document to XML requires pulling information from the document and then assigning appropriate tags to structure the extracted data in the XML syntax. Here are your options:

  • One could manually copy the PDF data and edit it to fit the XML syntax.
    • Attempting to extract and organize the data manually would be inefficient. It would also be time-consuming, error-prone and impossible to scale.
  • Luckily there are numerous online PDF to XML (or PDF to tables) converters that do a decent job such as PDFTables, FreeFileConvert & AConvert.
    • While the conversion is quite accurate, such tools can’t handle complex PDFs, large volumes & batch processing of documents. And they are usually not automated, thus requiring considerable manual effort to function in organizational use cases.
  • Intelligent document processing (IDP) software, like Nanonets, offer the most effective, accurate & scalable solution for a fully automated PDF to XML converter. IDP software like Nanonets leverage OCR, AI & ML capabilities to extract data from PDFs & other documents autonomously.
    • This is unlike most template-based OCR software that require users to define areas of interest for each document with a different layout.

Need a free online OCR for image to text, PDF to table, PDF to text, or PDF data extraction? Check out Nanonets' online OCR API in action and start building custom OCR models for free!


Convert PDF to XML with Nanonets

Converting PDF documents to XML is pretty straightforward with Nanonets. Nanonets offers 2 methods to convert PDF to XML:

Pre-trained Model

If you are looking to convert invoices, receipts, passports or driver's licenses from PDF to XML, then check out Nanonets’ pre-trained models for each of the above-mentioned document types. Each of these models has been trained on millions of documents and performs very well on its respective document types.

Here’s a demo of Nanonets’ pre-trained Receipt OCR model. Notice that the “Export” option provides XML as the first choice; apart from Excel & csv.

Here are the steps in detail:

  • Login to Nanonets - Select an appropriate pre-trained model - if none suit your use case, skip to the next method (Custom Model)
  • Add the PDF files - upload the PDFs that you wish to convert
  • Test & verify - run the Nanonets model & verify the extracted data
  • Export - download the data extracted from the PDFs as an XML

Custom Model

If you are looking for custom data extraction requirements then build a custom data extractor/converter with Nanonets. You can typically build, train and deploy a model for any document type, in any language, all in under 25 minutes.

Here’s a demo on how to train a custom data extraction model with Nanonets. As shown in the demo above, the “Export” option will provide XML as the first choice.

Here are the steps in detail:

  • Login to Nanonets - Create a custom OCR model
  • Add training files - Upload sample PDFs that will serve as a training set for Nanonets
  • Annotate text/data on the PDFs - “Teach” Nanonets AI to identify important data (specific to your requirements) in these training files
  • Train the custom OCR model - Nanonets leverages deep learning to build various OCR models and tests them against each other to pick the most accurate one.
  • Test & verify - Add a couple of PDFs to verify whether the custom OCR model suits your requirements/use case
  • Export - If the text has been recognized, extracted and presented appropriately then export the file - download the data extracted from the PDFs as an XML

Convert PDF to XML with Nanonets API

If you’re looking to train/build your own PDF to XML converter, check out the Nanonets API. In the documentation, you will find ready to fire code samples in Shell, Ruby, Golang, Java, C# and Python, as well as detailed API specs for different endpoints.


Nanonets online OCR & OCR API have many interesting use cases that could optimize your business performance, save costs and boost growth. Find out how Nanonets' use cases can apply to your product.


Update June 2021: this post was originally published in May 2021 and has since been updated.

Here's a slide summarizing the findings in this article. Here's an alternate version of this post.