Send raw data to print not working

前端 未结 5 861
春和景丽
春和景丽 2020-12-20 04:33

I want to send raw data to print, avoiding printer selection (fast print).

I am trying to use this helper provided by Microsoft: https://support.microsoft.com/en-us/

5条回答
  •  粉色の甜心
    2020-12-20 05:24

    In cases where you are using the MSDN example from here https://support.microsoft.com/en-us/kb/322091#top but are trying to use an array of bytes instead of a string or file... This may help

    public static void SendBytesToLocalPrinter(byte[] data, string printerName)
    {
       var size = Marshal.SizeOf(data[0]) * data.Length;
       var pBytes = Marshal.AllocHGlobal(size);
       try
       {
          SendBytesToPrinter(printerName, pBytes, size);
       }
       finally
       {
          Marshal.FreeCoTaskMem(pBytes);
       }
    }
    

    This does not change with the byte array encoding. This is useful if you are trying to send some utf8 encoded byte sequences with some binary (ie. image) data mixed in as was the case for our team.

提交回复
热议问题