apnxmammoth
apnxmammoth
CC#
Created by apnxmammoth on 11/9/2024 in #help
✅ PdfPig
I don't know what I am doing wrong. I am trying to generate a PDF document and attach an image (PNG) to the PDF Document. The problem is that I keep getting an index out of range exception. I did the math, and the points I use for the image coordinates are correct (At least, I am 98% sure). This is what I have:
private const double POINT_VALUE = 2.83465f;
private const double MARGIN = 10 * POINT_VALUE;
private const double PAGE_WIDTH = 60 * POINT_VALUE; // 170.079 points
private const double PAGE_HEIGHT = 108 * POINT_VALUE; // 306.142 points
private const double IMAGE_WIDTH = 40 * POINT_VALUE; // 113.386 points
private const double IMAGE_HEIGHT = 40 * POINT_VALUE; // 113.386 points
private const double IMAGE_X1 = MARGIN;
private const double IMAGE_Y1 = PAGE_HEIGHT - MARGIN - IMAGE_HEIGHT;
private const double IMAGE_X2 = IMAGE_X1 + IMAGE_WIDTH;
private const double IMAGE_Y2 = PAGE_HEIGHT - MARGIN;

public byte[] GeneratePrintableLabel(LogisticsViewModel model)
{
PdfDocumentBuilder builder = new PdfDocumentBuilder();
var fontBytes = File.ReadAllBytes("wwwroot/assets/fonts/la-regular-400.ttf");
var font = builder.AddTrueTypeFont(fontBytes);

var page = builder.AddPage(PAGE_WIDTH, PAGE_HEIGHT);

var qrCodeBytes = GenerateQrCode($"{model.Description}|{model.PalletNumber}|{model.Batch}|{model.Date:dd/MM/yyyy}|{model.Quantity}");

var qrPlacement = new PdfRectangle(IMAGE_X1, IMAGE_Y1, IMAGE_X2, IMAGE_Y2);
page.AddPng(qrCodeBytes, qrPlacement);

page.AddText($"Description: {model.Description}", 12, new PdfPoint(IMAGE_X2 + MARGIN, PAGE_HEIGHT - MARGIN - 20), font);
page.AddText($"Quantity: {model.Quantity}", 12, new PdfPoint(IMAGE_X2 + MARGIN, PAGE_HEIGHT - MARGIN - 40), font);

var pdfDocument = builder.Build();
using (var stream = new MemoryStream())
{
return stream.ToArray();
}
}
private const double POINT_VALUE = 2.83465f;
private const double MARGIN = 10 * POINT_VALUE;
private const double PAGE_WIDTH = 60 * POINT_VALUE; // 170.079 points
private const double PAGE_HEIGHT = 108 * POINT_VALUE; // 306.142 points
private const double IMAGE_WIDTH = 40 * POINT_VALUE; // 113.386 points
private const double IMAGE_HEIGHT = 40 * POINT_VALUE; // 113.386 points
private const double IMAGE_X1 = MARGIN;
private const double IMAGE_Y1 = PAGE_HEIGHT - MARGIN - IMAGE_HEIGHT;
private const double IMAGE_X2 = IMAGE_X1 + IMAGE_WIDTH;
private const double IMAGE_Y2 = PAGE_HEIGHT - MARGIN;

public byte[] GeneratePrintableLabel(LogisticsViewModel model)
{
PdfDocumentBuilder builder = new PdfDocumentBuilder();
var fontBytes = File.ReadAllBytes("wwwroot/assets/fonts/la-regular-400.ttf");
var font = builder.AddTrueTypeFont(fontBytes);

var page = builder.AddPage(PAGE_WIDTH, PAGE_HEIGHT);

var qrCodeBytes = GenerateQrCode($"{model.Description}|{model.PalletNumber}|{model.Batch}|{model.Date:dd/MM/yyyy}|{model.Quantity}");

var qrPlacement = new PdfRectangle(IMAGE_X1, IMAGE_Y1, IMAGE_X2, IMAGE_Y2);
page.AddPng(qrCodeBytes, qrPlacement);

page.AddText($"Description: {model.Description}", 12, new PdfPoint(IMAGE_X2 + MARGIN, PAGE_HEIGHT - MARGIN - 20), font);
page.AddText($"Quantity: {model.Quantity}", 12, new PdfPoint(IMAGE_X2 + MARGIN, PAGE_HEIGHT - MARGIN - 40), font);

var pdfDocument = builder.Build();
using (var stream = new MemoryStream())
{
return stream.ToArray();
}
}
For context: X1 and Y1 = Bottom Left coordinates and X2 and Y2 is top right.
10 replies
CC#
Created by apnxmammoth on 11/2/2024 in #help
.NET MAUI and Android Intents
Hey guys, I hate to be a bother, but I have a bit of a situation, is there anyone here that works with MAUI that could possibly help me? In short... I need to integrate with a phone that has a built in barcode scanner (UROVO DT50), and I managed to find the API documentation, but I for the life of me cannot grasp the concept of intents and how to use them in MAUI.
2 replies