ststeiger / PdfSharpCore

Port of the PdfSharp library to .NET Core - largely removed GDI+ (only missing GetFontData - which can be replaced with freetype2)
Other
1.05k stars 234 forks source link

XGraphics.DrawMatrixCode fails with inappropriate error message #361

Open StepKie opened 1 year ago

StepKie commented 1 year ago

Somebody created this issue here, and I have the exact same issue when trying to draw a QR code image onto a pdf document:

https://forum.pdfsharp.net/viewtopic.php?f=2&t=4121

My code is basically the same:

string qrString = GetStringForQr(sample);
CodeDataMatrix qrCode = new CodeDataMatrix(qrString, , qrString.Length);
page.DrawMatrixCode(qrCode, QrCodeLocation);

The last line will throw

System.ArgumentNullException : Value cannot be null. (Parameter 'image')

Stack Trace: 
XGraphics.DrawImage(XImage image, Double x, Double y, Double width, Double height)
CodeDataMatrix.Render(XGraphics gfx, XBrush brush, XPoint position)
XGraphics.DrawMatrixCode(MatrixCode matrixcode, XPoint position)

, though the argument is obviously not null (can be verified with debugger).

amerlin commented 1 year ago

I have also the same problem. There is a solution? Thanks

psycrush commented 1 year ago

I have the same problem. When debugging I saw that the following method always returns null. I guess this is not a bug but not implemented at all.

PdfSharpCore/Drawing.BarCodes/DataMatrixImage.opensource.cs Line 179:

/// <summary>
/// Creates a DataMatrix image object.
/// </summary>
public XImage CreateImage(char[] code, int rows, int columns, int pixelsize)
{
    return null;
}
StepKie commented 11 months ago

https://github.com/ststeiger/PdfSharpCore/blob/c918cbf79c0f6c0e13d71fee551286357140b665/PdfSharpCore/Drawing.BarCodes/DataMatrixImage.opensource.cs#L181

@ststeiger Any possibility to fix this? Thanks...