EVO HTML to PDF Converter allows you to set various PDF viewer preferences to be used when the generated PDF document is displayed in a PDF viewer. You can hide the viewer menu and toolbar, you can instruct the viewer to initially display the bookmarks, thumbnails or attachments and you can select the page layout to one or two columns.
The PDF viewer preferences can be set in HtmlToPdfConverterPdfViewerPreferences object. The most important options are detailed below.
PDF Viewer Preferences
Page Mode. You can use this option to instruct the PDF viewer to initially display the bookmarks panel, thumbnails panel or attachments panel when the generated PDF document is opened. The property you can set in your code for this option is ViewerPreferencesPageMode
Page Layout. You can use this option to set the PDF page layout to continuous one column, single page, two column left, two column right when the generated PDF document is opened. The property you can set in your code for this option is ViewerPreferencesPageLayout
Hide Menu Bar. You can use this option to hide the menu bar of the PDF viewer when the generated PDF document is opened. The property you can set in your code for this option is ViewerPreferencesHideMenuBar
Hide Toolbar. You can use this option to hide the toolbar of the PDF viewer when the generated PDF document is opened. The property you can set in your code for this option is ViewerPreferencesHideToolbar
Hide Window UI. You can use this option to hide the user interface elements (scroll bars, navigation controls) of the PDF viewer when the generated PDF document is opened. The property you can set in your code for this option is ViewerPreferencesHideWindowUI
Display Document Title. You can use this option to display the document title in PDF viewer title bar when the generated PDF document is opened. The property you can set in your code for this option is ViewerPreferencesDisplayDocTitle
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Http;
// Use EVO PDF Namespace
using EvoPdf.Chromium;
namespace EvoPdf_Chromium_AspNetDemo.Controllers.HTML_to_PDF
{
public class PDF_Viewer_PreferencesController : Controller
{
public ActionResult Index()
{
return View();
}
[HttpPost]
public ActionResult ConvertHtmlToPdf(IFormCollection collection)
{
// Set license key received after purchase to use the converter in licensed mode
// Leave it not set to use the library in demo mode
Licensing.LicenseKey = "4W9+bn19bn5ue2B+bn1/YH98YHd3d3c=";
// Create a HTML to PDF converter object with default settings
HtmlToPdfConverter htmlToPdfConverter = new HtmlToPdfConverter();
// Set the PDF Viewer Preferences
// Set page layout to continuous one column, single page, two column left, two column right
htmlToPdfConverter.PdfViewerPreferences.PageLayout = SelectedPageLayout(collection["pageLayoutComboBox"]);
// Set page mode to default, display bookmarks, display thumbnails, display attachments
htmlToPdfConverter.PdfViewerPreferences.PageMode = SelectedPageMode(collection["pageModeComboBox"]);
// Hide the viewer menu
htmlToPdfConverter.PdfViewerPreferences.HideMenuBar = collection["hideMenuBarCheckBox"].Count > 0;
// Hide the viewer toolbar
htmlToPdfConverter.PdfViewerPreferences.HideToolbar = collection["hideToolbarCheckBox"].Count > 0;
// Hide scroll bars and navigation controls
htmlToPdfConverter.PdfViewerPreferences.HideWindowUI = collection["hideWindowUICheckBox"].Count > 0;
// Display the document title in viewer title bar
htmlToPdfConverter.PdfViewerPreferences.DisplayDocTitle = collection["displayDocTitleCheckBox"].Count > 0;
// Convert the HTML page to a PDF document in a memory buffer
byte[] outPdfBuffer = htmlToPdfConverter.ConvertUrl(collection["urlTextBox"]);
// Send the PDF file to browser
FileResult fileResult = new FileContentResult(outPdfBuffer, "application/pdf");
fileResult.FileDownloadName = "Set_PDF_Viewer_Preferences.pdf";
return fileResult;
}
private ViewerPageLayout SelectedPageLayout(string selectedValue)
{
switch (selectedValue)
{
case "Single Page":
return ViewerPageLayout.SinglePage;
case "One Column":
return ViewerPageLayout.OneColumn;
case "Two Column Left":
return ViewerPageLayout.TwoColumnLeft;
case "Two Column Right":
return ViewerPageLayout.TwoColumnRight;
default:
return ViewerPageLayout.OneColumn;
}
}
private ViewerPageMode SelectedPageMode(string selectedValue)
{
switch (selectedValue)
{
case "Default":
return ViewerPageMode.UseNone;
case "Display Outlines":
return ViewerPageMode.UseOutlines;
case "Display Thumbnails":
return ViewerPageMode.UseThumbs;
case "Display Full Screen":
return ViewerPageMode.FullScreen;
case "Display Optional Content Group":
return ViewerPageMode.UseOC;
case "Display Attachments":
return ViewerPageMode.UseAttachments;
default:
return ViewerPageMode.UseNone;
}
}
}
}