I did some more searching and found some code on this forum that seems to partially work. Here is the code I have now.
Code:
' Create a PDF document, not a MigraDoc document
Dim document As PdfDocument = New PdfDocument()
document.Info.Title = "ECF Manual Denial Letter"
document.Info.Author = "Randy Johnson"
document.Info.Subject = "Creating denial letter for expired form submission"
'LetterPage1(document, Data)
LetterPage1(document)
LetterPage2(document)
Dim newLetter As MemoryStream = New MemoryStream()
document.Save(newLetter, False)
'Dim ltrSrc As Byte() = newLetter.ToArray()
Dim ltrForm As PdfDocument = PdfReader.Open(newLetter, PdfDocumentOpenMode.Import)
Dim formSrc As Byte() = My.Resources.pslf_ecf
Dim pdfStream As MemoryStream = New MemoryStream(formSrc)
Dim newForm As PdfDocument = PdfReader.Open(pdfStream, PdfDocumentOpenMode.Import)
Dim outputDocument As PdfDocument = New PdfDocument()
outputDocument.PageLayout = PdfPageLayout.SinglePage
Dim pages As Integer = Math.Max(document.PageCount, newForm.PageCount)
For idx As Integer = 0 To pages - 1
Dim page1 As PdfPage = If(ltrForm.PageCount > idx, document.Pages(idx), New PdfPage())
Dim page2 As PdfPage = If(ltrForm.PageCount > idx, document.Pages(idx), New PdfPage())
Dim page3 As PdfPage = If(newForm.PageCount > idx, newForm.Pages(idx), New PdfPage())
Dim page4 As PdfPage = If(newForm.PageCount > idx, newForm.Pages(idx), New PdfPage())
Dim page5 As PdfPage = If(newForm.PageCount > idx, newForm.Pages(idx), New PdfPage())
Dim page6 As PdfPage = If(newForm.PageCount > idx, newForm.Pages(idx), New PdfPage())
Dim page7 As PdfPage = If(newForm.PageCount > idx, newForm.Pages(idx), New PdfPage())
Dim page8 As PdfPage = If(newForm.PageCount > idx, newForm.Pages(idx), New PdfPage())
:evil: :shock: :mrgreen: page1 = outputDocument.AddPage(page1)
page2 = outputDocument.AddPage(page2)
page3 = outputDocument.AddPage(page3)
page4 = outputDocument.AddPage(page4)
page5 = outputDocument.AddPage(page5)
page6 = outputDocument.AddPage(page6)
page7 = outputDocument.AddPage(page7)
page8 = outputDocument.AddPage(page8)
Next
outputDocument.Save(outputFilename)
Process.Start(outputFilename)
Everything works up until the line of code with the emoticons, when I try to add the newly created pages to the outputDocument. I get an Exception that a "A PDF document must be opened with PdfDocumentOpenMode.Import to import pages from it."
I based this code on the samples in the source code and it is reflected in these lines:
Code:
Dim newLetter As MemoryStream = New MemoryStream()
document.Save(newLetter, False)
'Dim ltrSrc As Byte() = newLetter.ToArray()
Dim ltrForm As PdfDocument = PdfReader.Open(newLetter, PdfDocumentOpenMode.Import)
Dim formSrc As Byte() = My.Resources.pslf_ecf
Dim pdfStream As MemoryStream = New MemoryStream(formSrc)
Dim newForm As PdfDocument = PdfReader.Open(pdfStream, PdfDocumentOpenMode.Import)
It appears to me that both documents are opened in Import mode. I do not understand the reason for the Exception.