Problema ao gerar imagem QrCode com API Google

Olá pessoal,

Estou tentando gerar no relatório fastreport .net um QrCode usando a api Google. A imagem é gerada mas não está trazendo o link completo. Vou postar aqui a forma como estou salvando no banco de dados e como estou chamando no relatório. I use version 1.2.47 of fastreport .net and I use Visual Studio 2015..

VB Code:

Private Sub PercorreGrid()

    Dim Gi As DataGridItem

    Dim pHfID As WebControls.HiddenField

    Dim pLink As WebControls.HyperLink

    Dim pUrl As String

    For Each Gi In Datagrid1.Items

      pHfID = Gi.Cells(3).FindControl("hfIDItem")

      pLink = Gi.Cells(3).FindControl("gLinkprivado")

'pLink should return: http://web.centec.org.br/sisgeti/privado/index.aspx?&id=3D1T43E45ED8802BA23186898962C124F7E3

      pUrl = Server.UrlEncode(pLink.Text)

'As I am using the Server.UrlEncode function, the link is returning: http%3a%2f%2fweb.centec.org.br%2fsisgeti%2fprivado%2findex.aspx%3f%26id%3d3D1T43E45ED8802BA23186898962C124F7E3

      EditalItens.ExecutaSQLGenerica("UPDATE EDITALITENS SET " &

                      " LINKQRCODEITEM = '" & pUrl & "' WHERE ID = " & pHfID.Value)

    Next

  End Sub

Code in fastreport .net:

In the report, also using VB, the code looks like this:

Imports System

Imports System.Collections

Imports System.Collections.Generic

Imports System.ComponentModel

Imports System.Windows.Forms

Imports System.Drawing

Imports Microsoft.VisualBasic

Imports FastReport

Imports FastReport.Data

Imports FastReport.Dialog

Imports FastReport.Table

Imports FastReport.Barcode

Imports FastReport.Utils


Namespace FastReport

 Public Class ReportScript

  Private Sub Child2_BeforePrint(ByVal sender As object, ByVal e As EventArgs)

   If CType(Report.GetColumnValue("sdsDados.QRCODECOMPLETO"), String) <> "" Then

      imgQrCode.ImageLocation = "https://chart.googleapis.com/chart?chs=150x150&cht=qr&chl=" & CType(Report.GetColumnValue("sdsDados.QRCODECOMPLETO"), String)

It turns out that the QrCode is created but the link is incomplete. When reading the QRCode, the candidate is taken to this link: http://web.centec.org.br/sisgeti/privado/index.aspx? leaving the whole part of the parameter &id=3D1T43E45ED8802BA23186898962C124F7E3

   imgQrCode.Visible = True  

    Else

    If CType(Report.GetColumnValue("sdsDados.QRCODECOMPLETO"), String) = "" Then

     imgQrCode.Visible = False

    End if

   End if

      

  End Sub

 End Class

End Namespace


How can I solve this problem?

Grateful

Ilano

Comments

  • Guys, the version I use doesn't have a QrCode component, so I'm trying to generate my QrCode in an image component using the Google Api. On a normal page it works, but in the report, despite generating the QrCode, it is as if the link did not complete, that is, the link to generate the QrCode should be:

    http://web.centec.org.br/sisgeti/privado/index.aspx?&id=3D1T43E45ED8802BA23186898962C124F7E3

    But it only generates:

    http://web.centec.org.br/sisgeti/privado/index.aspx?

    How can I resolve this?

  • Hello!

    In FastReport .NET, there is no need to call external HTTP services — simply use the built-in `BarcodeObject` with the `BarcodeQR` type:

    var qr = new BarcodeObject
    {
    Barcode = new BarcodeQR(),
        Text = ‘https://example.com/pay?order=123&currency=BRL’
    };
    

    If, for any reason, you need to pass a URL as an embedded parameter within another URL, escape it first using Uri.EscapeDataString(url).

This discussion has been closed.