ImageEditor: Print

2 Answers 103 Views
ImageEditor
Joel
Top achievements
Rank 2
Iron
Iron
Iron
Joel asked on 04 May 2022, 05:12 PM | edited on 04 May 2022, 05:25 PM
How do I print from the image editor?  To open a broader discussion... do I need to pull the image then wrap it in a PDF in order to print?  If so, how?

2 Answers, 1 is accepted

Sort by
0
Tsvetomir
Telerik team
answered on 09 May 2022, 07:48 AM

Hi Joel,

Telerik UI for ASP.NET Core comes with a set of predefined methods and components that can be used to export content to an image, PDF, or SVG. More information on how to prepare the HTML and export it to PDF, take a look at the following example:

https://demos.telerik.com/aspnet-core/pdf-export

It works with any HTML elements, therefore, you could pass the correct selector for the image editor and the saveAs method should download a PDF with the respective image. 

 

Kind regards,
Tsvetomir
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Joel
Top achievements
Rank 2
Iron
Iron
Iron
commented on 17 May 2022, 03:47 PM

So... that is good export functionality.  However, I was asking about printing the PNG file that is loaded into your ImageEditor control.  Exporting to PDF in order to Print was just a rabbit trail I provided.
0
Aleksandar
Telerik team
answered on 20 May 2022, 08:32 AM

Hi Joel,

You can create a custom command for the ImageEditor to print images. There are numerous solutions on how to print an image, for example this SO thread discusses available options.

That said, you can define a Print command and print an image the following way:

<script>
     var imageEditorNS = kendo.ui.imageeditor;

        imageEditorNS.commands.PrintImageEditorCommand = imageEditorNS.ImageEditorCommand.extend({
          exec: function () {
            var that = this,
                options = that.options,
                imageeditor = that.imageeditor,
                canvas = imageeditor.getCanvasElement(),
                ctx = imageeditor.getCurrent2dContext(),
                image = imageeditor.getCurrentImage();

            var win = window.open('about:blank', "_new");
            win.document.open();
            win.document.write([
              '<html>',
              '   <head>',
              '   </head>',
              '   <body onload="window.print()" onafterprint="window.close()">',
              '       <img src="' + image.src + '"/>',
              '   </body>',
              '</html>'
            ].join(''));
            win.document.close();
          }
        });
</script>

<div class="demo-section wide">
    @(Html.Kendo().ImageEditor()
        .Name("imageEditor")
        .Height(900)
        .SaveAs(s => s.FileName("image_edited.png"))
        .Toolbar(toolbar=>toolbar.Items(i=> {
            i.Add().Name("open");
            i.Add().Name("save");
            i.Add().Name("resize");
            i.Add().Name("crop");
            i.Add().Name("undo");
            i.Add().Name("redo");
            i.Add().Name("zoomIn");
            i.Add().Name("zoomOut");
            i.Add().Name("zoomDropdown");
            i.Add().Command("PrintImageEditorCommand").Type("button").Text("Print").Icon("print");
        }))
    )
</div>

Here is a sample REPL.

Regards,
Aleksandar
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Tags
ImageEditor
Asked by
Joel
Top achievements
Rank 2
Iron
Iron
Iron
Answers by
Tsvetomir
Telerik team
Aleksandar
Telerik team
Share this question
or