We are merging PDF’s and then trying to convert the PDF to Pdf_A_2A. We dont need the old signature we simply just want to merge the document. We get an error after trying to upgrade to 24.8.0 or higher, we also see the same error when downgrading to 24.6.0. But 24.5.0 and 24.7.0 works. Here is the error that we recieve:
System.NullReferenceException: Object reference not set to an instance of an object.
at #=zhvNcQ1lyeQGAYZe1bYAPLI_uIKGUzBFZIl2xQtzLbMmv5$VFqJ3IFIg=.#=zLFYeOhQ=()
at #=zIoJtPKXkUlWC1ZOCbqP1wv_6RGR90tou$T2xzs54XBL6zq10BJyhJgs=.#=zHzgvwrM=()
at…
And this is the code:
var pdfDokument = new Pdf.Document();
foreach(var fil in files)
{
var bytes = Convert.FromBase64String(fil.Base64FilData);
var stream = new MemoryStream(bytes);
var doc = new Pdf.Document(stream);
pdfDokument .Pages.Add(doc.Pages);
}
using var ms = new MemoryStream();
pdfDokument.Convert(ms, Pdf.PdfFormat.PDF_A_2A, Pdf.ConvertErrorAction.None);
pdfDokument.Save(ms);
ms.Position = 0;
return ms.ToArray();
We tested with 24.12 version and the below code sample in our environment. We could not notice any error or exception:
var pdfDokument = new Pdf.Document();
var doc = new Pdf.Document(new FileStream(dataDir + "samplecertifiedpdf.pdf", FileMode.Open));
using var ms = new MemoryStream();
pdfDokument.Convert(ms, Pdf.PdfFormat.PDF_A_2A, Pdf.ConvertErrorAction.None);
pdfDokument.Save(ms);
Can you please try with the latest version of the API and let us know if issue still persists.
Hey,
Just looked at your example and it looks like your forgot to use “var doc”. You need to add “doc” to "pdfDokument " and then convert it to “Pdf.PdfFormat.PDF_A_2A”
public byte[] MergeDokumenter(List<FilModel> files)
{
var pdfDokument = new Pdf.Document();
foreach(var fil in files)
{
var bytes = Convert.FromBase64String(fil.Base64FilData);
var stream = new MemoryStream(bytes);
var doc = new Pdf.Document(stream);
pdfDokument .Pages.Add(doc.Pages);
}
using var ms = new MemoryStream();
pdfDokument.Convert(ms, Pdf.PdfFormat.PDF_A_2A, Pdf.ConvertErrorAction.None);
pdfDokument.Save(ms);
ms.Position = 0;
return ms.ToArray();
}
Looks like it works if i use the “Flatten()” methode before converting the merged PDF like this:
public byte[] MergeDokumenter(List<FilModel> files)
{
var pdfDokument = new Pdf.Document();
foreach(var fil in files)
{
var bytes = Convert.FromBase64String(fil.Base64FilData);
var stream = new MemoryStream(bytes);
var doc = new Pdf.Document(stream);
pdfDokument .Pages.Add(doc.Pages);
}
using var ms = new MemoryStream();
pdfDokument.Convert(ms, Pdf.PdfFormat.PDF_A_2A, Pdf.ConvertErrorAction.None);
pdfDokument.Save(ms);
ms.Position = 0;
return ms.ToArray();
}
But this pdf comes out as just an white page if i flatten it first: sample11.pdf (207.7 KB)
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-58998
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.