【问题标题】:How to print Generated Barcode ZXING in xamarin forms如何以 xamarin 形式打印生成的条码 ZXING
【发布时间】:2021-03-03 04:40:58
【问题描述】:

我设法使用 ZXING 库生成了条码,现在我想打印生成的条码,因为它来自 ZXingBarcodeImageView,大小相同,我该怎么做

private async Task<Item>  getItem()
    {

        HttpResponseMessage _response = await _client.GetAsync(url + txt_Barcode.Text);

        if (_response.IsSuccessStatusCode)
        {
            
            string itemDetailes = await _response.Content.ReadAsStringAsync();

            return JsonConvert.DeserializeObject<Item>(itemDetailes);
             
        }
        return new Item();
    }
    private async void Btn_GetInfo(object sender, EventArgs e)
    {
       var selected_item = await getItem();
       
       // Item_barcode.Text = selected_item.Value;
        Item_Description.Text = selected_item.Description;
        Item_name.Text = selected_item.Name;
        Item_price.Text = selected_item.Price.ToString();
        item_barcode.BarcodeValue = selected_item.Value;
    }

xml 代码

        <!--<Image HeightRequest="300" WidthRequest="300" Margin="1" x:Name="img_barcode"></Image>-->
        <zxing:ZXingBarcodeImageView x:Name="item_barcode" HeightRequest="20" WidthRequest="100" BarcodeFormat="CODE_39" BarcodeValue="Place Barcode" >
        <zxing:ZXingBarcodeImageView.BarcodeOptions>
              <zxingcomon:EncodingOptions Height="80" Width="1000"></zxingcomon:EncodingOptions>
            </zxing:ZXingBarcodeImageView.BarcodeOptions>
            
        </zxing:ZXingBarcodeImageView>
        <StackLayout Orientation="Horizontal" Spacing="20" >

            <Label TextColor="Black" x:Name="Item_Description"></Label>
            <Label TextColor="Black" x:Name="Item_price"></Label>
        </StackLayout>
        <StackLayout  x:Name="SLPrint" BackgroundColor="GhostWhite" VerticalOptions="FillAndExpand">
            <Button Text="print" BackgroundColor="Black" TextColor="White"></Button>
        </StackLayout>
    </StackLayout>
 
</StackLayout>

【问题讨论】:

  • 您的意思是“打印”到物理打印机吗?

标签: c# xamarin xamarin.forms zxing


【解决方案1】:

最好和最简单的选择是在 webview 中显示条形码。 这是一个你可以使用的库Link

您可以将脚本复制到资产文件夹中。创建一个html文件导入脚本

现在从 xamarin 端在 webview 中评估 javascript,您可以将条形码数据发送到 webview 这是你可以做到的。 Link

注意:您不需要进行任何自定义渲染

这样你可以移除 zxing 并且可以让你的应用变小

【讨论】:

    猜你喜欢
    • 2016-08-02
    • 2018-06-29
    • 1970-01-01
    • 2014-04-17
    • 2019-08-15
    • 2023-02-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多