Frequently Asked Question:
How are PDFs displayed?
Question
How are PDFs displayed? If I wanted to create my own PDF viewer, how steps would be required?
Answer
To display/render a PDF page the following steps need to be taken:
- Locate the page object in the PDF.
- Extract the page's content streams (one or more strings).
- Parse the content stream to get the page description commands - these are similar to PostScript language commands
- The content streams commands refer to one or more resources (fonts, images, etc.) - these resource objects are located in the PDF and images are decoded and fonts are processed to obtain the glyph outlines.
- As the page content is followed there are operations that adjust the user matrix which change the position, scaling and rotation.
- These commands / objects collectively describe the page in mathematical terms and are then converted into an appropriate output - either an image (using GDI+ in our case) or a different graphical language like EPS, EMF/WMF etc.
Text is simply a collection of shapes just like other graphic content.
Quick PDF Library, Adobe Acrobat and Foxit Reader all follow these same steps in order to display a PDF.