Null error on doc.save

Hello,

Using the second code snippet labeled "Save output HTML to a single stream with embedded resources" from here PDF to HTML - Save Output to a Stream Object we seam to get a null reference error.
doc.pdfaFormat: "Object reference not set to an instance of an object."
StackTrace:" at Aspose.Pdf.Document.get_PdfaFormat()"

The only thing we changed was pointing the new doc to a valid pdf.
We am currently using a temporary licence with version 11.5.0.0 of Aspose.pdf

Is there anything else that needs to be implements to fix this issue?


Thanks,
Mike Oliver

Hi Mike,


Thanks for your inquiry. I have tested the scenario again using Aspose.Pdf for .NET 11.6.0 and unable to notice the reported exception. Please note you have to consider only one thing while saving a single PDF from HTML to stream, need to pass a non-existing path and html file name to Document.Save() method. Please find the sample code. If the issue persist then please share a sample console project here, so we will look into it and will guide you accordingly.

public static void temp()<o:p></o:p>

{

Document doc = new Document(@"test.pdf");

// tune conversion params

HtmlSaveOptions newOptions = new HtmlSaveOptions();

newOptions.RasterImagesSavingMode = HtmlSaveOptions.RasterImagesSavingModes.AsEmbeddedPartsOfPngPageBackground;

newOptions.FontSavingMode = HtmlSaveOptions.FontSavingModes.SaveInAllFormats;

newOptions.PartsEmbeddingMode = HtmlSaveOptions.PartsEmbeddingModes.EmbedAllIntoHtml;

newOptions.LettersPositioningMethod = HtmlSaveOptions.LettersPositioningMethods.UseEmUnitsAndCompensationOfRoundingErrorsInCss;

newOptions.SplitIntoPages = false;// force write HTMLs of all pages into one output document

newOptions.CustomHtmlSavingStrategy = new HtmlSaveOptions.HtmlPageMarkupSavingStrategy(SavingToStream);

//we can use some non-existing path and result file name - all real saving will be done

//in our custom method SavingToStream() (it's follows this one)

string outHtmlFile = @"Z:\SomeNonExistingFolder\SomeUnexistingFile.html";

doc.Save(outHtmlFile, newOptions);

}

private static void SavingToStream(HtmlSaveOptions.HtmlPageMarkupSavingInfo htmlSavingInfo)

{

byte[] resultHtmlAsBytes = new byte[htmlSavingInfo.ContentStream.Length];

htmlSavingInfo.ContentStream.Read(resultHtmlAsBytes, 0, resultHtmlAsBytes.Length);

// here You can use any writable stream, file stream is taken just as example

string fileName =@"stream_out.html";

Stream outStream = File.OpenWrite(fileName);

outStream.Write(resultHtmlAsBytes, 0, resultHtmlAsBytes.Length);

}


Please feel free to contact us for any further assistance.

Best Regards,

I have gotten it to work with some files. Still seam to get the error with the attached files and a lot of other similar files.

Is there something I can do to check the format or is there a different way I need to convert these files?

Hi Mike,


Thanks for sharing the resource file.

I have tested the scenario and have managed to reproduce same problem. For the sake of correction, I have logged it as PDFNEWNET-40774 in our issue tracking system. We will further look into the details of this problem and will keep you posted on the status of correction. Please be patient and spare us little time. We are sorry for this inconvenience.

The issues you have found earlier (filed as PDFNET-40774) have been fixed in Aspose.PDF for .NET 23.4.