Exception:The given key was not present in the dictionary. StackTrace: at System.Collections.Generic.Dictionary`2.get_Item(TKey key) at PdfSharp.Pdf.Advanced.PdfImportedObjectTable.get_Item(PdfObjectID externalID) at PdfSharp.Pdf.PdfObject.FixUpObject(PdfImportedObjectTable iot, PdfDocument owner, PdfObject value) at PdfSharp.Pdf.PdfObject.FixUpObject(PdfImportedObjectTable iot, PdfDocument owner, PdfObject value) at PdfSharp.Pdf.PdfObject.ImportClosure(PdfImportedObjectTable importedObjectTable, PdfDocument owner, PdfObject externalObject) at PdfSharp.Pdf.PdfPages.CloneElement(PdfPage page, PdfPage importPage, String key, Boolean deepcopy) at PdfSharp.Pdf.PdfPages.ImportExternalPage(PdfPage importPage) at PdfSharp.Pdf.PdfPages.Insert(Int32 index, PdfPage page) at PdfSharp.Pdf.PdfPages.Add(PdfPage page) at PdfSharp.Pdf.PdfDocument.AddPage(PdfPage page) at Tickets.Module1.mergePDFS(IEnumerable`1 docs) in E:\Apps\PDF\Tickets\Tickets\Module1.vb:line 87 at Tickets.Module1.Main() in E:\Apps\PDF\Tickets\Tickets\Module1.vb:line 31 at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args) at System.AppDomain.nExecuteAssembly(RuntimeAssembly assembly, String[] args) at System.Runtime.Hosting.ManifestRunner.Run(Boolean checkAptModel) at System.Runtime.Hosting.ManifestRunner.ExecuteAsAssembly() at System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext activationContext, String[] activationCustomData) at System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext activationContext) at System.Activator.CreateInstance(ActivationContext activationContext) at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssemblyDebugInZone() at System.Threading.ThreadHelper.ThreadStart_Context(Object state) at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Threading.ThreadHelper.ThreadStart()
Code:
Function mergePDFS(docs As IEnumerable(Of String)) As PdfSharp.Pdf.PdfDocument
Dim merged As New PdfSharp.Pdf.PdfDocument merged.Options.CompressContentStreams = True merged.Options.NoCompression = False
For Each doc In docs.Distinct
Dim rdr = PdfSharp.Pdf.IO.PdfReader.Open(doc, PdfSharp.Pdf.IO.PdfDocumentOpenMode.Import) For Each pg In rdr.Pages.Cast(Of PdfSharp.Pdf.PdfPage)().ToArray
merged.AddPage(pg)<-----Exception here Next
Next
Return merged
End Function
<package id="PdfSharp" version="1.32.3057.0" targetFramework="net462" />
|