PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Thu Mar 28, 2024 6:44 pm

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: Sat Nov 20, 2021 4:53 am 
Offline

Joined: Sat Nov 20, 2021 4:34 am
Posts: 3
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


Top
 Profile  
Reply with quote  
PostPosted: Mon Nov 22, 2021 8:44 am 
Offline
PDFsharp Expert
User avatar

Joined: Sat Mar 14, 2015 10:15 am
Posts: 909
Location: CCAA
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.

_________________
Best regards
Thomas
(Freelance Software Developer with several years of MigraDoc/PDFsharp experience)


Top
 Profile  
Reply with quote  
PostPosted: Mon Nov 22, 2021 11:40 am 
Offline

Joined: Sat Nov 20, 2021 4:34 am
Posts: 3
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


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC


Who is online

Users browsing this forum: Bing [Bot] and 137 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Privacy Policy, Data Protection Declaration, Impressum
Powered by phpBB® Forum Software © phpBB Group