Foxtable(狐表)用户栏目专家坐堂 → [求助]Savetopdf 生成的pdf修改问题


  共有3314人关注过本帖树形打印复制链接

主题:[求助]Savetopdf 生成的pdf修改问题

帅哥哟,离线,有人找我吗?
有点甜
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:版主 帖子:85326 积分:427815 威望:0 精华:5 注册:2012/10/18 22:13:00
  发帖心情 Post By:2018/12/19 9:15:00 [显示全部帖子]

那你就直接用vba存为图片,如

 

Dim App As New MSExcel.Application
try
    Dim Wb As MSExcel.WorkBook = app.WorkBooks.open("d:\test.xls")
    Dim Ws = wb.WorkSheets(1)
    Dim rg As MSExcel.Range = ws.UsedRange
   
    rg.copy
    'app.visible = True
    ClipBoard.GetImage.save("d:\aaa.wmf")
    app.quit
catch ex As exception
    msgbox(ex.message)
    app.quit
End try


 回到顶部
帅哥哟,离线,有人找我吗?
有点甜
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:版主 帖子:85326 积分:427815 威望:0 精华:5 注册:2012/10/18 22:13:00
  发帖心情 Post By:2018/12/20 9:29:00 [显示全部帖子]

修改pdf权限吧,参考代码

 

Dim reader As New iTextSharp.text.pdf.PdfReader("d:\test.pdf")
Dim document As New  iTextSharp.text.Document(reader.GetPageSizeWithRotation(1))
Dim n As Integer = reader.NumberOfPages
Dim baos As New IO.FileStream("d:\test2.pdf", IO.FileMode.Create, IO.FileAccess.Write)
Dim copy As New  iTextSharp.text.pdf.PdfCopy(document, baos)

Dim ownerPassword = Encoding.default.GetBytes("12345")
Dim permissions = iTextSharp.text.pdf.PdfWriter.ALLOW_COPY Or iTextSharp.text.pdf.PdfWriter.ALLOW_MODIFY_CONTENTS Or iTextSharp.text.pdf.PdfWriter.ALLOW_PRINTING
copy.setEncryption(Nothing, ownerPassword, permissions,False)
copy.ViewerPreferences =  iTextSharp.text.pdf.PdfWriter.HideToolbar Or iTextSharp.text.pdf.PdfWriter.HideMenubar Or iTextSharp.text.pdf.PdfWriter.HideWindowUI
'往pdf中写入内容
document.Open()
For i As Integer = 1 To n
    Dim page As  iTextSharp.text.pdf.PdfImportedPage = copy.GetImportedPage(reader, i)
    copy.AddPage(page)
Next
document.Close()
reader.Close()

 

下载信息  [文件大小:1.3 MB  下载次数:5]
图片点击可在新窗口打开查看点击浏览该文件:itextsharp.zip

 

http://www.foxtable.com/bbs/dispbbs.asp?BoardID=2&ID=100045&skin=0

 


 回到顶部
帅哥哟,离线,有人找我吗?
有点甜
  3楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:版主 帖子:85326 积分:427815 威望:0 精华:5 注册:2012/10/18 22:13:00
  发帖心情 Post By:2018/12/20 12:27:00 [显示全部帖子]

 

你去打开123.pdf这个文件测试啊。

 

 


 回到顶部
帅哥哟,离线,有人找我吗?
有点甜
  4楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:版主 帖子:85326 积分:427815 威望:0 精华:5 注册:2012/10/18 22:13:00
  发帖心情 Post By:2018/12/20 15:25:00 [显示全部帖子]

 

1、请截图说明可以怎么编辑?

 

2、除了这些 iTextSharp.text.pdf.PdfWriter.ALLOW_COPY Or iTextSharp.text.pdf.PdfWriter.ALLOW_MODIFY_CONTENTS Or iTextSharp.text.pdf.PdfWriter.ALLOW_PRINTING

还有如下权限,你可以加上看看

 

PdfWriter.ALLOW_ASSEMBLYPdfWriter.ALLOW_FILL_INPdfWriter.ALLOW_MODIFY_ANNOTATIONSPdfWriter.ALLOW_DEGRADED_PRINTINGPdfWriter.ALLOW_SCREENREADERSPdfWriter.DO_NOT_ENCRYPT_METADATA


 回到顶部
帅哥哟,离线,有人找我吗?
有点甜
  5楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:版主 帖子:85326 积分:427815 威望:0 精华:5 注册:2012/10/18 22:13:00
  发帖心情 Post By:2018/12/21 8:53:00 [显示全部帖子]

 

pdf文件发上来(原来的pdf以及生成的新的d:\123.pdf,一起发上)

 

 


 回到顶部
帅哥哟,离线,有人找我吗?
有点甜
  6楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:版主 帖子:85326 积分:427815 威望:0 精华:5 注册:2012/10/18 22:13:00
  发帖心情 Post By:2018/12/21 9:10:00 [显示全部帖子]

