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()
{
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 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);
outStream.Close();
}
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.
Hi Mike,
The issues you have found earlier (filed as PDFNET-40774) have been fixed in Aspose.PDF for .NET 23.4.