In This Topic

Demonstration of features usage

In This Topic

In these educational videos, we would like to demonstrate how DocuVieware can help you integrate important features of the document management into your business workflows.

 PDF document viewing with content protection

The demo covers various technologies related to document content protection for online applications. We will review methods with a focus on content protection when viewing documents. The video includes practical examples implemented with the help of DocuVieware SDK, a fully featured HTML5 viewing and document management solution.

Watch the video here!

Here are the code snippets added to the project for individual steps to implement demonstrated features. Be aware that they are only provided for educatiol purposes, so you will probably need to adapt them to get it fully work in your application.

Copy Code
EnablePrintButton = false,
EnableSaveButton = false,
AllowPrint = false,
EnableTextSelection = false
Copy Code
GdPicturePDF pdf = new GdPicturePDF();
pdf.LoadFromFile("document.pdf", false);
pdf.SetMeasurementUnit(PdfMeasurementUnit.PdfMeasurementUnitInch);
pdf.SetOrigin(PdfOrigin.PdfOriginTopLeft);
pdf.SetFillColor(153, 50, 204);
Copy Code
AnnotationManager manager = new AnnotationManager();
manager.InitFromGdPicturePDF(pdf);

//Adding copyright text.
AnnotationText annot = manager.AddTextAnnot(5, 5, 15, 5, "copyright ORPALIS");
annot.ForeColor = System.Drawing.Color.Red;
annot.Rotation = 45;
annot.FontSize = 80;
annot.Opacity = 0.2F;
manager.BurnAnnotationsToPage(false);

//Adding a watermark.
GdPictureImaging image = new GdPictureImaging();
int imageID = image.CreateGdPictureImageFromFile("watermark.png");
image.SetTransparency(imageID, -200);
string imageName = pdf.AddImageFromGdPictureImage(imageID, false, false);
pdf.DrawImage(imageName, 0, pdf.GetPageHeight(), pdf.GetPageWidth(), pdf.GetPageHeight());
Copy Code
for (int i = 1; i <= pdf.GetPageCount(); i++)
{
    pdf.SelectPage(i);
    float left = 0, top = 0, width = 0, height = 0;
    if (pdf.SearchText("viewing", count, false, true, ref left, ref top, ref width, ref height) == true)
    {
        pdf.DrawRectangle(left, top, width, height, true, true);
        count++;
    }
}
Copy Code
for (int i = pdf.GetPageCount(); i > 0 ; i--)
{
    pdf.SelectPage(i);
    float left = 0, top = 0, width = 0, height = 0;
    if (pdf.SearchText("viewing", 1, false, true, ref left, ref top, ref width, ref height) == true)
    {
        pdf.DeletePage(i);
    }
}
 PDF Encryption Practices

The demo reviews encryption practices for PDF files processed online. The purpose of this video is to illustrate several document content protection methods for PDF files. Thanks to the DocuVieware SDK these practices can be integrated easily into any web-based application.

Watch the video here!

Here are the code snippets added to the project for individual steps to implement demonstrated features. Be aware that they are only provided for educatiol purposes, so you will probably need to adapt them to get it fully work in your application.

