EdgePDF
Features
Tech Specs
How-to C#
Pricing
HTML5 Viewer & Editor
  |  
Home ›› XDoc.PDF ›› C# PDF: HTML5 PDF Viewer

How to load & save Adobe PDF documents into EdgePDF ASP.NET PDF Editor


Online Guide for loading, saving Acrobat PDF file into HTML PDF Editor using Web browser






How to load PDF document into EdgePDF ASP.NET PDF Editor




This example will open a PDF file located under your server "C:/temp/1.pdf", through url:
http://localhost:9090/?yourtarget=/1.pdf.

Next one will allow you to define a new command in toolbar. And you can save modified pdf file to original file location "C:/temp/1.pdf"

With EdgePDF HTML5 PDF Editor, you can easily load a file from your server file system or database into viewer.

Here are the details:
  • Setup EdgePDF demo project in IIS
  • In Default.aspx.cs

    // load file from your target
    string targetkey = Request.QueryString["yourtarget"];
    <br/><br/>
    RasterEdge.XDoc.PDF.PDFDocument pdf = new RasterEdge.XDoc.PDF.PDFDocument("C:/temp" + targetkey);
    // object can be PDFDocument,File bytes or File Stream
    // file name must be ended with file extension, like ".pdf", ".docx"
    webDoc = REProcessControl.PageLoadFile(Request,pdf,"yourdoc.pdf");
    


    You can use the targetKey value to locate your file from file system or database, and load file into PDFDocument object.
  • Now you navigate to "http://localhost/?yourtarget={your file location key}" to open file in EdgePDF editor.
  • You can change http parameter yourterget to other names, like fileid.



How to Save file from EdgePDF into your file system




Define your saving command in viewer toolbar
Navigate to {EdgePDF Demo Project}/ RasterEdge_Resource_Files/Javascript/ RasterEdge_WebApp_Customize.js
Define your command in function initCustomize()

    var myIcon = new CToolbarIcon();
    myIcon.id="myIcon";
    myIcon.event = "saveOnServer()";
    myIcon.title = "Save on server";
    myIcon.reqDoc = true;


    var myGroup = new CToolbarIconGroup();
    myGroup.name="Save Server";
    myGroup.addIcon(myIcon);

    var myTab = new CToolbar();
    myTab.id = "Customizebar";
    myTab.name = "Customize";
    myTab.addIconGroup(myGroup);

    addToolbarTab(myTab);


Define server side processing method to handle your command

// demo function to save the file on server
function saveOnServer() {
    // whether the file is loaded
    if (getCurrentFileId() == "")
        return;
    // get the basic save datas from API(getSaveDatas)
    var datas = getSaveDatas();
    // set the customize calling function in userCommandProcessHandler
    datas.action = "SaveFileOnServer";
    var options = {
        type: "POST",
        url: getServerHandlerUrl(),
        async: false,
        data: datas,
        success: function (result) {
            // hide the loading panel
            $("#loading").hide();
            // get the message
            var arr = eval('(' + result + ')');
            if (arr.state == "success") {
                saveFile = arr.msg;
                // open the file that store on server
                window.open(_cacheFolder + "/" + getCurrentFileId() + "/" + saveFile);
            }
            else {
                alert(arr.msg);
            }
        },
        error: function (err) {
            $("#loading").hide();
        }
    }
    // show the loading panel
    $("#loading").show();
    // send the message
    $.ajax(options);
}


Process your saving command in the server side
Navigate to {EdgePDF Demo Project}/ RasterEdge_Resource_Files/ UserCommandProcessHandler.ashx

    public void SaveFileOnServer()
    {
        string fid = _httpRequest["fid"];
        // you can process saved pdf document here, like add watermark, ...
        object document= this.SaveFile();
        if (document is RasterEdge.XDoc.PDF.PDFDocument)
        {
            RasterEdge.XDoc.PDF.PDFDocument pdfDoc = document as RasterEdge.XDoc.PDF.PDFDocument;
            // get the upload information of the file
            RasterEdge.WDP.DocUploadInfo docinfo =  this.getDocUploadInfo(fid);

            string filename = docinfo.FileName;
            // get your file open url parameters value, if needed.
            string paraFilepathValue = docinfo.GetRequestParameters("yourtarget");

            RasterEdge.XDoc.PDF.PDFMetadata metadata = pdfDoc.GetDescription();
            metadata.Producer = "RasterEdge PDF HTML5 Viewer";
            pdfDoc.SetDescription(metadata);

            try
            {
                pdfDoc.Save("C:/temp" + paraFilepathValue);
            }
            catch (Exception e)
            {
                // process error code, and return error information here
            }
        }
    }