# Printing

> Print from the Document Viewer: the Print and Download buttons, printDocument with the print function of the browser, downloadDocument and FormattingPrinter.

- **Product:** TX Text Control .NET Server
- **Section:** Documentation
- **Kind:** Topic
- **Path:** TX Text Control .NET Server > Document Viewer > Printing
- **1713 words**
- **Web URL:** https://docs.textcontrol.com/tx-text-control-dotnet-server/document-viewer/printing/
- **LLMs URL:** https://docs.textcontrol.com/tx-text-control-dotnet-server/document-viewer/printing/llms.txt
- **LLMs-Full URL:** https://docs.textcontrol.com/tx-text-control-dotnet-server/document-viewer/printing/llms-full.txt

---

Users print a document from the toolbar of the Document Viewer, and your code can start printing from buttons on your own page. For browsers that don't support printing from the viewer, your page can offer the document as a PDF file instead.

The examples change the view of the [ASP.NET Core](https://docs.textcontrol.com/tx-text-control-dotnet-server/getting-started/document-viewer/aspnet-core/llms-full.txt) tutorial.

### How Printing Works

The toolbar of the viewer has two buttons for getting a document out of the viewer:

- **Print** prints the document with the print function of the browser. The browser shows its print dialog.
- **Download** downloads the document as a PDF file, which users open and print with any application.

Not all browsers support printing from the viewer. For users of such browsers, offer the download.

### Print and Download From Code

[printDocument](https://docs.textcontrol.com/tx-text-control-dotnet-server/reference/javascript-document-viewer/documentviewercontroller/printdocument-method/llms-full.txt) and [downloadDocument](https://docs.textcontrol.com/tx-text-control-dotnet-server/reference/javascript-document-viewer/documentviewercontroller/downloaddocument-method/llms-full.txt) do the same as the two buttons. The following view adds a **Print** and a **Download PDF** button below the viewer. Replace the content of *Views/Home/Index.cshtml*:

```cshtml
@using TXTextControl.Web.MVC.DocumentViewer
@using System.Text

<div style="width: 800px; height: 600px;">

@Html.TXTextControl().DocumentViewer(settings => {
    settings.DocumentData = Convert.ToBase64String(
        Encoding.ASCII.GetBytes("<strong>Sample Content</strong>"));
    settings.Dock = DocumentViewerSettings.DockStyle.Fill;
}).Render()

</div>

<input type="button" id="printButton" value="Print" disabled />
<input type="button" id="downloadButton" value="Download PDF" disabled />

<script>
    // TXDocumentViewer exists only after this event
    window.addEventListener("documentViewerLoaded", function () {
        var printButton = document.getElementById("printButton");
        var downloadButton = document.getElementById("downloadButton");

        printButton.disabled = false;
        downloadButton.disabled = false;

        // Uses the print function of the browser; not all browsers support it
        printButton.addEventListener("click", function () {
            TXDocumentViewer.printDocument();
        });

        // A PDF file that users can print with any application
        downloadButton.addEventListener("click", function () {
            TXDocumentViewer.downloadDocument();
        });
    });
</script>
```

The code works as follows:

- The buttons are disabled until the viewer has raised `documentViewerLoaded`, because [TXDocumentViewer](https://docs.textcontrol.com/tx-text-control-dotnet-server/reference/javascript-document-viewer/txdocumentviewer/llms-full.txt) doesn't exist before.
- `printDocument` prints the content of the document with the print function of the browser. It takes no parameters.
- `downloadDocument` downloads the current document as a PDF file. It takes no parameters either.

Run the application and click **Print**: the print dialog of the browser opens with the text "Sample Content".

Both methods return nothing, and the viewer raises no events for printing. Your code can't find out whether the user printed the document or canceled the dialog.

To create a PDF document that contains the values users entered into form fields or the annotations they added, save the document with `saveDocument` instead, as described in [Saving Documents](https://docs.textcontrol.com/tx-text-control-dotnet-server/document-viewer/saving/llms-full.txt).

### The Formatting Printer

[DocumentViewerSettings.FormattingPrinter](https://docs.textcontrol.com/tx-text-control-dotnet-server/reference/txtextcontrol-web-mvc-documentviewer/documentviewersettings/formattingprinter-property/llms-full.txt) sets the name of a printer whose text dimensions format the document, so that the displayed and the printed document have the same dimensions when the document is printed with this printer:

- `"Standard"` uses the installed standard printer of the system.
- `"Display"` uses the font dimensions of the display.
- If the named printer isn't installed, the standard printer is used.

```cshtml
@Html.TXTextControl().DocumentViewer(settings => {
    settings.DocumentPath = "App_Data/template.docx";
    settings.Dock = DocumentViewerSettings.DockStyle.Fill;
    settings.FormattingPrinter = "Display";
}).Render()
```

The reference doesn't state whether this setting has an effect with the Core engine. For the Document Editor, printer-specific formatting isn't supported by its cross-platform backend; see [Viewing and Printing](https://docs.textcontrol.com/tx-text-control-dotnet-server/document-editor/viewing-printing/#print-the-document).

### Next Steps

- [Saving Documents](https://docs.textcontrol.com/tx-text-control-dotnet-server/document-viewer/saving/llms-full.txt): save the document with form values and annotations.
- [User Interface](https://docs.textcontrol.com/tx-text-control-dotnet-server/document-viewer/user-interface/llms-full.txt): show, hide and disable the toolbar.
- [Annotations](https://docs.textcontrol.com/tx-text-control-dotnet-server/document-viewer/annotations/llms-full.txt): let users comment documents before they print them.

---

## Nearby

- **Previous:** [Zooming](https://docs.textcontrol.com/tx-text-control-dotnet-server/document-viewer/zooming/llms-full.txt)
- **Next:** [User Interface](https://docs.textcontrol.com/tx-text-control-dotnet-server/document-viewer/user-interface/llms-full.txt)
