Hello Milan,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />
As a workaround you can use table in Header section and set table’s ColumnWidth. Please try using the following code snippet.
[Java]
//Create pdf document
Pdf pdf = new Pdf();
//Add a section into the pdf document
Section sec1 = pdf.getSections().add();
HeaderFooter Header = new HeaderFooter(sec1);
//Set the header of odd pages of the PDF document
sec1.setOddHeader(Header);
//Set the header of even pages of the PDF document
sec1.setEvenHeader(Header);
//Create an image object in the section
com.aspose.pdf.elements.Image img1 = new com.aspose.pdf.elements.Image(sec1);
//Set the path of image file
img1.getImageInfo().setFile("D:/pdftest/tulip.jpg");
// Create a new table
Table pdfTable = new Table(sec1);
//Set the column widths of the table
pdfTable.setColumnWidths("30");
// Add row to Table
Row headerRow = pdfTable.getRows().add();
// create a cell with image object
Cell c = new Cell(pdfTable, img1);
//Add 1st cell in the row
headerRow.getCells().add(c);
// add the text to Paragraphs collection of Header
Header.getParagraphs().add(pdfTable);
FileOutputStream out = new FileOutputStream(new File("d:/pdftest/HeaderShowing_Image.pdf"));
pdf.save(out);
I've test it with Aspose.Pdf for Java 2.4.0.7 which has already been shared at 156384 against "Header&Footer doesn't resize to fit content" or also can be accessed at 159605, please try using it, and in case of any further query, feel free to contact.