Free Support Forum - aspose.com

Save Pdf/A Exception

Hi,
I am using aspose.pdf to convert pdf/a. But it gives me an exception for one PDF.
Pdf download link;

The code below;
Using pdf_document As New Aspose.Pdf.Document(pOutputFilepath)
For Each page As Page In pdf_document.Pages
If page.Resources.Fonts IsNot Nothing Then
For Each pageFont As Aspose.Pdf.Text.Font In page.Resources.Fonts
'Check if font is already embedded
If Not pageFont.IsEmbedded Then
pageFont.IsEmbedded = True
End If
Next
End If

            'Check for the Form objects
            For Each form As XForm In page.Resources.Forms
                If form.Resources.Fonts IsNot Nothing Then
                    For Each formFont As Aspose.Pdf.Text.Font In form.Resources.Fonts
                        'Check if the font is embedded
                        If Not formFont.IsEmbedded Then
                            formFont.IsEmbedded = True
                        End If
                    Next
                End If
            Next
        Next

        pdf_document.Convert(pTempFilePath4Log, PdfFormat.PDF_A_1A, ConvertErrorAction.Delete)

        Dim optimizeOptions As New Aspose.Pdf.Optimization.OptimizationOptions()

        optimizeOptions.RemoveUnusedObjects = True
        'optimizeOptions.RemoveUnusedStreams = True
        optimizeOptions.UnembedFonts = False
        optimizeOptions.SubsetFonts = True
        optimizeOptions.AllowReusePageContent = True
        pdf_document.OptimizeResources(optimizeOptions)

        pdf_document.Save(pOutputFilepath)
        Try
            System.IO.File.Delete(pTempFilePath4Log)
        Catch
            'NOLOG
        End Try
    End Using

Error;
An entry with the same key already exists.
at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)
at System.Collections.Generic.TreeSet1.AddIfNotPresent(T item) at System.Collections.Generic.SortedDictionary2.Add(TKey key, TValue value)
at #=zwN7gV$i3ZWLK_lDIOJyCPbp4y2eeM2tANV4XsrEOHTjAEfR4Qg==.#=zwDHfAWC4hgB6()
at #=zqw9ISzvB3tQKO7TL$dspb318g8$9UGOTeALZC$NB2R062AjsRUhM3zpT3zCT.#=zWIK7pfrH53YObwENUA==()
at #=zqw9ISzvB3tQKO7TL$dspb318g8$9UGOTeALZC$NB2R062AjsRUhM3zpT3zCT.#=z4i2s6L7htg7g(BaseOperatorCollection #=zrhapXy0=, Resources #=zeo2FNI8=)
at #=zqw9ISzvB3tQKO7TL$dspb318g8$9UGOTeALZC$NB2R062AjsRUhM3zpT3zCT.#=zcXOshpM=()
at #=zqw9ISzvB3tQKO7TL$dspb318g8$9UGOTeALZC$NB2R062AjsRUhM3zpT3zCT…ctor(Page #=z1mwwV1s=, TextSearchOptions #=ziKTNgYLRKixX, Resources #=zeo2FNI8=, BaseOperatorCollection #=z_yOqpvg=)
at #=zqw9ISzvB3tQKO7TL$dspb318g8$9UGOTeALZC$NB2R062AjsRUhM3zpT3zCT…ctor(Page #=z1mwwV1s=, Resources #=zeo2FNI8=, BaseOperatorCollection #=z_yOqpvg=)
at #=zXVlFEEh4xBtU6NeQ7RfG7bZZYdqTo5TaNMXAA$7k6k9dn0s_MgUL1CY=.#=zHQ$v4KDtvaaE(Page #=z1mwwV1s=, OperatorCollection #=zrhapXy0=, Resources #=zeo2FNI8=, Int32 #=zyk9RmRUDYCJB, #=z$zbkIeXhJXncVj5AwTO1lO3ZiW4AanAqZ3nyo2drhd3lMnPAsg== #=zhX6lThofGato)
at #=zXVlFEEh4xBtU6NeQ7RfG7bZZYdqTo5TaNMXAA$7k6k9dn0s_MgUL1CY=.#=zNZGRSand7y1b(Page #=z1mwwV1s=, #=z$zbkIeXhJXncVj5AwTO1lO3ZiW4AanAqZ3nyo2drhd3lMnPAsg== #=zhX6lThofGato)
at #=zXVlFEEh4xBtU6NeQ7RfG7bZZYdqTo5TaNMXAA$7k6k9dn0s_MgUL1CY=.#=zvTnI0Y8=()
at #=zXVlFEEh4xBtU6NeQ7RfG7bZZYdqTo5TaNMXAA$7k6k9dn0s_MgUL1CY=.#=zv9OzZ_8=()
at #=zkz44GdPYlcd5RjCgaE0BUQx0vHBqK0sI9NAuoquF0IOzaHP64wuCI$U=.#=zTol2npc=()
at #=zXVlFEEh4xBtU6NeQ7RfG7bZZYdqTo5TaNMXAA$7k6k9dn0s_MgUL1CY=.#=zxu3C9F4=(XmlTextWriter #=zqIDLf_Y=, PdfFormat #=zhpl2_D8=, Document #=zx8MBJi0=, Boolean #=z$Nzjd5356YXh, ConvertErrorAction #=zdKmfLp0=)
at Aspose.Pdf.Document.#=z4VYcFJ0=(XmlTextWriter #=zqIDLf_Y=, PdfFormat #=zhpl2_D8=, Boolean #=z$Nzjd5356YXh, ConvertErrorAction #=zdKmfLp0=)
at Aspose.Pdf.Document.#=zfYeD98hMVN6_(Stream #=zDrP5f$U=, SaveOptions #=zLc_YMqUK9KcV)
at Aspose.Pdf.Document.#=z6kAOwZAWlPGY(String #=zknH$69bRkHRh)
at Aspose.Pdf.Document.Save(String outputFileName)

