System.ArgumentException "An item with the same key has already been added" when converting PostScript (Xerox and HP drivers)

Reproducible in versions 24.x through 26.7

Summary

We consistently get a System.ArgumentException (“An item with the same key
has already been added.”) when loading real-world PostScript print jobs
with Aspose.Pdf.Document using PsLoadOptions, in order to render each page
to PNG. The exception originates deep inside the internal PS parsing/
resource-handling pipeline (see stack trace below), not in our calling code.

This has been reproducible across every version we have tested, from 24.x
through the current 26.7, with PostScript generated by two different print
drivers (HP and Xerox), from two different physical print jobs. We were
also able to reproduce the failure using your own online PS/EPS converter
with one of the same files, which rules out anything specific to our local
environment, .NET version, or installed fonts.

Environment

  • Aspose.PDF for .NET, versions tested: 24.x through 26.7 (current)
  • .NET Framework 4.8
  • Windows

Source of the PostScript files

  • File 1: generated by an HP printer driver (PScript5.dll-based).
  • File 2: generated by a Xerox printer driver (Xerox Pull Print Driver PS,
    PostScript Level 3 / DSC 3.0).
  • Both are real Microsoft Word print jobs (PJL-encapsulated PostScript, as
    is standard for our print-capture pipeline).
  • We have tested both: (a) the PostScript stream with the surrounding @PJL
    commands and UEL sequences stripped out (PostScript only), and (b) the
    file completely unmodified as originally captured. The exception occurs
    in both cases, so PJL is not a factor.

What we already ruled out

Before reporting, we manually inspected both files for the most likely
causes of a duplicate-key exception at the DSC (Document Structuring
Convention) level:

  • No duplicate %%BeginResource / %%IncludeResource / %%+ font declarations.
  • No duplicate internal font resource names among the embedded Type 42
    (TrueType-wrapped) fonts (each embedded font subset has a distinct
    internal PostScript name, e.g. /TT12E6t00 vs /TT200D6t00).
    Given the obfuscated stack trace, we were not able to narrow this down
    further from our side — this appears to require internal instrumentation
    of your parser/resource dictionary construction.

Business context

We are finalizing a Developer OEM license purchase for Aspose.PDF as part
of a licensing compliance initiative (replacing AGPL-licensed components
previously used for print-job coverage analysis and thumbnail generation
for PCL and PostScript print jobs). Aspose.PDF already works well for us
across PCL (PclLoadOptions), PDF, and HTML — version 26.6→26.7 brought a
noticeable improvement specifically on the PCL side, which is part of what
convinced us to move forward with the purchase.

PostScript is the one remaining format where we cannot get Aspose.PDF to
work at all — not even with a minimal, non-confidential test file. Our
intended use case is generating an 80dpi thumbnail preview image on demand,
only when a user chooses to open/preview a specific print job (not for
every job processed), covering the Mac/PostScript segment of our print
fleet. This issue is currently the one open item standing between us and
finalizing the purchase — we would very much like to get it resolved.

Stack trace

