I’m generating a very simple PDF that includes a PNG image in the header by following the example here: Add Header and Footer to PDF|Aspose.PDF for .NET
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();
this._Header.Paragraphs.Add(headerTable);
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;
imageContainer.Segments.Add(imageSegment);
cell2.Paragraphs.Add(imageContainer);
string outputPath = Path.GetTempFileName();
pdf.Save(outputPath);
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.