PDFsharp & MigraDoc Foundation

Cannot generate Matrix Code/QR code on PDF using PDFSharp
Page 1 of 1

Author:  chanandrew96 [ Wed Apr 01, 2020 2:16 pm ]
Post subject:  Cannot generate Matrix Code/QR code on PDF using PDFSharp

I import the PDFSharp 1.50.5147 version using NuGet and tried to generate the matrix code using the code below

var myXSize = new XSize(130, 130);
var myNewCode = new PdfSharp.Drawing.BarCodes.CodeDataMatrix("Content", 144, myXSize);
var myXPoint = new XPoint(630, 50);
//gfx.DrawMatrixCode(myNewCode, myXPoint);

But when I execute the code it return error "Value cannot be null. Parameter name: image" as below:

[ArgumentNullException: Value cannot be null.
Parameter name: image]
   PdfSharp.Drawing.XGraphics.DrawImage(XImage image, Double x, Double y, Double width, Double height) +174
   PdfSharp.Drawing.BarCodes.CodeDataMatrix.Render(XGraphics gfx, XBrush brush, XPoint position) +2637
   PdfSharp.Drawing.XGraphics.DrawMatrixCode(MatrixCode matrixcode, XPoint position) +147
   learners.pages.Class.ViewCompletedAssessment.btnDownloadCert_Click(Object sender, EventArgs e) in E:\Inetpub\wwwroot\learners\learners\pages\Class\ViewCompletedAssessment.aspx.cs:181
   System.Web.UI.WebControls.Button.OnClick(EventArgs e) +11758656
   System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +150
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5028

It seems that the "DrawMatrixCode" function will call "DrawImage" function and I dig the source code and found it should run the code below:

if (MatrixImage == null)
                MatrixImage = DataMatrixImage.GenerateMatrixImage(Text, Encoding, Rows, Columns);

However, it seems that the image is not generated. Does anyone can come up with some advise?

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group