EdgePDF
Features
Tech Specs
Online Demo
How to
Pricing

ASP.NET PDF Viewer Web Control
C#: how to display, save, convert, export PDF file in server side file system or database in asp.net mvc razor project


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












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 SaveCallBack(string fid,string savepath,string responsemsg) {

        // you can process saved pdf document here, like add watermark, ...
        var documentPath = savepath;
        RasterEdge.Imaging.Basic.BaseDocument document = null;
        if (!string.IsNullOrEmpty(documentPath))
        {
            Logger.LogFile(fid, "SaveFileOnServer: output file path " + documentPath, LogType.DEBUG);

            if (documentPath.EndsWith(".pdf"))
            {
                document = new RasterEdge.XDoc.PDF.PDFDocument(documentPath);
            }

            if (document != null)
            {
                RasterEdge.XDoc.PDF.PDFDocument pdfDoc = document as RasterEdge.XDoc.PDF.PDFDocument;

                //  post-process
                String creatorName = "Hello";    //  creator name
                postSaveFileProcess(pdfDoc, creatorName);

                // get the upload information of the file
                RasterEdge.WDP.DocUploadInfo docinfo = RasterEdge.WDP.Manager.FileManager.getUploadinfoByFid(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 EdgePDF";
                pdfDoc.SetDescription(metadata);

                try
                {
                    //pdfDoc.Save(docinfo.LoadPath);
                    //pdfDoc.Save(@"C:\temp\test.pdf");
                    pdfDoc.Save(@"C:\temp\" + paraFilepathValue);
                }
                catch (Exception ex)
                {
                    // process error code, and return error information here
                    Logger.LogFile(fid, ex.Message + ". fail to save file to server.", LogType.ERROR);
                }
            }
            else
            {
                Logger.LogFile(fid, "output PDF file is invalid.", LogType.ERROR);
            }
        }
        else
        {
            Logger.LogFile(fid, "fail to save file to server. output file path is null or empty.", LogType.ERROR);
        }

    }



About document object in method "SaveCallBack"



In file UserCommandProcessHandler.ashx method "SaveCallBack", you can get a PDF document object using


                document = new RasterEdge.XDoc.PDF.PDFDocument(documentPath);



The object "document" here includes all user modifications in web browser. If a user has added new annotations on the opened PDF file, the object includes those new annotations.



Get PDF file open request url parameters' values



During pdf file opening request, you can add url parameters and values. All of these parameters and values have been stored in EdgePDF cached content.

You can get url parameters' values through the following codes:


                string paraFilepathValue = docinfo.GetRequestParameters("yourtarget");