Printing a barcode in silent mode

I'm using Blazor 18.3.0.48
I need to print a barcode to a label printer in silent mode, but I found only this solution:
I opened a SfDialog with inside a SfPdfViewerServer on a button click
I added in the pdf  a barcode and then I printed it as soon as he document is loaded with the following code:

Is there a way to print the barcode in silent mode? I mean avoiding to show the SfDialog 
Or what is the best practice to print a barcode directly to a print ? Not necessary adding it to a pdf document.

<SfDialog @ref="@Barcodedialog" Width="200px" Visible="false"
          IsModal="true" Header="Codice a barre" ShowCloseIcon="true" EnableResize="true">
    <DialogEvents OnOpen="OnOpen"></DialogEvents>
<SfPdfViewerServer @ref="@viewer" EnableToolbar="false" EnablePrint="true" EnableNavigationToolbar="false">
    <Syncfusion.Blazor.PdfViewer.PdfViewerEvents DocumentLoaded="StartPrint" ></Syncfusion.Blazor.PdfViewer.PdfViewerEvents>
</SfPdfViewerServer> 
</SfDialog>

@code{

    public void OnCommandClicked(CommandClickEventArgs<Utenti> args)
    {
        Barcodedialog.Show();
    }

    public void OnOpen(Syncfusion.Blazor.Popups.BeforeOpenEventArgs args)
    {

        PdfDocument doc = new PdfDocument();
        doc.PageSettings.Size = Syncfusion.Pdf.PdfPageSize.A8;
        doc.PageSettings.Margins.All = 0;
        PdfPage page = doc.Pages.Add();
        PdfCode39Barcode barcode = new PdfCode39Barcode();
        barcode.BarHeight = 45;
        barcode.Location = new PointF(0, 0);
        barcode.Size = new SizeF(58, 30);
        barcode.Text = "2001213";
        barcode.Draw(page, new PointF(2, 2));
        MemoryStream stream = new MemoryStream();
        doc.Save(stream);
        stream.Position = 0;
        doc.Close(true);
        byte[] byteArray = stream.ToArray();
        string base64String = Convert.ToBase64String(byteArray);
        string DocumentPath = "data:application/pdf;base64," + base64String;
        viewer.Load(DocumentPath, null);

    }


    private void StartPrint (Syncfusion.Blazor.PdfViewer.LoadEventArgs args)
    {
        viewer.Print();
    }
}

18 Replies 1 reply marked as answer

AA Akshaya Arivoli Syncfusion Team December 28, 2020 12:14 PM UTC

Hi Walter,   
  
Thank you for contacting Syncfusion support.   
  
Please find the details of your query below,   
  
Query   
Details    
Is there a way to print the barcode in silent mode? I mean avoiding to show the SfDialog    
Currently, we will use the browser default print functionalities for printing the PDF document in our PDF Viewer control. So the browser does not support silent printing (print directly to a local printer). In web technologies, do not support direct printing without additional client-side software because it creates valid security risks.  So we were unable to perform the silent printing on our end.   
 what is the best practice to print a barcode directly to a print? Not necessary to add it to a pdf document.   
We will analyze further on your requirement and update you with more details on December 30, 2020   
  


Regards, 
Akshaya 



WM Walter Martin December 30, 2020 09:34 PM UTC

It would be enough to be able to add a barcode to a pdf or to a word page and print it to a printer without showing the page on the screen.
I can't do that


AA Akshaya Arivoli Syncfusion Team December 31, 2020 02:09 PM UTC

Hi Walter, 

Please find the details from the below, 

Query 
Details 
PDF 
As mentioned earlier, Currently, we will use the browser default print functionalities for printing the PDF document in our PDF Viewer control. So the browser does not support silent printing (print directly to a local printer). In web technologies, do not support direct printing without additional client-side software because it creates valid security risks.  So we were unable to perform the silent printing on our end 
Word  
 
 Barcode in Document editor.  
