BoldDesk®Customer service software offering ticketing, live chat, and omnichannel support, starting at $49/mo. for 10 agents. Try it for free.
Hi,
Tried to add printing functionality the standard Zoom and Panning demo ( https://ej2.syncfusion.com/demos/#/material3/diagram/zoom-and-pan.html ) and it somehow does not want to work.
When running it locally, the print dialog comes up, but the page is completely blank. The MS Edge debug panel shows the following message "print-preview.bundle.js:15 This document requires 'TrustedScript' assignment."
Is there something I can do about that?
If I then try to reproduce this in Stackblitz : https://stackblitz.com/edit/zpufk9-9qcy7k?file=index.html,index.ts
The error becomes "This operation is insecure".
Puzzled... answers welcome!
--
Wil
Hi,
The standard Zoom and Panning demo (https://ej2.syncfusion.com/demos/#/material3/diagram/zoom-and-pan.html )
is created with setNodeTemplate property in which the nodes are rendered
as HTML shapes.
In diagram We don’t have support to export/print the native and HTML nodes
in the diagram. So, we are using the advanced Blink rendering engine from
Syncfusion HtmlToPdf convertor library to export the Diagram in Image
Format or as PDF while printing/exporting. We have KB article on how
to implement it. Please refer the KB for guidance.
KB: How to export HTML node using blink rendering in JavaScript
Diagram? (syncfusion.com)
And while exporting with blink rendering, we didn’t encounter any issues
as This document requires 'TrustedScript' assignment" or the
error "This operation is insecure".
Regards,
Moulidharan G
Hi,
If I read that correctly then the blink rendering is server side. Initially when I read your reply I was worried that it would only work on blink based browsers and not on browsers such as Firefox. That should not be an issue.
Creating and installing a .net service -just for printing- is quite a lot of work in order to get printing to work, I understand from your reply that printing does not work when you have custom shapes, such as in the organisation chart from the demo mentioned.
I will look into this.
thanks,
--
Wil
Hi Moulidharan,
I've experimented a bit more with the export features and this - sort of - works for me in my project.
Hi,
As mentioned earlier, there is no workaround to export a diagram without
backend support for Blink rendering for HTML and Native nodes. Additionally, we
could not reproduce the error you described. If you still facing issues, please
provide video demonstration of issue you are facing. To export the entire
content of a diagram, you can adjust the pageSettings.pageHeight and
pageSettings.pageWidth properties to encompass the entire diagram during
the print operation.
We have prepared a sample and included a video demonstration
illustrating how to perform the print action for exporting diagrams with HTML nodes. Kindly use the server-side sample attached in the Knowledge base article. Please refer to the provided sample and video for detailed guidance.
Sample: Oh1qkj
(forked) - StackBlitz
Regards,
Moulidharan
Hello Moulidharan,
Sorry for the delay, had some other things to pursue.
You are correct that the only solution to get a properly rendered printout is to use the webservice.
So I did all that and the webservice works for image export. It does however loose all images.
The org chart that looks like this:
Returns from the webservice like so:
I take it that this is because the images must have a full URL and not a relative URL so that the webservice can actually can retrieve the data.
Probably not a big issue, but undocumented. I hope it doesn't need access to the images via the file system?
The getDiagramContent API documentation mentions that you can add a stylesheetList as parameter. Is there any details on how to fill that parameter? Like is it an array of type string with each item a full URL to the CSS file?
Or does the CSS file need to be accessed over a file system?
(breaking up the reply as the forums software complains that my message is too long)
Then the printing...
The problem there is .. I use the exact same code as from the video and the Knowledge Base article, but it never starts the print dialog. So the image is there.. but it does not print.
fetch(url, options)
.then((response) => {
if (!response.ok) {
throw new Error('Network response was not ok');
}
return response.json();
})
.then((data) => {
console.log('success', data);
//debugger;
let printOptions = {};
let exportOptions = {};
let strImage = "";
exportOptions.format = 'PNG';
exportOptions.mode = 'Data';
exportOptions.region = 'Content';
exportOptions.pageHeight = 1500;
exportOptions.pageWidth = 1500;
exportOptions.stretch = 'None';
printOptions.margin = { left: 0, top: 0, bottom: 0, right: 0 };
diagram.printImage(data.result, printOptions);
console.log('After printImage');
})
.catch((error) => {
console.error('Error:', error);
// Handle errors here
});
and in the console:
FWIW, I'm using syncfusion version 27.2.5
So the very very latest that is available.
thanks,
--
Wil
Hi,
Query |
Response |
Regarding usage of Webservices and images must have a full URL and not a relative URL |
We are glad to hear that the image export and printing options are working fine with the web services. However, we are unable to fully understand your query. Could you please clarify how you are referring to the image URL in your project? Specifically, are you using an online URL or referencing the image from your local project files?
If the image URL is defined correctly and it is rendered properly in the diagram, then while exporting or printing with the generated data from web services, it will always contain the necessary image data. We have not encountered any issues with printing or exporting in such cases.
Please provide more details about the issue you are facing so we can assist you more effectively |
getDiagramContent API documentation styleSheetLIst |
To manually pass stylesheets, create an array of objects with Refer the code – snippet: below |
Print dialog not opened |
The diagram relies directly on the browser's print window to handle printing functionality. Once the necessary data is available, the diagram triggers the print window with that data.
If the print window does not open, please ensure the following:
Your project has permission to access the browser's print functionality. Check if the browser's popup access is blocked. Some browsers block popups by default, so you may need to enable them for your project. If you are still facing issues, kindly provide a video demonstration of the problem for further investigation and assistance |
Code – snippet:
const customStyleSheets = [{ rel='nofollow' href: 'styles1.css' }, { rel='nofollow' href: 'styles2.css' }]; const diagramContent = diagram.getDiagramContent(customStyleSheets); |
Regards,
Moulidharan G
Hello Moulidharan,
Thank you for the answers.
The issue with the images not showing up in the data when exporting as image turned out to be a host configuration issue. I was using a self signed certificate for localhost and the .net service didn't like that.
After switching off https and using http instead that part works fine.
The printImage function however still doesn't work for me.
The irony is that the print function works (but it has its own issues as you are well aware).
I've included a demo zip with pure html/javascript to show the issue.
You still need .net service of course, but I take it that you have that available. Just change the urlhost variable in function getImage and function printImage to use your own .net service.
If you still cannot reproduce the issue with printImage then I can try and make a video.
thanks!
--
Wil
Just to make sure, here's the adjusted webservice source code as well.
Nothing shocking in there, turning off https redirect so I can use it with plain http and a function to read the license code from a file on C:\ and apply that. That's about it.
Oh and updated to the latest components from syncfusion obviously.
--
Wil
Attachment: diagramcoreserverSidesampleprintexport20241210_892a2f03.zip
Hi,
We have replicated the reported behavior where the image export is not functioning correctly in this sample. We are currently validating the issue and will provide an update shortly.
Regards,
Pranoove
Hello Pranoove,
Thank You.
A little bit more background info. The test page was run on http://localhost via IIS, as was the webservice, so not from the file system, and the browser in which I ran the test was Microsoft Edge.
--
Wil
Hi,
After analyzing the sample you provided, we noticed that you removed app.UseHsts(), app.UseHttpsRedirection(), and updated app.UseCors("") to app.UseCors("AllowAllOrigins") to accept HTTP requests instead of HTTPS, as you mentioned.
To allow requests in the .NET service using CORS and permit requests from any origin, you need to ensure that CORS is correctly configured. Using app.UseCors("AllowAllOrigins") indicates that a CORS policy named "AllowAllOrigins" is defined. This policy should be configured earlier in your Startup.cs file in the ConfigureServices method as follows:
public void ConfigureServices(IServiceCollection services) { services.AddControllersWithViews(); services.AddCors(options => { options.AddPolicy("AllowAllOrigins", builder => { builder.AllowAnyOrigin() // Allow all origins .AllowAnyMethod() // Allow all HTTP methods .AllowAnyHeader(); // Allow all headers }); }); } |
Additionally, ensure that the CORS middleware is applied before routing and endpoint configurations in your Startup.cs file:
app.UseCors("AllowAllOrigins"); // Apply CORS policy app.UseRouting(); // Setup routing |
Please make these changes in your application and refer to the provided server-side sample for guidance.
Regards,
Moulidharan G
Hello Moulidharan,
Good tips, thanks.
I did apply all those suggestions then updated the webservice with the new binaries.
Couldn't see how it would make a difference as both webservice as well as test where running from the same localhost. But figured to test it anyways.
Saw it work one time.. then many times not. <confused face>
Restarted the Microsoft Edge browser, with debugging open, with debugging closed.. then it worked another time and again many times not.
Kept on trying and eventually noticed an icon shortly flashing in the top right of the address location bar, really just a half second or so. Not exactly drawing my attention tbh.
Put my mouse over it and .. tada.. the thing you mentioned earlier. "Unable to popup for localhost".. wot? There's no clear indicator of this in MS Edge? I was sure that I had set that in the past to allowed?
So I allowed popups for localhost and from then on the print dialog pops up from the printImage command just fine.
I'm a bit confused as to why a print dialog needs to have a popup dialog enabled.. isn't this a native part of the browser? Why would one need to have to tell the browser to allow the ability to print by enabling popups?
Why would it work one time and then many times not? Smells like a browser bug of some kind.
I'm OK with this as a solution, but it is confusing and will certainly raise questions from end users.
Thanks!
--
Wil
FWIW, for others reading this thread.
That's the indicator that a popup got blocked in MS Edge...
Also see the attached gif.
--
Wil
Hi,
Thanks for the update!
We assume that the behavior of restricting pop-up access multiple times is due to browser-side limitations. Nevertheless, we’re glad that our solution works for you now.
If you need any further assistance, please feel free to reach out to us. We are always happy to help!
Regards,
Moulidharan
Moulidharan
Yes, no idea why the popup, but it is not a real problem.
Sadly I did bump into one more thing, hopefully you can help me with that too.
When I export the org chart in the diagram control as an image, it exports the image completely, no problem.
However when I use printImage it appears to cut off the bottom part and a little bit from the right hand side.
I already tweaked the printoptions a bit and tried things like print to an A3 sized pdf, but it's always missing the same parts.
This should be easy to reproduce using the standalone html page + javascript demo from my reply on December 9 ( https://www.syncfusion.com/downloads/support/forum/195291/ze/printImageproblemdemo20241210_7b5520ca )
The resulted pdf is attached, as well as the Output.jpg that is created for this pdf at the .net webservice side of things.
Thanks,
Wil
Hi,
We have replicated the reported behavior where the exported diagram does not fully contain the diagram elements in the print window correctly. We are currently validating the issue and will provide an update as soon as possible
Regards,
Moulidharan
Thanks Moulidharan,
Thanks for letting me know that you could reproduce the issue.
Hopefully you'll find a solution.
Enjoy your weekend.
--
Wil
Hi,
Please note that the diagram.printImage(data.result, printOptions);
function is used to handle the printing of image data that is typically the
result of the diagram.exportDiagram function. Generally, the printImage
function takes image data and print options to print the diagram. However,
since we are handling HTML nodes and the Base64 string is returned from the
.NET service, the printImage function is not effective.
To overcome this limitation, please use the custom print functionality provided in the sample below.
In the sample, we created a printImages function. The printImages function is designed to handle a Base64-encoded image string, render it in a temporary browser window, and print it. First, it creates an img element with its src attribute set to the Base64 string to ensure the image displays correctly. Once the image is loaded, a new browser window (printWindow) is opened. The function writes a minimal HTML document into the window, embedding the image's HTML (img.outerHTML) within a centered <body> tag to ensure proper alignment for printing. Finally, the window triggers the print() function and closes automatically once the print job is queued.
This approach simplifies the process of printing images directly from Base64 data and ensures compatibility with printing the whole diagram..
Sample: Oh1qkj (forked) - StackBlitz
Regards,
Moulidharan G
Hi Moulidharan,
Thanks for going the extra mile.
That does indeed work perfectly in the demo code I posted previously.
Sadly in my project, the image as generated by the diagram.getDiagramContent(); itself turns out to get cropped.
Not sure why that is yet, but I'll try to see if I can figure out the culprit for that.
To me it seems that it must be something unique to my project and not due to syncfusion.
If I am unable to resolve it, then I might open a new topic as we're not divering quite far from the original issue.
Consider this "case closed".
Thanks again for your extraordinary help.
--
Wil
Right... found two problems on my project.
First in my project I was incorrectly setting the diagram.pageSettings.width and diagram.pageSettings.height.
That was the main issue and certainly not a syncfusion issue.
After removing that, the image was almost there.. sadly it still looked similar to the problem you had solved earlier.
So it cut a little bit from the right and from the bottom.
This then turned out to be due to having the rulers on via diagram.rulerSettings.showRulers set to true.
Having that property set to on caused the getDiagramContent function to clip a bit from the image.
--
Wil
Hi,
When printing a diagram with rulers enabled, the ruler values are included in
the diagram bounds calculation, which can result in the diagram being cut off.
To fix this issue, you can add extra space at the bottom of the diagram by
setting the padding property within the scrollSettings options.
Assign padding values that are double
the default ruler size (default rulerSize is 25) to
ensure sufficient space. Refer to the documentation and the following code
snippet for implementation details:
Documentation: Scroll
settings in EJ2 JavaScript Diagram control | Syncfusion®
scrollSettings:{ padding:{ top:50, left:50, bottom:50, right:50 } }, |
Regards,
Moulidharan G
Hello Moulidharan,
Ah good to know, yes it all makes sense.
For now I worked around the issue by temporarily turning off the rulers if they had been enabled and subsequently issue a refresh, followed by retrieving the DiagramContent and turning the rulers back on again.
Worked without a problem.
--
Wil
Hi Wil Van Antwerpen,
Thank you for the update. Should you require any additional assistance, please do not hesitate to reach out. We are always pleased to support you.
Regards,
Preethi R