Free Support Forum - aspose.com

Header not working for all formats

Hi Team,

i tried header food example but it is not working on all the formats. our business requirement is to have left header with some information about the diagram but it doesn’t work in all the formats. please see the below code sample for the same and attached Drawing1.vsdx fileDrawing1.zip (22.9 KB)
.

	String dataDir = Utils.getSharedDataDir(ManageHeadersandFooters.class) + "HeadersFooters/";
	
	String licenseFileDir = Utils.getSharedDataDir(ManageHeadersandFooters.class);
	String licenseFile = licenseFileDir+"Aspose.Diagram.lic";
	com.aspose.diagram.License license = new com.aspose.diagram.License();
	license.setLicense(licenseFile);

	
	// call the diagram constructor to a load Visio diagram
	Diagram diagram = new Diagram(dataDir + "Drawing1.vsdx");

	// add page number at the right corner of header
	diagram.getHeaderFooter().setHeaderRight("&p");

	// set text at the center
	diagram.getHeaderFooter().setHeaderCenter("Center of the header");

	// set text at the left side
	diagram.getHeaderFooter().setHeaderLeft("Left of the header");

	// add text at the right corner of footer
	diagram.getHeaderFooter().setFooterRight("Right of the footer");

	// set text at the center
	diagram.getHeaderFooter().setFooterCenter("Center of the footer");

	// set text at the left side
	diagram.getHeaderFooter().setFooterLeft("Left of the footer");

	// set header & footer color
	diagram.getHeaderFooter().setHeaderFooterColor(Color.getRed());

	// set text font properties
	diagram.getHeaderFooter().getHeaderFooterFont().setItalic(BOOL.TRUE);
	diagram.getHeaderFooter().getHeaderFooterFont().setUnderline(BOOL.FALSE);

	// save Visio diagram
	diagram.save(dataDir + "EditConnectorGeometry_Out.pdf", SaveFileFormat.PDF);

@jitushrivastava

We have tested the scenario in our environment and were able to notice that header/footer was not present in the output PDF, PNG and HTML formats. However, we are further checking it and will get back to you soon with our feedback.

Hi @asad.ali, do we have any ETA on the same? if it will take more than this week time then can you please help me put the text box in the top left header with some information in it. we have a demo coming monday next week and we have to show some information. also we need this text to be printed in all the formats.

@jitushrivastava

We have noticed that there is an issue with the API that it was not preserving header/footer while exporting diagram to other file formats. We have logged an issue as DIAGRAMJAVA-50701 in our issue tracking system for it and will further work over its fix. Please spare us some time.

You may please use following code snippet to add text inside a diagram. You can please change/adjust the values of PinX and PinY in order to position the text as per your desire:

com.aspose.diagram.Diagram diagram = new com.aspose.diagram.Diagram(dataDir + "Drawing1.vsdx");

double PinX = 1, PinY = 1, Width = 1, Height = 1;
String text = "Test text";
// add text to a Visio page
diagram.getPages().getPage(0).addText(PinX, PinY, Width, Height, text);
// save diagram
diagram.save(dataDir + "InsertTextShape_out.vsdx", SaveFileFormat.VSDX);

Hi @asad.ali,
I tried the code you provided. it works with visio format but as soon as you will try with pdf or any other format this code throws a nullpointerexception.

@jitushrivastava

Please reinitialize Diagram object with saved Diagram and then save it to any other format like following:

diagram.save(dataDir + "ditConnectorGeometry_Out.vsdx", SaveFileFormat.VSDX);
diagram = new com.aspose.diagram.Diagram(dataDir + "ditConnectorGeometry_Out.vsdx");
com.aspose.diagram.PdfSaveOptions options = new com.aspose.diagram.PdfSaveOptions();
diagram.save(dataDir + "output.pdf", options);