In Word document we can insert barcode as text by applying barcode font or as image by creating from barcode generators.  
Currently we are working on sample to insert barcode as image to document editor. We will share the sample on or before Jan 5th,2021.  
 
 Silent printing  
We are sorry to let you know that silent printing is not possible in web platforms. As a work around it can be achieved using the browsers settings. Eg. https://stackoverflow.com/questions/36265503/silent-print-from-browser  
 


Regards, 
Akshaya


AA Akshaya Arivoli Syncfusion Team January 6, 2021 07:46 AM UTC

Hi Walter,  

Query: Barcode in Document editor.  

Details: We are facing some difficulties in rendering the image after converting barcode to image using barcode component. We are checking on this and we will provide sample by January 7th,2021.  

Regards, 
Akshaya  



WM Walter Martin January 6, 2021 09:58 AM UTC

I have the same difficulties I think, it' three days I'm trying to find a solution to this problem unsuccessfully.
Just to give you more details, I have a grid where I added a commandcolumn to open a dialog with inside the barcode generated by "barcode generator" with the information of the grid key column.
My best solution would be to add the barcode generated and exported as image inside a Word (or pdf ) document and then print it to a barcode label printer where I can use two label size (62 x 50 mm and 29 x 90 mm) 
I managed to add the barcode exported as image in a word document but waiting for too much processes (I mean I need a click to generate it, a click to export it as image, and another button click to add it to the document and print it)
After loading it in the Word document, I managed to remove the Word toolbar but not the right side panel with the size and font selection because I don't need them and also I'm not able to rotate the barcode image of 90 degrees to fit it in my label size.
I hope you'll find a solution
Thanks


SM Suriya Murugan Syncfusion Team January 7, 2021 12:42 PM UTC

Hi Walter, 
 
Thanks for your response. 
 
We need some additional information regarding your requirement.  
 
According to your requirement,  
1.      Do you want to generate barcode as image and print it in label ? You want to view the generated barcode label in any viewer or editor?  
2.      We have our syncfusion library to generate barcode label in back end?Whether this will satify your requirement. 
 
In DocumentEditor, we don’t have support to rotate the image to 90 degree. 
 
Can you please provide details regarding above details that will helpful for us to proceed further? 
 
Regards, 
 
Suriya M. 



WM Walter Martin January 7, 2021 01:06 PM UTC

Hello Suriya
these my requirements:
1) yes, I need exactly to generate a barcode and print it in a label. I don't need to show the barcode in the web page but I supposed it was necessary to add it in an editor to be able to customize the margins and the position in the document to fit it in the label.

2) i didn't see this library but it seems to be what I need. I'm working with Blazor version 18.3.0.53 so if you can suggest me the use of this library it would be wonderful

Thanks
Best Regards



SM Suriya Murugan Syncfusion Team January 8, 2021 01:59 PM UTC

Hi Walter, 

Currently, we are working on Barcode label generator using Syncfusion DocIO library in blazor. We will update you sample by January 11th,2021. 
 
Regards, 
Suriya M. 



SM Suriya Murugan Syncfusion Team January 12, 2021 03:49 AM UTC

Hi Walter, 
 
 
Sorry for the inconvenient caused. 
 
 
We have checked your requirement in Syncfusion DocIO but facing some difficulties to achieve it.  
 
 
We will update your further details by January 12th,2021. 
 
 
 
 
Regards, 
 
Suriya M. 



WM Walter Martin January 12, 2021 08:30 AM UTC

For your information I'm now using version 18.4.0.33 but I still can't find a solution by myself

Thanks
Regards


KB Kurthis Banu Abdul Majeeth Syncfusion Team January 13, 2021 04:39 PM UTC

Hi Walter,    
  
We have planned to achieve the requested scenario with the help of Syncfusion DocIO but DocIO in blazor environment does not have support to achieve this completely.  
  