试试改成

 

Dim reader As New iTextSharp.text.pdf.PdfReader("c:\test.pdf")
Dim document As New  iTextSharp.text.Document(reader.GetPageSizeWithRotation(1))
Dim n As Integer = reader.NumberOfPages
Dim baos As New IO.FileStream("c:\123.pdf", IO.FileMode.Create, IO.FileAccess.Write)
Dim copy As New  iTextSharp.text.pdf.PdfCopy(document, baos)

Dim ownerPassword = Encoding.default.GetBytes("12345")
copy.setEncryption(Nothing, ownerPassword, iTextSharp.text.pdf.PdfWriter.ALLOW_SCREENREADERS,False)
copy.setEncryption(Nothing, ownerPassword, iTextSharp.text.pdf.PdfWriter.ALLOW_DEGRADED_PRINTING,False)
copy.setEncryption(Nothing, ownerPassword, iTextSharp.text.pdf.PdfWriter.ALLOW_MODIFY_ANNOTATIONS,False)
copy.setEncryption(Nothing, ownerPassword, iTextSharp.text.pdf.PdfWriter.ALLOW_FILL_IN,False)
copy.setEncryption(Nothing, ownerPassword, iTextSharp.text.pdf.PdfWriter.ALLOW_ASSEMBLY,False)
copy.setEncryption(Nothing, ownerPassword, iTextSharp.text.pdf.PdfWriter.ALLOW_COPY,False)
copy.setEncryption(Nothing, ownerPassword, iTextSharp.text.pdf.PdfWriter.ALLOW_MODIFY_CONTENTS,False)
copy.setEncryption(Nothing, ownerPassword, iTextSharp.text.pdf.PdfWriter.ALLOW_PRINTING,False)
copy.ViewerPreferences =  iTextSharp.text.pdf.PdfWriter.HideToolbar Or iTextSharp.text.pdf.PdfWriter.HideMenubar Or iTextSharp.text.pdf.PdfWriter.HideWindowUI
'往pdf中写入内容
document.Open()
For i9 As Integer = 1 To n
    Dim page As  iTextSharp.text.pdf.PdfImportedPage = copy.GetImportedPage(reader, i9)
    copy.AddPage(page)
Next
document.Close()
reader.Close()


 回到顶部
帅哥哟,离线,有人找我吗?
有点甜
  7楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:版主 帖子:85326 积分:427815 威望:0 精华:5 注册:2012/10/18 22:13:00
  发帖心情 Post By:2018/12/21 10:21:00 [显示全部帖子]

执行这段代码后没问题,请认真测试

 

Dim reader As New iTextSharp.text.pdf.PdfReader("c:\test.pdf")
Dim document As New  iTextSharp.text.Document(reader.GetPageSizeWithRotation(1))
Dim n As Integer = reader.NumberOfPages
Dim baos As New IO.FileStream("c:\123.pdf", IO.FileMode.Create, IO.FileAccess.Write)
Dim copy As New  iTextSharp.text.pdf.PdfCopy(document, baos)

Dim ownerPassword = Encoding.default.GetBytes("12345")
copy.setEncryption(Nothing, ownerPassword, iTextSharp.text.pdf.PdfWriter.ALLOW_SCREENREADERS,False)
copy.setEncryption(Nothing, ownerPassword, iTextSharp.text.pdf.PdfWriter.ALLOW_DEGRADED_PRINTING,False)
copy.setEncryption(Nothing, ownerPassword, iTextSharp.text.pdf.PdfWriter.ALLOW_MODIFY_ANNOTATIONS,False)
copy.setEncryption(Nothing, ownerPassword, iTextSharp.text.pdf.PdfWriter.ALLOW_FILL_IN,False)
copy.setEncryption(Nothing, ownerPassword, iTextSharp.text.pdf.PdfWriter.ALLOW_ASSEMBLY,False)
copy.setEncryption(Nothing, ownerPassword, iTextSharp.text.pdf.PdfWriter.ALLOW_COPY,False)
copy.setEncryption(Nothing, ownerPassword, iTextSharp.text.pdf.PdfWriter.ALLOW_MODIFY_CONTENTS,False)
copy.setEncryption(Nothing, ownerPassword, iTextSharp.text.pdf.PdfWriter.ALLOW_PRINTING,False)
copy.ViewerPreferences =  iTextSharp.text.pdf.PdfWriter.HideToolbar Or iTextSharp.text.pdf.PdfWriter.HideMenubar Or iTextSharp.text.pdf.PdfWriter.HideWindowUI
'往pdf中写入内容
document.Open()
For i9 As Integer = 1 To n
    Dim page As  iTextSharp.text.pdf.PdfImportedPage = copy.GetImportedPage(reader, i9)
    copy.AddPage(page)
Next
document.Close()
reader.Close()


 回到顶部