Foxtable(狐表)用户栏目专家坐堂 → [求助]请教老师C#转换的代码怎样使用


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

主题:[求助]请教老师C#转换的代码怎样使用

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


加好友 发短信
等级:五尾狐 帖子:1139 积分:11245 威望:0 精华:0 注册:2017/9/26 16:30:00
[求助]请教老师C#转换的代码怎样使用  发帖心情 Post By:2019/7/6 9:35:00 [只看该作者]

1、参照:https://blog.csdn.net/u011108093/article/details/81916318

        C#使用itextsharp对pdf文件进行分割的几种方法(方法一)


2、将方法一的c#代码转换为VB.net:
Public Sub ExtractPages(ByVal sourcePdfPath As String, ByVal outputPdfPath As String, ByVal startPage As Integer, ByVal endPage As Integer)
    Dim reader As PdfReader = Nothing
    Dim sourceDocument As Document = Nothing
    Dim pdfCopyProvider As PdfCopy = Nothing
    Dim importedPage As PdfImportedPage = Nothing

    Try
        reader = New PdfReader(sourcePdfPath)
        sourceDocument = New Document(reader.GetPageSizeWithRotation(startPage))
        pdfCopyProvider = New PdfCopy(sourceDocument, New System.IO.FileStream(outputPdfPath, System.IO.FileMode.Create))
        sourceDocument.Open()

        For i As Integer = startPage To endPage
            importedPage = pdfCopyProvider.GetImportedPage(reader, i)
            pdfCopyProvider.AddPage(importedPage)
        Next

        sourceDocument.Close()
        reader.Close()
    Catch ex As Exception
        Throw ex
    End Try
End Sub

3、如果要打开的PDF文件路径:d:\ABC.pdf
    打开的页面:5-7页
    写入的新文件是:d:\123.pdf

    上面的代码应该怎样修改使用?
    谢谢!

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


加好友 发短信
等级:超级版主 帖子:107440 积分:546479 威望:0 精华:9 注册:2015/6/24 9:21:00
  发帖心情 Post By:2019/7/6 9:59:00 [只看该作者]

1、2、把ExtractPages函数放到全局代码,引用的类型补全完整的命名空间

如:Dim reader As PdfReader = Nothing
改为:Dim reader As iTextSharp.text.pdf.PdfReader = Nothing

3、调用
ExtractPages("d:\ABC.pdf","d:\123.pdf",5,7)

 回到顶部