Hi, my project got one pdf that I am trying to convert to PDF_A_3U. It has 97 pages 2 with text and 95 with 95 a4 pictures.
Tried 24.9.0, 24.10.0 and even aspose pdf drawing 24.9.0 and same error.
This is pdf I am trying to convert aqacwgqx.yz0.pdf
Object reference not set to an instance of an object. at #=zYuTRjC5haReAzPc8N2LDllcd3lWZYn7yXVkho4tDCa$x7Uamb7XTnY9$UEmq.#=zbJbbqUgM6wW6(String #=zPbDyMCU=)\n at #=zYuTRjC5haReAzPc8N2LDllcd3lWZYn7yXVkho4tDCa$x7Uamb7XTnY9$UEmq.Visit(ShowText #=zBq$kHDE=)\n at Aspose.Pdf.Operators.ShowText.Accept(IOperatorSelector visitor)\n at #=zYuTRjC5haReAzPc8N2LDllcd3lWZYn7yXVkho4tDCa$x7Uamb7XTnY9$UEmq.#=zp2$6MCA=(OperatorCollection #=z9OTUI24=)\n at #=zkkgbJHCtquAeYpcBgZH0G$rKKCr6alY_v1qUID1JoSikuqNwUx1yHAs=.#=zqXBVfwO_uTpB(#=zkkgbJHCtquAeYpcBgZH0G$rKKCr6alY_v1qUID1JoSikuqNwUx1yHAs= #=zyj$d7k8=, OperatorCollection #=z9OTUI24=, Resources #=zyD6ssiU=)\n at #=zbYFkEb0m8XLicMDR5i57wOZ0QemvpxievWf38R0_zHBTpMESBGOppA6f8wUB.#=zCx6CJDP1qLt0(OperatorCollection #=z9OTUI24=, Resources #=zyD6ssiU=)\n at #=zdOQ$0HU4geN7$D5lgdEHvaqD2az01TONb4EEdnhMvrf_vxycan8wZcA=.#=zmiHcfz96dimq(HashSet1 #=zKiq06t9dBgr9, XForm #=zOBSOD90=, Resources #=zvL3qEER6lJAl, HashSet1 #=z00WO_mhxu8he)\n at #=zdOQ$0HU4geN7$D5lgdEHvaqD2az01TONb4EEdnhMvrf_vxycan8wZcA=.#=zxkQ9J9Hi7XyP()\n at #=zkkgbJHCtquAeYpcBgZH0G$rKKCr6alY_v1qUID1JoSikuqNwUx1yHAs=.#=zzBg_pes=()\n at #=zdOQ$0HU4geN7$D5lgdEHvaqD2az01TONb4EEdnhMvrf_vxycan8wZcA=.#=z_8Hf15U=()\n at #=zkkgbJHCtquAeYpcBgZH0G$rKKCr6alY_v1qUID1JoSikuqNwUx1yHAs=.#=zDcPbedw=(XmlTextWriter #=zOt_7BM4=, PdfFormat #=z1pv3stw=, Document #=zGBHEld0=, Boolean #=zQxr2kM2gT1Qv, ConvertErrorAction #=zBwVMCGQ=)\n at Aspose.Pdf.Document.#=zHAvpqGg=(XmlTextWriter #=zOt_7BM4=, PdfFormat #=z1pv3stw=, Boolean #=zQxr2kM2gT1Qv, ConvertErrorAction #=zBwVMCGQ=)\n at Aspose.Pdf.Document.Convert(Stream outputLogStream, PdfFormat format, ConvertErrorAction action)\n at Esel.Sazba.Api.Host.DokumentGenerator.PdfGenerator.Helper.AHFPdfGenerovani.PdfPostprocess(List1 outputFiles, ConcurrentBag1 _logovaniPerfDat, String outputFile, XmpMetadata xmpMetadata, GenerovaniSouborovehoDokumentu dalsiInfo, IResourcesManager _resourcesManager, IOptions1 _exportOptions) in E:\\work2\\sazba\\src\\Esel.Sazba.Api.Host\\DokumentGenerator\\PdfGenerator\\Helper\\AHFPdfGenerovani.cs:line 343\n at Esel.Sazba.Api.Host.DokumentGenerator.PdfGenerator.Helper.AHFPdfGenerovani.generovatAHFPdf(FileLoader fileLoader, List1 spracovaneDokumenty, ZdrojSouboru zdrojSouboru, GenerovaniSouborovehoDokumentu dalsiInfo, XmpMetadata xmpMetadata) in E:\work2\sazba\src\Esel.Sazba.Api.Host\DokumentGenerator\PdfGenerator\Helper\AHFPdfGenerovani.cs:line 139\n at Esel.Sazba.Api.Host.Controllers.SazbaAsyncControllerImpl.<>c__DisplayClass15_0.<b__1>d.MoveNext() in E:\work2\sazba\src\Esel.Sazba.Api.Host\Controllers\SazbaAsyncControllerImpl.cs:line 281
Code I use for it is just basic
Aspose.Pdf.Document doc = new Aspose.Pdf.Document(outputFile);
doc.Convert(new MemoryStream(), PdfFormat.PDF_A_3U, ConvertErrorAction.Delete);
It seems you are encountering a System.NullReferenceException while trying to convert a PDF file to PDF/A-3U format using Aspose.PDF. This type of error typically indicates that there is an attempt to access an object that has not been initialized.
To address this issue, I recommend the following steps:
Validate the PDF Document: Before converting the PDF to a PDF/A format, it’s essential to validate the document. This can help identify any issues that may cause the conversion to fail. You can use the Validate method provided by the Aspose.PDF library to perform this check.
Check for Unsupported Elements: The PDF you are trying to convert may contain elements that are not supported in the PDF/A format. You can specify how to handle these unsupported elements using the ConvertErrorAction enumeration. For example, you can choose to delete unsupported elements or log them for review.
Use the Correct Version: Ensure that you are using a version of Aspose.PDF that supports PDF/A-3U conversion. This feature was introduced in version 17.2.0, so make sure your library version is up to date.
Here is a basic example of how to validate and convert a PDF to PDF/A-3U:
using Aspose.Pdf;
using System.IO;
public void ConvertToPdfA3U(string inputFilePath, string outputFilePath)
{
// Load the PDF document
Document doc = new Document(inputFilePath);
// Validate the PDF document
var validationResult = doc.Validate();
// Check if the document is valid
if (validationResult.IsValid)
{
// Convert to PDF/A-3U
using (MemoryStream outputStream = new MemoryStream())
{
doc.Convert(outputStream, PdfFormat.PDF_A_3U, ConvertErrorAction.Delete);
File.WriteAllBytes(outputFilePath, outputStream.ToArray());
}
}
else
{
// Handle validation errors
foreach (var error in validationResult.Errors)
{
Console.WriteLine($"Validation Error: {error}");
}
}
}
Make sure to replace inputFilePath and outputFilePath with the actual paths of your PDF files. This code snippet first validates the PDF and then attempts to convert it to PDF/A-3U, handling any errors that may arise during the process.
If the problem persists after following these steps, consider checking the specific content of the PDF file for any elements that may not be compatible with PDF/A standards.
We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.
Issue ID(s): PDFNET-58381
You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.