狐表专业报表生成PDF时如何加密码?防止其他人编辑修改(转载)

发表日期: 2022-10-08

(转载自狐表论坛:http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&id=142361&authorid=0&page=0&star=1

1.简介

生成PDF的时候,可以添加管理员密码用户密码,这2种密码的区别

  1. 管理员密码,可获得读取+编辑权

  2. 常见的用户密码,可获得读取权限


Dim doc As New PrintDoc '定义一个报表
Dim rt As C1.C1Preview.RenderText '定义一个文本对象
Dim rm As C1.C1Preview.RenderEmpty '定一个空对象
For n As Integer = 1 To 50
    rm = New C1.C1Preview.RenderEmpty '定义一个新的空对象
    rm.BreakBefore = C1.C1Preview.BreakEnum.Page '打印前换页
    doc.Body.Children.Add(rm) '加入到报表中
    For i As Integer = 1 To 5
        rt = New C1.C1Preview.RenderText() '创建文本对象
        rt.Text = "Hello Foxtable " & n & "----" & i '设置文本对象的内容
        rt.Width = "Auto" '自动设置宽度
        rt.X = i * 10 + 20 '指定水平位置
        rt.Y = i * 10 + 20 '指定垂直位置
        rt.Style.Borders.All = New C1.C1Preview.LineDef(1, Color.Red) '设置边框
        doc.Body.Children.Add(rt) '将文本对象加入到报表
    Next
Next
'以上替换成你自己的报表

'开始加入密码来生成PDF
Try 
    If (doc.Generate()) Then
        Dim fl As String = "c:\data\test.pdf" '文件的位置
        Dim pdfExp As New C1.C1Preview.Export.PdfExporter
        pdfExp.ShowOptions = False '是否跳出保存对话框
        pdfExp.Security.AllowCopyContent = False '是否可以复制
        pdfExp.Security.AllowEditAnnotations = False '是否可以编辑批注
        pdfExp.Security.AllowEditContent = False '是否可以编辑内容
        pdfExp.Security.AllowPrint = False '是否可以打印
        pdfExp.Security.Encryption = C1.C1Preview.Export.PdfSecurity.EncryptionType.AES_128 '加密格式
        pdfExp.Security.OwnerPassword = "123" '管理员密码,可获得读取+编辑权限
        pdfExp.Security.UserPassword = "456" '常见的用户密码,可获得读取权限
        pdfExp.Document = Doc
        pdfExp.Export(fl)
        MessageBox.Show("生成成功")
        '打开文件夹查看结果
        Dim Proc As New Process
        Proc.File = "c:\data\" 
        Proc.Start()
    End If
Catch ex As Exception
    MessageBox.Show(ex.Message)
Finally
    doc.Dispose()
End Try


生成文件

image.png


2.密码效果

2.1用户密码效果

image.png



2.2管理员密码效果

image.png

image.png



随便看看
商务联系QQ : 2385350359

Copyright 2016-2023 江门蓬江区华越科技公司 版权所有 | 承接软件定制开发,欢迎联系
粤ICP备19148806号-5