@zelihaserbez

I can not reproduce the issue and the Pdf/A is created fine. I request you to upgrade to latest version and share your feedback.

Hello,

Thanks, This pdf fixed with new aspose version, but i am getting error when convert pdf to pdf/a with same code block with this attached pdf. Araştırma İzni Hk…pdf (2.3 MB)

Error;
Invalid font name
[STACK TRACE] --> at Aspose.Pdf.Text.FontCollection.get_Item(String name)
at #=zLp1QCJMCjlTckKpu7U$O4RCSSaZfFQfkGD6hnPj2aQs7byb4pKltQ0g=.#=z_B8Pw6ZA4M1E(OperatorCollection #=zsXKF$4Q=, Resources #=zXPauxRg=, Double #=zLiDU_zg=, Double #=zPdDEvtU=)
at #=zLp1QCJMCjlTckKpu7U$O4RCSSaZfFQfkGD6hnPj2aQs7byb4pKltQ0g=.#=znaZWZSY=()
at #=zrDdklJFhB7bjk3SZNbiGp62ySlxdD37r0zoXY1htGL410friz6wo09k=.#=z59ew$Q$UI0Y8()
at #=zyd0QVtztbDpEqmmf2iEbxs7j4YMOPYzTTuhS9PshG_F1CdQ7FbEMBMI=.#=zXVMpArA=()
at #=zrDdklJFhB7bjk3SZNbiGp62ySlxdD37r0zoXY1htGL410friz6wo09k=.#=zmXDKc7Y=()
at #=zyd0QVtztbDpEqmmf2iEbxs7j4YMOPYzTTuhS9PshG_F1CdQ7FbEMBMI=.#=ztjhr9pM=(XmlTextWriter #=zdjYVnxU=, PdfFormat #=zs28Uvck=, Document #=z1RIQoE4=, Boolean #=z7UTHiARpVlMe, ConvertErrorAction #=zkkCddzs=)
at Aspose.Pdf.Document.#=zyLWIUi8=(XmlTextWriter #=zdjYVnxU=, PdfFormat #=zs28Uvck=, Boolean #=z7UTHiARpVlMe, ConvertErrorAction #=zkkCddzs=)
at Aspose.Pdf.Document.#=z191VBrPmsrWS(Stream #=zC_Y0TrI=, SaveOptions #=zqcrLbOpckPbJ)
at Aspose.Pdf.Document.#=zpcTDqMYRNLY7(String #=zbReOKOf$ER2X)
at Aspose.Pdf.Document.Save(String outputFileName)

Best regards,

@zelihaserbez

I have been able to reproduce the issue on our end. A ticket with ID PDFNET-50050 has been created in our issue tracking system to further investigate the issue on our end. This thread has been linked with the issue so that you may be notified once the issue will be fixed.

Hello,

I have another problem. I am getting error when convert pdf to pdf/a with same code block with this attached pdf. örnek_htf.pdf (68.8 KB)

Error;
Object reference not set to an instance of an object.
[STACK TRACE] --> at #=zNmZ11JZG2s4gwNGgO6ST5AthpERdUSbnG35bvOgblSWNoGKUNP3qbeA=.#=zb2zrEKzgDxMY(#=zCHff2yDbXLvv #=zRkWmKnA=)
at #=zNmZ11JZG2s4gwNGgO6ST5AthpERdUSbnG35bvOgblSWNoGKUNP3qbeA=.#=zYa3VMOcF0Kk7(FontSubsetStrategy #=ziV2Hzj4AtbNA)
at #=zz3MGaNDzsCB0VsKL5idmp$MggTBb.#=znaZWZSY=(OptimizationOptions #=zWYbfV2Y=)
at Aspose.Pdf.Document.OptimizeResources(OptimizationOptions strategy)

Best regards,

@zelihaserbez

I have been able to reproduce NullReferenceException on our end. A ticket with ID PDFNET-50058 has been created in our issue tracking system to further investigate the issue.