# Best Practice to PHP Output PDF to Browser Directly – PHP Tutorial

By | August 10, 2019

To make browser show pdf file, we can:

## Use html embed

<embed width="100%" height="600" src="https://www.example.com/1.pdf"> </embed>

or Open a pdf url by browser.

However, these two methods of displaying pdf file is hard to make some control, for example, if we only want to valid user to read pdf, how to control? To do this, we need output pdf file by php script. In this tutorial, we will show you how to do.

## Set charset

<meta charset="utf-8">

header("Content-type: application/pdf");
pdf = '1.pdf';
echo file_get_contents(pdf);