How to prevent copy paste of text in a generated RadPDF File after it is downloaded by a user?

8 posts, 0 answers
  1. darren
    darren avatar
    3 posts
    Member since:
    Aug 2020

    Posted 26 Nov 2020 Link to this post

    Hi,

    I am asking a question regarding the processing of PDF. I am generating a PDF using RadFixedDocument through asp.net mvc. I want to prevent users from copying my contents in PDF. I have added in watermark on my document but users are still able to copy and paste text in the pdf to a text document. I tried to look for related materials in the listed Telerik resources but to no avail.

    https://demos.telerik.com/aspnet-mvc/pdfprocessing
    https://docs.telerik.com/devtools/document-processing/libraries/radpdfprocessing/overview

    How am I able to prevent users who download my PDF from copy pasting the content inside the pdf to another document? 

    Thanks in advance.

  2. Martin
    Admin
    Martin avatar
    140 posts

    Posted 27 Nov 2020 Link to this post

    Hi Darren,

    With the current version of the PdfProcessing library, the option I can suggest is to export the document pages as images and to keep the original document on your side in order to not lose all the document data. For more information and examples you can check the Export RadFixedPage to image knowledge base article.

    According to the PDF specification, there is a functionality named Owner passwords that handles such kinds of permissions on export but it is currently not supported by the PdfProcessing library. We have an item logged to provide such functionality: PdfProcessing: Provide API for setting different permissions when exporting encrypted PDF document. You can cast your vote for the implementation as well as subscribe to the task by clicking the Follow button, so you can receive updates when its status changes.

    Regards,
    Martin
    Progress Telerik

    Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

  3. darren
    darren avatar
    3 posts
    Member since:
    Aug 2020

    Posted 27 Nov 2020 in reply to Martin Link to this post

    Hi Martin, Thanks for the response and example given. May I know based on your the first example which you recommended. I am having difficulty interpreting the code shared in the example you have shared. Is there any sample code which I can follow to convert each page in the document and be able to send it back as a File result from the controller method that I have written below?

     

         [HttpGet]
            public virtual ActionResult DownloadPDF()
            {
                try
                {

                    PdfFormatProvider formatProvider = new PdfFormatProvider();

                    byte[] renderedBytes = null;
                    using (MemoryStream ms = new MemoryStream())
                    {
                        RadFixedDocument document = new RadFixedDocument();
                        RadFixedDocumentEditor editor = new RadFixedDocumentEditor(document);

                        Table table = new Table();
                        Border border = new Border();
                        table.DefaultCellProperties.Borders = new TableCellBorders(border, border, border, border);
                        table.DefaultCellProperties.Padding = new Thickness(2);

                        // Testing purposes for 1000 data
                        //for (int i = 1; i <= 10000; i++)
                        //{
                        //    TableRow currentRow = table.Rows.AddTableRow();
                        //    AddCellToRow(currentRow, $"testtesttest{i}");
                        //    AddCellToRow(currentRow, $"testtesttest{i}");
                        //    AddCellToRow(currentRow, $"testtesttest{i}");
                        //    AddCellToRow(currentRow, $"testtesttest{i}");
                        //    AddCellToRow(currentRow, $"testtesttest{i}");

                        //}

                        table.LayoutType = Telerik.Windows.Documents.Fixed.Model.Editing.Flow.TableLayoutType.FixedWidth;
                        editor.InsertTable(table);

                        int pageCount = 0;
                        int totalPageCount = document.Pages.Count();

                        foreach (RadFixedPage page in document.Pages)
                        {
                            pageCount++;
                            string currentPage = pageCount + " of " + totalPageCount;
                            AddWatermarkText(page, watermarkText, 100, currentPage);
                        }

                        PdfExportSettings settings = new PdfExportSettings();

                        settings.IsEncrypted = true;
                        settings.UserPassword = "abcd12345678";
                        settings.ImageQuality = ImageQuality.Medium;

                        formatProvider.ExportSettings = settings;

                        formatProvider.Export(document, ms);

                        renderedBytes = ms.ToArray();

                    }

                   return File(renderedBytes, "application/pdf", fileName);

                }
                catch (Exception ex)
                {
                    LogAdaptor.Error(ex);
                    throw ex;
                }
            }

  4. Martin
    Admin
    Martin avatar
    140 posts

    Posted 30 Nov 2020 Link to this post

    Hi Darren,

    After created (or imported the desired document) you can create a new RadFixedDocument, iterate the original document's pages, convert them as images using the ThumbnailFactory (check Exporting Fixed Page to Image help topic), and add the images as new page content. Check the following code snippet:

    RadFixedDocument originalDocument = OpenOrCreateRadFixedDocument();
    
    RadFixedDocument newDocument = new RadFixedDocument();
    
    ThumbnailFactory factory = new ThumbnailFactory();
    
    PageCollection originalPages = originalDocument.Pages;
    foreach (RadFixedPage originalPage in originalPages)
    {
    	Image image = new Image();
    
    	ImageSource imageSource = factory.CreateThumbnail(originalPage, originalPage.Size);
    	image.Source = imageSource;
    
    	Grid container = new Grid();
    	container.Background = Brushes.White;
    	container.Children.Add(image);
    	container.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
    	container.Arrange(new Rect(new Point(0, 0), container.DesiredSize));
    
    	RenderTargetBitmap bitmap =
    		new RenderTargetBitmap((int)PageLayoutHelper.GetActualWidth(originalPage), (int)PageLayoutHelper.GetActualHeight(originalPage), 96, 96, PixelFormats.Pbgra32);
    	bitmap.Render(container);
    
    	RadFixedPage newPage = new RadFixedPage();
    	newPage.Content.AddImage(new Telerik.Windows.Documents.Fixed.Model.Resources.ImageSource(bitmap));
    	newDocument.Pages.Add(newPage);
    }
    
    ExportDocument(newDocument);

    So, in your scenario, you can execute this code snipped before the export of the document:

    ...
    // ExpecuteCodeSnippet
    
    formatProvider.Export(newDocument, ms);
    ...

    In order to demonstrate what exactly I am testing, I am attaching a sample console application.

    Regards,
    Martin
    Progress Telerik

    Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

  5. estanislao
    estanislao avatar
    2 posts
    Member since:
    Nov 2020

    Posted 30 Nov 2020 Link to this post

    Hi Martin,

    ThumbnailFactory is under what category here. I cannot find it in the assembly using my license. I attached the screenshot. Thanks.

     

     

     

     

  6. Martin
    Admin
    Martin avatar
    140 posts

    Posted 01 Dec 2020 Link to this post

    Hello Estanislao,

    The ThumbnailFactory class is part of the Telerik.Windows.Controls.FixedDocumentViewers assembly which in turn is part of the RadPdfViewer control form the UI for WPF suite.

    I saw you have a DevCraft Complete license, so you can download it from your Telerik account by selecting Progress Telerik UI for WPF product title:

    And you can find the binary file in this archive:

    Regards,
    Martin
    Progress Telerik

    Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

  7. estanislao
    estanislao avatar
    2 posts
    Member since:
    Nov 2020

    Posted 03 Dec 2020 in reply to Martin Link to this post

    Hi,

    Can you tell us what dll or namespace under theses object:

    Image image = new Image();

    Grid container = new Grid();

     

    Thanks!

  8. Martin
    Admin
    Martin avatar
    140 posts

    Posted 03 Dec 2020 Link to this post

    Hello Estanislao,

    Both classes (Image and Grid) are part of the System.Windows.Controls namespace from the PresentationFramework assembly:

    System.Windows.Controls.Image = new System.Windows.Controls.Image();
    
    System.Windows.Controls.Grid container = new System.Windows.Controls.Grid();

    Regards,
    Martin
    Progress Telerik

    Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Back to Top