XML to PDF Converter

Print an XML file as an indented, readable listing on A4 pages.

or drop files here

XM

XML Format

Extensible Markup Language

A markup language for structured data, maintained by the W3C. Custom tags describe the data, and both people and programs can read it.

  • Text-based
  • User-defined tags
  • W3C Recommendation
  • Validated with schemas
PD

PDF Format

Portable Document Format

A document format created by Adobe in 1993 and standardized as ISO 32000. It keeps text, fonts, images and layout the same on any device.

  • Fixed page layout
  • Embedded fonts
  • Vector and raster content
  • Optional encryption and signatures

How to convert an XML file to PDF

Your XML is read in your browser and listed, an element a line, on A4 pages in a PDF named after your file.

    1

    Upload your XML file.

    2

    We check that it's well-formed, then list its elements, attributes, text, comments and CDATA, each level of nesting two spaces further in.

    3

    Download the PDF, which opens and prints the same on any device.

What to know before converting XML to PDF

  • The PDF is a listing of the XML, not a rendering: no XSLT, XSL-FO or e-invoice layout.
  • Pages are A4 portrait with 3/4 inch margins and 10 point text.
  • The file must be well formed, and a parse error stops with its line and column.
  • Entities are never fetched; only the five built-in ones and numeric references are read.
  • Files up to 20 MB and 2,000 pages are accepted.

About XML files

What is an XML file?

XML stands for Extensible Markup Language. The W3C developed it from a subset of SGML, and the fifth edition of XML 1.0 became a W3C Recommendation in November 2008. A document has a single root element with properly nested content, made of elements, attributes, character data and entities. A conforming processor must accept UTF-8 and UTF-16.

XML describes structure, not appearance. The tags are yours to define, so an invoice, a sitemap, a feed and a configuration file are all XML but mean different things. RFC 7303 defines the application/xml media type and treats text/xml as its alias. You meet XML in data exchange between systems, in configuration files and in feeds and sitemaps. Plain XML says nothing about fonts, page size or colors, so there is no single correct way to print it, and that is why a converter has to choose one.

Programs that open XML files

Windows / Mac / Linux

  • Visual Studio Code: opens XML source in its XML language mode.
  • xmllint: reads XML and reports parsing errors; it comes with libxml2.

XML and PDF compared

  • What they are: XML is text that structures data, and PDF fixes content onto pages. PDF pages can hold text next to vector graphics and raster images, and a PDF can add links, bookmarks and forms.
  • Extensions and media types: .xml with application/xml; .pdf with application/pdf.
  • Origin: Adobe's Camelot project started in 1991 and was PDF by 1992. It was meant to capture a document from any application and display or print it identically anywhere. ISO 32000-1 adopted PDF 1.7 in 2008.
  • Fonts: fonts must be embedded in a PDF for it to look identical on every system.
  • Validation: well-formed syntax does not show that the data satisfies a DTD or an application schema.

The XML to PDF page does not render the file. It prints a listing: one line for each node, with every element followed by its attributes in source order and indented two columns for each level, down to 20 levels. Text sits beside its element when that is all the element holds. CDATA keeps its lines. Comments, processing instructions and the DOCTYPE are gray.

The encoding is taken from the byte order mark, a UTF-16 <?, or the XML declaration, in that order, and otherwise the file is read as UTF-8 and then Windows-1252. Elements nested deeper than 20 levels share the indent of the 20th. Text lines inside an element are trimmed, and a long line wraps with its continuation indented. The listing is for reading and review, for example to send someone a file they would rather not open in an editor. It is not a byte-exact copy, so keep the XML as your source.

The pages are A4 portrait with 3/4 inch margins, in 10 point type on 12 point lines, with no header, footer or page numbers. A file whose text is entirely Windows-1252 is set in Courier, and any other character sets the whole file in DejaVu Sans.

Other ways to convert XML to PDF

  • Apache FOP (command line): pass the XML and a stylesheet to FOP and name the PDF with -pdf, as in fop -xml report.xml -xsl layout.xsl -pdf report.pdf. The stylesheet has to turn your XML into valid XSL-FO, because plain XML does not define a page layout.

Problems with XML files

  • Tags don't match: an unclosed element, overlapping elements or a second root element stops a strict parser. Fix the line and column the error names.
  • A schema is not checked: a file that passes here is well formed, which says nothing about whether its contents are right for the program that will use them.
  • An undeclared entity: a strict parser can reject a reference to an undeclared entity as a well-formedness error, while this page shows any entity beyond the five built-in ones as written.
  • A repeated attribute: XML forbids repeating an attribute on one element, but the parser used here accepts it and the listing keeps only the first value.
  • The file has no content: a file holding only whitespace and control characters is refused by this page as empty, and a file with no element at all is refused as malformed.
  • The encoding is wrong: bytes that disagree with the declared character encoding make the file unreadable. Save a UTF-8 copy and fix the declaration.

Frequently Asked Questions

Everything you need to know about our converter

How do I convert XML to PDF?

Can you convert XML to PDF with the layout of an invoice?

How do I change XML to PDF with my own stylesheet?

What do the pages look like?

Is my XML checked against a schema?

What does a malformed XML error with a line and column mean?

Does the page download external entities?

Why is my XML refused for its characters?

How big can the XML file be?

What happens to comments and the DOCTYPE?