使用Docotic.pdf库合并pdf

使用Docotic.pdf库合并pdf,pdf,Pdf,我已经有一个这样做的类,但我希望您使用Docotic.Pdf库完成一个新类的编程。他们的网站供您参考: 这是我写的代码 `Public Class Form1 Private Sub butMergePdfs_Click(sender As System.Object, e As System.EventArgs) Handles butMergePdfs.Click ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

我已经有一个这样做的类,但我希望您使用Docotic.Pdf库完成一个新类的编程。他们的网站供您参考:

这是我写的代码

`Public Class Form1

Private Sub butMergePdfs_Click(sender As System.Object, e As System.EventArgs) Handles butMergePdfs.Click

    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    'Load some sample PDF files into the string arrays
    'In production it will read the files into the string arrays
    'from a database.
    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    Dim strMergeFiles(3) As String
    Dim strMergeTitles(3) As String
    strMergeFiles(0) = "D:\Nayeem_Mansoori\Cis_Projects\Cis_Projects\SanjayVerma\PdfMergeTest\PDF_1.pdf"
    strMergeFiles(1) = "D:\Nayeem_Mansoori\Cis_Projects\Cis_Projects\SanjayVerma\PdfMergeTest\PDF_2.pdf"
    strMergeFiles(2) = "D:\Nayeem_Mansoori\Cis_Projects\Cis_Projects\SanjayVerma\PdfMergeTest\PDF_3.pdf"
    'strMergeFiles(0) = "C:\Temp\PDF_1.pdf"
    'strMergeFiles(1) = "C:\Temp\PDF_2.pdf"
    'strMergeFiles(2) = "C:\Temp\PDF_3.pdf"
    strMergeTitles(0) = "OUTLINE_1"
    strMergeTitles(1) = "OUTLINE_2"
    strMergeTitles(2) = "OUTLINE_3"
        ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
        'This shows how the old class worked. The new class needs to work
        'with exactly the same parameters.
        ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
       'Dim myMerge As New clsMerge_OLD
       'Dim strFileName As String = System.IO.Path.GetRandomFileName & ".pdf"
       'Dim strOutputFileAndPath As String = "C:\temp\" & strFileName
        Dim myMerge As New clsMerge_NEW
        Dim strFileName As String = System.IO.Path.GetRandomFileName & ".pdf"
        Dim strOutputFileAndPath As String = "C:\temp\" & strFileName
        'Merge the files.
        myMerge.MergeFiles(strMergeFiles, strMergeTitles, strOutputFileAndPath)
        'Shop any merge errors.
        If myMerge.Errors <> "" Then
            MsgBox(myMerge.Errors)
        End If
        'Open the merged PDF
        Process.Start(strOutputFileAndPath)
        myMerge = Nothing
    End Sub
    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs)
        MsgBox(System.IO.Directory.GetCurrentDirectory())
    End Sub
End Class
    Imports BitMiracle.Docotic.Pdf

Public Class clsMerge_NEW

    Private mstrErrors As String
    Private mboolCurrentFileIsIrefStream As Boolean
    Private mboolPadPageCountToEven As Boolean
    Private mRand As Random

    Public ReadOnly Property Errors() As String
        Get
            Return mstrErrors
        End Get
    End Property
    Public Sub New()
        mstrErrors = ""
    End Sub
    Public Function MergeFiles(ByVal SourceFiles() As String _
                                , ByVal SourceTitles() As String _
                                , ByVal DestinationFile As String) As Boolean

        Dim boolReturnVal As Boolean = True

        'clear error variable
        mstrErrors = ""

        'If the destination merged PDF file exists, then delete it. 
        Try
            If System.IO.File.Exists(DestinationFile) = True Then
                System.IO.File.Delete(DestinationFile)
            End If
        Catch ex As Exception
            mstrErrors = mstrErrors & " Cannot delete destination file:" & DestinationFile & ". Error is: " & ex.Message & vbCrLf
            boolReturnVal = False
        End Try

        If boolReturnVal = True Then 'if still true then continue!

            'Iterate the string array.
            For i As Int32 = 0 To UBound(SourceFiles) - 1

                '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
                '
                '
                ' !!!!   FINISH THIS CODE    - MERGE THE PDF's       !!!!!!!
                '
                '
                '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''





                '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
                'Ensure OUTLINES are created in the destination PDF file!!!!!
                'The TITLES passed in SourceTitles are the OUTLINES. 
                '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

            Next

        End If

        Return boolReturnVal

    End Function



    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    '
    '
    ' Here is a C# example of how to use the class.
    '
    '-------------------------------------------------------------------------------
    '
    '                using (PdfDocument pdf = new PdfDocument())
    '            {
    '                pdf.PageMode = PdfPageMode.UseOutlines;
    '                pdf.Append("d:\\0000-2981A.pdf");
    '
    '                pdf.Append("d:\\0000-2981B.pdf");
    '                pdf.RemovePage(0);
    '
    '
    '                PdfOutlineItem root = pdf.OutlineRoot;
    '
    '                for (int i = 0; i < pdf.PageCount; ++i)
    '                {
    '                    int pgcount = i + 1;
    '                    PdfOutlineItem outlineForPage = root.AddChild("Page " + pgcount.ToString(), i);
    '                }
    '
    '                pdf.Save(pathToFile);
    '            }




