How to customize header and footer in React Diagram printing?
This article explains how to customize the header and footer in React Diagram printing. 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 React 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(
' //customised header
<div class="upper">Syncfusion Diagram control</div>
//customised Footer
<div class="absolute">Page No: 1</div>'
);
printWind.document.write(
''
);
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
```js
<style>
@page { size: auto; margin: 0mm; }
</style>
Refer to the working sample for additional details and implementation: sample
Conclusion
We hope you enjoyed learning about how to customize header and footer in React Diagram printing.
You can refer to our React Diagram feature tour page to know about its other groundbreaking feature representations and documentation. You can also explore our React Diagram example to understand how to present 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 React Spreadsheet and other components.
If you have any queries or require clarifications, please let us know in the comments below. You can also contact us through our support forums, BoldDesk Support, or feedback portal. We are always happy to assist you!