Free Support Forum -

PDF doesn't finish saving when including an image

I’m generating a very simple PDF that includes a PNG image in the header by following the example here:

The problem is that as soon as I include the image and save the PDF, the output file is never released and remains locked. As soon as I remove the lines of code that include the image, everything works fine.

Here’s the code I’m using:

var pdf = new Aspose.Pdf.Generator.Pdf();
var documentSection = pdf.Sections.Add();

var header = new HeaderFooter(documentSection);
documentSection.EvenHeader = documentSection.OddHeader = header;

Aspose.Pdf.Generator.Table headerTable = new Aspose.Pdf.Generator.Table();

headerTable.ColumnWidths = “50% 50%”;

var row1 = headerTable.Rows.Add();
row1.DefaultCellTextInfo.Alignment = AlignmentType.Center;
row1.DefaultCellTextInfo.FontName = “Helvetica-Bold”;
row1.DefaultCellTextInfo.FontSize = 16;

var cell1 = row1.Cells.Add(“Left Aligned Header Text”);
cell1.VerticalAlignment = VerticalAlignmentType.Center;
cell1.Alignment = AlignmentType.Left;

var cell2 = row1.Cells.Add();
cell2.Alignment = AlignmentType.Right;
cell2.VerticalAlignment = VerticalAlignmentType.Center;

Image logo = new Image();
logo.ImageInfo.File = @“C:\dev\path_to_logo.png”;
logo.ImageInfo.ImageFileType = ImageFileType.Png;
logo.ImageInfo.FixWidth = 151;

Text imageContainer = new Text();
Segment imageSegment = new Segment();
imageSegment.InlineParagraph = logo;


string outputPath = Path.GetTempFileName();

As soon as I cut out the highlighted lines, everything works fine. But when they are left in, the pdf.Save(outputPath) call just creates a 0kb file that stays locked.

Hi Ryan,

Thanks for using our products.

I have tested the scenario using the complete code snippet (including lines highlighted in yellow) while using Aspose.Pdf for .NET 7.6.0 over Windows 7 X64 machine where I have used VisualStudio 2010 sample application and as per my observations, the output file is properly being generated. I have referenced the image saved on my local machine.

Can you please share some sample application and details regarding your working environment so that we can again test the scenario at our end. We are sorry for this inconvenience.