PDFsharp & MigraDoc Foundation
https://forum.pdfsharp.net/

Adding a pdf to an existing pdf
https://forum.pdfsharp.net/viewtopic.php?f=2&t=4298
Page 1 of 1

Author:  bhendo54@gmail.com [ Sat Nov 20, 2021 4:53 am ]
Post subject:  Adding a pdf to an existing pdf

My project requires that I create a single pdf and save it in a directory. Then add that pdf to another pdf in a separate directory.
Code:
        Private Sub AddInvoiceToDaily(SingleFile As String, CombinedFile As String)
        Dim doc1 As PdfDocument = PdfReader.Open(SingleFile, PdfDocumentOpenMode.Import)
        Dim doc2 As PdfDocument
        Dim page As PdfPage = doc1.Pages(0)
        If Not File.Exists(CombinedFile) Then
            doc2 = doc1
        Else
            doc2 = PdfReader.Open(CombinedFile, PdfDocumentOpenMode.Import)
            doc2.AddPage(page)
        End If
        doc2.Save(CombinedFile)
    End Sub


Regardless of whether the file exists I get this error message: "The document cannot be modified." at "Doc2.save(CombinedFile).
Any help would be greatly appreciated.
Brad

Author:  TH-Soft [ Mon Nov 22, 2021 8:44 am ]
Post subject:  Re: Adding a pdf to an existing pdf

bhendo54@gmail.com wrote:
Regardless of whether the file exists I get this error message: "The document cannot be modified." at "Doc2.save(CombinedFile).
When the file already exists and is opened in Import mode, then it cannot be modified.
This error should not occur if it does not exist.

Author:  bhendo54@gmail.com [ Mon Nov 22, 2021 11:40 am ]
Post subject:  Re: Adding a pdf to an existing pdf

Thanks Thomas
I created a third document for the output or the two imports and saved that as the combined file
And it works your help is much appreciated
Brad

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/