Copy Code
using (HtmlGenericControl icon = new HtmlGenericControl("svg"))
{
    icon.Attributes["viewBox"] = "0 0 16 16";
    icon.Attributes["width"] = "100%";
    icon.Attributes["height"] = "100%";
    icon.InnerHtml = "<path d=\"M6 0l-6 8h6l-4 8 14-10h-8l6-6z\"></path>";
    using (HtmlGenericControl panel = new HtmlGenericControl("div"))
    {
        panel.ClientIDMode = ClientIDMode.Static;
        panel.ID = "customSnapInTutorialPanel" + docuVieware.UniqueID;
        using (HtmlGenericControl customSnapInTutorialButtonDiv = new HtmlGenericControl("div"))
        {
            customSnapInTutorialButtonDiv.Style["float"] = "left";
            customSnapInTutorialButtonDiv.Style["margin-top"] = "6px";
            customSnapInTutorialButtonDiv.Style["margin-left"] = "6px";
            using (HtmlGenericControl labelForOwner = new HtmlGenericControl("label"))
            {
                labelForOwner.InnerText = "Owner Password";
                customSnapInTutorialButtonDiv.Controls.Add(labelForOwner);
            }
            using (HtmlGenericControl customSnapInInput = new HtmlGenericControl("input"))
            {
                customSnapInInput.ID = "customSnapInputOwner";
                customSnapInTutorialButtonDiv.Controls.Add(customSnapInInput);
                customSnapInInput.Style["margin-bottom"] = "10px";
            }
            using (HtmlGenericControl br = new HtmlGenericControl("br"))
            {
                customSnapInTutorialButtonDiv.Controls.Add(br);
            }
            using (HtmlGenericControl labelForUser = new HtmlGenericControl("label"))
            {
                labelForUser.InnerText = "User Password";
                customSnapInTutorialButtonDiv.Controls.Add(labelForUser);
            }
            using (HtmlGenericControl customSnapInInputU = new HtmlGenericControl("input"))
            {
                customSnapInInputU.ID = "customSnapInputUser";
                customSnapInTutorialButtonDiv.Controls.Add(customSnapInInputU);
                customSnapInInputU.Style["margin-bottom"] = "10px";
            }
            using (HtmlGenericControl br = new HtmlGenericControl("br"))
            {
                customSnapInTutorialButtonDiv.Controls.Add(br);
            }
            using (HtmlGenericControl labelForP = new HtmlGenericControl("label"))
            {
                labelForP.InnerText = "Can print";
                customSnapInTutorialButtonDiv.Controls.Add(labelForP);
            }
            using (HtmlInputCheckBox cbxPrint = new HtmlInputCheckBox())
            {
                cbxPrint.ID = "canPrint";
                customSnapInTutorialButtonDiv.Controls.Add(cbxPrint);
            }
            using (HtmlGenericControl labelForC = new HtmlGenericControl("label"))
            {
                labelForC.InnerText = "Can copy";
                customSnapInTutorialButtonDiv.Controls.Add(labelForC);
            }
            using (HtmlInputCheckBox cbxPrint = new HtmlInputCheckBox())
            {
                cbxPrint.ID = "canCopy";
                customSnapInTutorialButtonDiv.Controls.Add(cbxPrint);
            }
            using (HtmlGenericControl customSnapInTutorialButton = new HtmlGenericControl("button"))
            {
                customSnapInTutorialButton.ID = "customSnapInSubmit";
                customSnapInTutorialButton.Style["height"] = "26px";
                customSnapInTutorialButton.Style["background-color"] = "#213E4E";
                customSnapInTutorialButton.InnerHtml = "Encrypt PDF";
                customSnapInTutorialButton.Attributes["class"] = "btn-valid";
                customSnapInTutorialButtonDiv.Controls.Add(customSnapInTutorialButton);
            }
            panel.Controls.Add(customSnapInTutorialButtonDiv);
        }
        docuVieware.AddCustomSnapIn("customSnapInTutorial", "SETTINGS", icon, panel, true);
    }
}
Copy Code
<script>
    //Sending encryption settings server-side.
    $('#customSnapInSubmit').click(function() {
        var owner = $("#customSnapInputOwner").val();
        var user = $("#customSnapInputUser").val();
        var print = $("#canPrint").prop('checked');
        var copy = $("#canCopy").prop('checked');
        var json = {
            OwnerPass: owner,
            UserPass: user,
            CanPrint: print,
            CanCopy: copy,
            //Additional encryption settings.
            CanModify: false,
            CanAssemble: false,
            CanCopyAccess: false,
            CanFillFields: false,
            CanAddNotes: false,
            CanPrintFull: false
        };
        DocuViewareAPI.PostCustomServerAction('DocuVieware1', true, 'Encrypt', json, function (result) { alert(result)}, function () { });
    })
</script>
Copy Code
//Subscribe to delegate
DocuViewareEventsHandler.CustomAction += CustomActionDispatcher;

//JSON deserializer class
class Args
{
    public string OwnerPass { get; set; }
    public string UserPass { get; set; }
    public bool CanPrint { get; set; }
    public bool CanCopy { get; set; }
    public bool CanModify { get; set; }
    public bool CanAssemble { get; set; }
    public bool CanCopyAccess { get; set; }
    public bool CanFillFields { get; set; }
    public bool CanAddNotes { get; set; }
    public bool CanPrintFull { get; set; }
}

private static void CustomActionDispatcher(object sender, CustomActionEventArgs e)
{
    switch (e.actionName)
    {
        //...
        case "Encrypt":
            //Get the currently rendered document (assuming it is a PDF document).
            GdPicturePDF pdf = new GdPicturePDF();
            e.docuVieware.GetNativePDF(out pdf);
            //Apply encryption settings.
            Args oArgs1 = JsonConvert.DeserializeObject<Args>(e.args.ToString());
            GdPictureStatus status = pdf.SaveToFile(HttpContext.Current.Server.MapPath("test_encrypted.pdf"), PdfEncryption.PdfEncryption256BitAES,
                                                    oArgs1.UserPass, oArgs1.OwnerPass,
                                                    oArgs1.CanPrint, oArgs1.CanCopy,
                                                    oArgs1.CanModify, oArgs1.CanAddNotes,
                                                    oArgs1.CanFillFields, oArgs1.CanCopyAccess,
                                                    oArgs1.CanAssemble, oArgs1.CanPrintFull);
            e.message = new DocuViewareMessage("Operation status : " + status.ToString());
            e.result = status.ToString();
            break;
    }
}
 AJAX Control DocuVieware HTML5 Viewer

On the contrary to conventional web applications that communicate to a server using static requests, AJAX allows dynamic content display without having to refresh the page. This educational video demonstrate the integration and the usage of AJAX Control with DocuVieware.

Watch the video here.