(转载自狐表论坛:http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&id=142361&authorid=0&page=0&star=1)
生成PDF的时候,可以添加管理员密码和用户密码,这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生成文件