at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)
at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
at #=zD7wkdDvtJXGtGEPccCuyxKbcJ7xvxYeU_GlDU8ObLe5B.#=zwpl1Fd0=(Int32 #=zRc34axA=, #=zCW$rNQr1rZ5qO5oQjrJZEcxD8L6_Uf0Ovy4r5Qc= #=zBzguhyw=)
at #=zVqfx4H2FHDVW$FXBkuxA9tOJmVT5C0$_jrQrTMlxV1FQ.#=z$2lOUWD9sffO(#=zsZ6nHclJFe5r1VHere4tEUurPOlIBkT7K7D2Zcg= #=z_Fvufg4=)
at #=zhUlyPIBdUJaDRP1JHiQrODqmh7Yn9a1tqmFrr5k=.#=zOhhViKLub6tU(#=zVqfx4H2FHDVW$FXBkuxA9tOJmVT5C0$_jrQrTMlxV1FQ #=zS0xeRww=, Boolean #=zqbqDMSY=)
at #=zhUlyPIBdUJaDRP1JHiQrODqmh7Yn9a1tqmFrr5k=.#=zooYO7g4=(#=zmrMPozFUM8Ro9oEs9O$vs5R5HlnKRGUGrgfo27mgQsyW #=zWMvtu08=)
at #=z1Qmo3qMvzehkbhk3hV1FqUdJg_FwkwI2lOScoVrTeGKn.#=zVUltoUso$N9Q(#=zmrMPozFUM8Ro9oEs9O$vs5R5HlnKRGUGrgfo27mgQsyW #=zWMvtu08=)
at #=zraEykBcIC80DhTQxQmoQT0Hh06UNEVkrCTQb9R8=.#=zfGAT2vw=(Boolean #=zKd4rOmg=)
at #=zraEykBcIC80DhTQxQmoQT0Hh06UNEVkrCTQb9R8=.#=zwvzVT2g=()
at #=z2ABKGRtkSEpJhjlMEZTQEdNfFRlQ.#=zLPdCd8j3DI4s(#=z3iGAYM877E6MDE2dNlhmp5k= #=zDRbaXCo=, #=zPd$$slz5Rf9uJyR9Fw== #=zTLEioJc=, #=zBT2oPUzdiYKz #=z7llgb_j_k$kL)
at #=z2ABKGRtkSEpJhjlMEZTQEdNfFRlQ.#=zecvaE1M=(#=z3iGAYM877E6MDE2dNlhmp5k= #=zDRbaXCo=, #=zPd$$slz5Rf9uJyR9Fw== #=zTLEioJc=, #=zBT2oPUzdiYKz #=z7llgb_j_k$kL)
at #=z2ABKGRtkSEpJhjlMEZTQEdNfFRlQ.#=zMdJ99ao=(#=zPd$$slz5Rf9uJyR9Fw== #=zTLEioJc=, #=z3iGAYM877E6MDE2dNlhmp5k= #=zDRbaXCo=)
at #=z2ABKGRtkSEpJhjlMEZTQEdNfFRlQ.#=zebYuWQcFjl$p(Stream #=zUn8Av5iN$X$5, #=zXEtnsa0npbQMIkDsAZ2SDWjJjw21a0QcHA== #=zDRbaXCo=)
at #=znKQO$yeonvh7pPoEc_n4Vqo=.#=zMhKnvWWQ598V(Document #=z$SDfYT4=, Stream #=zlA$gHJcHwSKu, PsLoadOptions #=zxSvU5f26dwqs)
at Aspose.Pdf.Document.#=zfKtXKjs=(Stream #=zS7hRhj0=, LoadOptions #=zDRbaXCo=, Boolean #=zpVcRdOpz_cza)
at Aspose.Pdf.Document.#=zfKtXKjs=(Stream #=zS7hRhj0=, LoadOptions #=zDRbaXCo=)
at Aspose.Pdf.Document…ctor(String filename, LoadOptions options)
at PruebaPCL.Form1.btnPostScript_Click(Object sender, EventArgs e) in C:\Proyectos\PruebaPCL\PruebaPCL\Form1.vb:line 58

Code used to reproduce (License loads before)

Private Sub btnPostScript_Click(sender As Object, e As EventArgs) Handles btnPostScript.Click
Dim ArchivoPS = “D:\ArchivoPS_HP.ps”
Dim RutaSalida = “C:\Users\danie\Desktop\SalidaPNG”
Dim options As New PsLoadOptions() With {
.DisableFontLicenseVerifications = False
}
Using doc As New Document(ArchivoPS, options)
’ Ver cuántas páginas detectó
Debug.Print($“Páginas detectadas: {doc.Pages.Count}”)
’ Generar PNG por página a 80 DPI
Dim resolution As New Resolution(80)
Dim device As New PngDevice(resolution)
For i As Integer = 1 To doc.Pages.Count
Dim rutaPNG As String = Path.Combine(RutaSalida, $“paginaPS_{i}.png”)
Using stream As New FileStream(rutaPNG, FileMode.Create)
device.Process(doc.Pages(i), stream)
End Using
Console.WriteLine($“Generada: {rutaPNG}”)
Next
End Using
End Sub

Sharing the reproduction files

We were not able to find an option to attach files directly on this form.
We have two PostScript files ready to share (HP-driver and Xerox-driver,
both with PJL stripped) that reliably reproduce this exception. Could you
let us know how we should get them to you — email, a shared drive link, or
another channel?

Request

Could you please confirm whether this is a known issue, and let us know
what information you need from us (e.g., the unmodified files with PJL
included, additional test files) to help pinpoint the root cause? We’re
happy to provide more reproduction cases if useful — we have several print
jobs from both HP and Xerox drivers exhibiting the same failure.

Good day. I am pleased to inform you that I encountered the same issue in the logs of our project at Convert PDF | Online and Free 5 months ago. I work on the Web team. Our team uses the Aspose.PDF.Drawing.dll library, where this issue occurs. Therefore, I filed a bug report, adding a log, a file, and the line of my code where the stack trace begins. The issue with ID PDFNET-61730 has not been resolved yet. Please reach out to the team responsible for developing this library to expedite the resolution of the problem.