Articles in this section
Category / Section

How to Customize Header and Footer in Diagram Printing

4 mins read

Headers and footers, located in the top and bottom margins of each page, respectively, are essential elements in document formatting. When the header and footer option is enabled in the print dialog box, these sections become visible.

The diagram offers the capability to export its content, with the client-side method exportDiagram facilitating this process.

Customizing the header and footer involves adding personalized content, including elements like time, date, or even adjusting the position of the content within the header and footer. This customization occurs in the print window. Refer to the code snippet below to understand how to achieve custom printing while exporting the diagram using exportDiagram.

 

Note:
To use Print and Export, you need to inject PrintAndExport in the diagram.

 

function toolbarClick(args: ClickEventArgs): void {
if (args.item.text === 'Print') {
var image;
var options: IExportOptions = {};
options.mode = 'Data';
options.region = 'Content';
options.pageOrientation = 'Portrait';
options.multiplePage = false;
image = diagram.exportDiagram(options);
printImages(image, options);
    }
}


function printImages(url: any, options: any) {
var _this: any = diagram.printandExportModule;
var attr = {
id: diagram.element.id + '_printImage',
src: url
    };
options.margin = { top: 0, bottom: 0, right: 0, left: 0 };
var img = createHtmlElement('img', attr);
img.onload = function() {
var div = _this.getMultipleImage(img, options);
var printWind = window.open('');
if (printWind != null) {
if (div instanceof HTMLElement) {
printWind.document.write(
'<html><head><style> @page { size: auto;  margin: 0mm; } 
body{margin:0px;} div.parent {  position: relative; } div.upper {  position: absolute;left: 50%;top: 0%;}  div.absolute {  position: absolute;left: 50%;bottom: 0%;} </style>
//customised header
<div class=upper>Syncfusion Diagram control</div>

//customised Footer
<div class=absolute >Page No: 1</div></head></html>'
          );
printWind.document.write(
'<BODY onload="setTimeout(function(){window.print();}, 100)">'
          );
printWind.document.write('<center>' + div.innerHTML + '</center>');
printWind.document.close();
        }
      }
    };
  }

 

The default date and page number can be prevented by adding the following content in CSS or in Style

<style>

@page { size: auto;  margin: 0mm; }

</style>

 

 

Sample Linkhttps://stackblitz.com/edit/gwdipf?file=index.ts



Conclusion
I hope you enjoyed learning about how to do custom printing.
You can refer to our JavaScript Diagram feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications. You can also explore our JavaScript Diagram example to understand how to create and manipulate data.
For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion®, you can try our 30-day free trial to check out our other controls.
If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forumsDirect-Trac, or feedback portal. We are always happy to assist you!



Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied