EdgePDF
Features
Tech Specs
How-to C#
Pricing

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



To run the following demo code, please do the following steps:


  1. Create and add the follow sample documents to folder "c:\temp\"
    • pdf-1.pdf
    • tiff-1.tif
    • word-1.docx
    • excel-1.xlsx
    • powerpoint-1.pptx
    • jpeg-1.jpg
    • text-1.txt
  2. Make sure IIS application (User: IIS_IUSRS) has the read and write rights to the folder "temp“, and all files inside.

The following guide will help to setup a demo project, which allows you to open a file (pdf, word, excel, powerpoint, tiff, jpeg, text) located under your server file system "C:/temp/", through url:
http://localhost:9090/?yourtarget=/1.pdf.

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

Here are the details:


            else if (!string.IsNullOrEmpty(request.QueryString["yourtarget"]))
            {

                // load file from your target
                String docid = request.QueryString["yourtarget"];                
                if (docid == null) docid = "0";
                byte[] dataBytes = System.IO.File.ReadAllBytes(@"C:\\temp\" + docid);
                String fileName = docid;               
                webDoc = REProcessControl.PageLoadFile(request, this.Manager, dataBytes, fileName);

            }

You can use the "yourtarget" value to id and locate your file from file system or database, and load the file into PDFDocument or BaseDocument object.



  • Now you navigate to "http://localhost/?yourtarget={your file location key, such as '/word-1.docx'}" 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 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);
        }

    }