Using ASP.NET PDF Viewer Control
How to view a merged PDF from multiple files in ASP.NET PDF Viewer control using C#?
How to merge multiple files into one PDF file, and open, view, edit it in web browser using C# ASP.NET PDF Viewer control.
Open, read, view and comment a new merged PDF from multiple files in ASP.NET using C# is very simple. EdgePDF provides a simple C# demo code to accomplish the job.
- Create a new combined PDF from multiple PDF files, or other file formats, such as Word, Excel, PowerPoint, Tiff, JPG, PNG images
- Read, view, edit newly merged PDF file in web browser
How to view a merged PDF file programmatically in asp.net using C#
Preparation
To run the following tutorial successfully, we need the following setup ready.
- Install EdgePDF demo project in IIS
- Several demo PDF files in folder C:\temp\merge\
How to read, view, a merged PDF from two PDF files online in ASP.NET C#?
The following steps and C# source code will help to setup a demo ASP.NET project, which allows you to read, view a merged PDF file from two PDF documents in web browser using ASP.NET C# code.
After you have completed the following guide, you can open, view a combined PDF file for commenting, editing through url (a sample url
http://localhost:56643/?yourtarget1=merge/pdf-1.pdf&yourtarget2=merge/pdf-scanned-1.pdf)
- Open file UserCommandProcessHandler.ashx from {EdgePDF demo project}/RasterEdge_Resource_Files/
- Go to method FileProcess()
- Get two target PDF files' id from url parameter "yourtarget1" and "yourtarget2"
- Create two new PDFDocument object with target PDF files loaded
- Get a new PDF document PDFDocument object with two PDF files combined
- Call method REProcessControl.PageLoadFile() to load merged PDF document into EdgePDF for viewing, annotating, editing
public override PDFWebDocument FileProcess()
{
HttpRequest request = this.Context.Request;
if (!String.IsNullOrEmpty(request.QueryString["yourtarget1"]) && !String.IsNullOrEmpty(request.QueryString["yourtarget2"]))
{
PDFDocument sourceDoc1 = new PDFDocument(@"C:\\temp\" + request.QueryString["yourtarget1"]);
PDFDocument sourceDoc2 = new PDFDocument(@"C:\\temp\" + request.QueryString["yourtarget2"]);
PDFDocument[] sourceDocs = new PDFDocument[] {sourceDoc1, sourceDoc2};
PDFDocument mergedDoc = PDFDocument.CombineDocument(sourceDocs);
String fileName = "merged.pdf";
return REProcessControl.PageLoadFile(request, this.Manager, mergedDoc, fileName);
}
else
{
Logger.Log(">>> Unknown load file mode. Load default file defined in Web.config.", LogType.DEBUG);
// load default file. defined in Web.config
return REProcessControl.PageLoadFile(request, this.Manager, "", LoadType.Server);
}
}