We have tried below to insert barcode and then to customize and print options we have check further details on or before January 18th,2021.  
  
Please refer the below example link:   
  
  
Please let us know if you have any other questions.  
  
Regards, 
  
Kurthis Banu A. 



WM Walter Martin January 13, 2021 10:16 PM UTC

Thank you, I managed to print a barcode in my label printer using your sample, I'm using the Blazor Server version 18.4.0.33
I need to know some other information because I can't fit the barcode in the document size.

1) Is it possible to set margins = 0 in the documentmodule ? (just to place the barcode close to the document boundaries) 
2) Is it possible to use the barcodegenerator to add the barcode in a pdf document as  an image where I can maybe rotate the image of 90 degrees?


 




KB Kurthis Banu Abdul Majeeth Syncfusion Team January 18, 2021 02:25 PM UTC

Hi Walter, 
  
We are started working on this sample. We will provide the sample and update the details Jan 19, 2021.   
  
Regards, 
  
Kurthis Banu A. 



SM Suriya Murugan Syncfusion Team January 19, 2021 12:21 PM UTC

Hi Walter, 
Thank you for your patience. 
To achieve your requirement, we suggest you get the barcode images from SfBarcodeGenerator control and insert into Word document using Syncfusion Word library (Essential DocIO). Then rotate the image and convert into PDF using DocIO. We have prepared the sample application for the same and it can be downloaded from the below link along with the output generated from the sample: 
 
 
Note: Earlier sample is Blazor Client side. We have modified as Server side sample due to limitation of SkiaSharp library in Client side for Word to PDF conversion process.

In the above sample, we have done the below things:
 
1.      Create Word document using DocIO with requirement page settings (zero margins) when inserting first barcode. 
2.      Get barcode as image from SfBarcodeGenerator. 
3.      Appends the image into Word document and rotate to 90 degree. 
4.      Appends the rotated barcode images whenever inserting new barcodes. 
5.      Converts to PDF (when click Convert to PDF button). 
6.      Saves the resultant PDF document. 
Note: If you wish to view the Word document intermediately using Document Editor, it doesn’t support image rotation (already known feature) so, you may face preservation difference in the document in viewer. 
 
Regards, 
 
Suriya M. 



WM Walter Martin January 20, 2021 08:58 AM UTC

Many thanks for your support and sample solution
I propose you in attachment a different approach using only a RichTextBox component where I can even rotate the barcode by 90 degrees
In my solution I'd like to avoid to show the richtextbox on the screen because my target is only to print it on a label printer so it would be enough to show it with the barcodegenerator  but I think it's not possible to hide the richtextbox if I want to print it.

Thanks


Attachment: RichTextBox_79aab5fe.zip


SM Suriya Murugan Syncfusion Team January 21, 2021 10:51 AM UTC

Hi Walter, 

We have validated the query “To hide the Rich Text Editor inside the Dialog before print barcode”.  
  
This can be done by setting the ‘Height’ and ‘Width’ property to 0, and then setting the `HtmlAttributes` with styles as `display: none` where this will hide the Rich Text Editor completely from the Dialog before print.  
  
Code Snippet:  
<SfRichTextEditor @ref="rtb" Value="@contenutortb" Width="0" Height="0" HtmlAttributes="@CustomAttributes">  
                <RichTextEditorToolbarSettings Enable="false" Items="@Tools" />  
            </SfRichTextEditor>  
  
Dictionary<string, object> CustomAttributes = new Dictionary<string, object>() {  
        {"style", "display: none;" }  
    };  
  
We have modified the sample for your reference,  
  

Regards, 

Suriya M. 


Marked as answer

WM Walter Martin January 23, 2021 12:17 AM UTC

Many thanks Suriya
your suggestion works perfectly



SM Suriya Murugan Syncfusion Team January 24, 2021 03:41 PM UTC

Hi Walter, 

Thanks for your update. 
 
Regards, 
 
Suriya M. 


Loader.
Up arrow icon