Dear Aspose Support,
I recently upgraded my AWS Lambda function from .NET Core 3.1 to .NET 8.0, and after the upgrade, I encountered an issue where images are no longer being appended in the Publisher files when converting to PDF. Text conversion to PDF works as expected, but the images are missing in the resulting document. Since System.Drawing is not supported in .NET 8 in linux environment I am using Aspose.Drawing package.
Since this is business critical issue, I will require your assistance promptly.
Here’s the original code that was working fine prior to the upgrade:
var pubDoc = PubFactory.CreateParser(inStream);
var pubDocToPdf = pubDoc.Parse();
PubFactory.CreatePdfConverter().ConvertToPdf(pubDocToPdf, outStream);
Aspose.Pdf.Document pubPdfDoc = new Aspose.Pdf.Document(outStream);
After the upgrade, I have tried the following different code approaches, but none of them solve the problem of missing images in the final PDF output:
-
First Attempt - Image Optimization
case “.pub”:
Console.WriteLine(“Converting Publisher document with image optimization…”);
inStream.Position = 0;// First stage: Convert to PDF using Aspose.Pub var pubDoc = PubFactory.CreateParser(inStream); var pubDocToPdf = pubDoc.Parse(); using (var tempStream = new MemoryStream()) { // Initial conversion PubFactory.CreatePdfConverter().ConvertToPdf(pubDocToPdf, tempStream); tempStream.Position = 0; // Second stage: Optimize with Aspose.Pdf using (var pdfDoc = new Aspose.Pdf.Document(tempStream)) { // Configure PDF options for better image handling var pdfDeviceInfo = new Aspose.Pdf.Devices.PdfDeviceInfo { PageSize = new Aspose.Pdf.Devices.PageSize(800, 600), Quality = 100 }; // Set rendering options pdfDoc.PageInfo.Width = 800; pdfDoc.PageInfo.Height = 600; pdfDoc.OptimizeResources(); // Save with optimization pdfDoc.Save(outStream, Aspose.Pdf.SaveFormat.Pdf); pageCountDocument = pdfDoc.Pages.Count.ToString(); } } break;
-
Second Attempt - Enhanced Rendering
case “.pub”:
Console.WriteLine(“Converting Publisher document with enhanced rendering…”);
inStream.Position = 0;// Initial conversion var pubDoc = PubFactory.CreateParser(inStream); var pubDocToPdf = pubDoc.Parse(); using (var tempStream = new MemoryStream()) { // Convert to PDF first PubFactory.CreatePdfConverter().ConvertToPdf(pubDocToPdf, tempStream); tempStream.Position = 0; // Load into PDF document using (var pdfDoc = new Aspose.Pdf.Document(tempStream)) { // Configure save options var saveOptions = new Aspose.Pdf.PdfSaveOptions { EnableLinearization = true, CompressImages = true, ImageQuality = 100, OptimizeResources = true }; // Process each page to ensure proper image rendering foreach (var page in pdfDoc.Pages) { page.ResizeContent(800, 600, true, true); page.OptimizeResources(); } // Save with optimization pdfDoc.Save(outStream, saveOptions); pageCountDocument = pdfDoc.Pages.Count.ToString(); } } break;
-
Third Attempt - Fallback Options
case “.pub”:
Console.WriteLine(“Converting Publisher document with fallback options…”);
inStream.Position = 0;try { // Attempt primary conversion with image optimization var pubDoc = PubFactory.CreateParser(inStream); var pubDocToPdf = pubDoc.Parse(); using (var tempStream = new MemoryStream()) { // First attempt with Aspose.Pub PubFactory.CreatePdfConverter().ConvertToPdf(pubDocToPdf, tempStream); tempStream.Position = 0; // Check if the PDF has content using (var pdfDoc = new Aspose.Pdf.Document(tempStream)) { if (pdfDoc.Pages.Count > 0) { // Configure save options for better image handling var saveOptions = new Aspose.Pdf.PdfSaveOptions { EnableLinearization = true, CompressImages = true, ImageQuality = 100 }; pdfDoc.Save(outStream, saveOptions); pageCountDocument = pdfDoc.Pages.Count.ToString(); } else { throw new Exception("Empty PDF generated"); } } } } catch (Exception pubEx) { Console.WriteLine($"Warning: Primary conversion failed, attempting fallback: {pubEx.Message}"); // Fallback: Create a PDF with warning using (var doc = new Aspose.Words.Document()) { var builder = new Aspose.Words.DocumentBuilder(doc); builder.ParagraphFormat.Alignment = Aspose.Words.ParagraphAlignment.Center; builder.Writeln("Publisher Document Conversion Notice"); builder.Writeln(); builder.Writeln("This document contains images that could not be fully rendered."); builder.Writeln("Please try viewing the original file or converting on a Windows system."); builder.Writeln(); builder.Writeln($"File size: {inStream.Length} bytes"); doc.Save(outStream, Aspose.Words.SaveFormat.Pdf); pageCountDocument = "1"; } } break;
Let me know where I should change so PUB can be converted successfully.