End Class
`公共类表单1
私有子butMergePdfs\u Click(发送者作为System.Object,e作为System.EventArgs)处理butMergePdfs。单击
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'将一些示例PDF文件加载到字符串数组中
'在生产中,它会将文件读入字符串数组
'从数据库中。
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
将strmerge文件(3)设置为字符串
作为字符串的Dim STRMERGETILES(3)
strMergeFiles(0)=“D:\nayem\u Mansoori\Cis\u Projects\Cis\u Projects\SanjayVerma\PdfMergeTest\PDF\u 1.PDF”
strMergeFiles(1)=“D:\nayem\u Mansoori\Cis\u Projects\Cis\u Projects\SanjayVerma\PdfMergeTest\PDF\u 2.PDF”
strMergeFiles(2)=“D:\Nayeem\u Mansoori\Cis\u Projects\Cis\u Projects\SanjayVerma\PdfMergeTest\PDF\u 3.PDF”
'strMergeFiles(0)=“C:\Temp\PDF\u 1.PDF”
'strMergeFiles(1)=“C:\Temp\PDF\u 2.PDF”
'strMergeFiles(2)=“C:\Temp\PDF\u 3.PDF”
strTargetLes(0)=“大纲图1”
strTargetLes(1)=“大纲2”
strTargetLes(2)=“大纲3”
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
"这说明旧阶级是如何运作的。新班级需要工作
“使用完全相同的参数。
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
“将我的合并变为新的合并”
'Dim strFileName As String=System.IO.Path.GetRandomFileName&'.pdf'
'Dim strOutputFileAndPath As String=“C:\temp\”&strFileName
将myMerge变暗为新clsMerge_New
Dim strFileName为String=System.IO.Path.GetRandomFileName&“.pdf”
Dim strOutputFileAndPath为String=“C:\temp\”&strFileName
'合并文件。
myMerge.MergeFiles(strMergeFiles、strMergeTitles、strOutputFileAndPath)
'查找任何合并错误。
如果myMerge.Errors为“”,则
MsgBox(myMerge.Errors)
如果结束
'打开合并的PDF
Process.Start(strOutputFileAndPath)
myMerge=无
端接头
私有子按钮1\u单击(发件人作为System.Object,e作为System.EventArgs)
MsgBox(System.IO.Directory.GetCurrentDirectory())
端接头
末级
导入BitMiracle.Docotic.Pdf
公共类clsMerge_新
私有mstrErrors作为字符串
作为布尔值的私有MBoolCurrentFileIsRefStream
私有MBoolPadPageCountToEvent为布尔值
私有mRand是随机的
作为字符串的公共只读属性错误()
收到
返回mstrErrors
结束
端属性
公共分新()
mstrErrors=“”
端接头
公共函数MergeFiles(ByVal SourceFiles()作为字符串_
,ByVal SourceTitles()作为字符串_
,ByVal DestinationFile作为字符串)作为布尔值
Dim boolReturnVal为布尔值=真
'清除错误变量
mstrErrors=“”
'如果目标合并PDF文件存在,则将其删除。
尝试
如果System.IO.File.Exists(DestinationFile)=True,则
System.IO.File.Delete(DestinationFile)
如果结束
特例
mstrErrors=mstrErrors&“无法删除目标文件:&DestinationFile&”。错误为:&ex.Message&vbCrLf
boolReturnVal=False
结束尝试
如果boolReturnVal=True,则“如果仍然为True,则继续!”!
'迭代字符串数组。
对于i As Int32=0到UBound(SourceFiles)-1
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'
'
' !!!!   完成此代码-合并PDF的!!!!!!!
'
'
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'确保在目标PDF文件中创建轮廓!!!!!
'在SourceTitles中传递的标题是大纲。
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
下一个
如果结束
返回布尔返回值
端函数
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'
'
“下面是一个C#示例,说明如何使用该类。
'
'-------------------------------------------------------------------------------
'
'使用(PdfDocument pdf=new PdfDocument())
'            {
'pdf.PageMode=PdfPageMode.UseOutlines;
'pdf.Append(“d:\\0000-2981A.pdf”);
'
'pdf.Append(“d:\\0000-2981B.pdf”);
'pdf.RemovePage(0);
'
'
'PdfOutlineItem root=pdf.OutlineRoot;
'
'用于(int i=0;i

请任何人帮我。

你的问题可以更具体一些。我不确定我是否理解正确,但请尝试以下示例代码

示例代码将不同的文档合并到一个PDF文件中,并创建书签。每个书签指向原始文档的第一页。书签标题作为函数的参数提供

请注意,代码是从C#自动转换而来的

以下是C#版本供参考:

public static void MergeFiles(string[] sourceFiles, string[] bookmarkTitles, string destination)
{
    using (PdfDocument pdf = new PdfDocument())
    {
        int targetPageIndex = 0;
        for (int i = 0; i < sourceFiles.Length; i++)
        {
            string currentName = sourceFiles[i];

            if (i == 0)
                pdf.Open(currentName);
            else
                pdf.Append(currentName);

            pdf.OutlineRoot.AddChild(bookmarkTitles[i], targetPageIndex);
            targetPageIndex = pdf.PageCount;
        }

        pdf.PageMode = PdfPageMode.UseOutlines;
        pdf.Save(destination);
    }
}
公共静态void合并文件(字符串[]源文件、字符串[]书签标题、字符串目标)
{
我们
public static void MergeFiles(string[] sourceFiles, string[] bookmarkTitles, string destination)
{
    using (PdfDocument pdf = new PdfDocument())
    {
        int targetPageIndex = 0;
        for (int i = 0; i < sourceFiles.Length; i++)
        {
            string currentName = sourceFiles[i];

            if (i == 0)
                pdf.Open(currentName);
            else
                pdf.Append(currentName);

            pdf.OutlineRoot.AddChild(bookmarkTitles[i], targetPageIndex);
            targetPageIndex = pdf.PageCount;
        }

        pdf.PageMode = PdfPageMode.UseOutlines;
        pdf.Save(destination);
    }
}