.net Code.
I am using the PDF.JS to load a pdf and into the canvas, the user can double click in the canvas and type a message.
The solution get the mouse position and send to spire class to convert it to the PDF coordinates.
PDF.JS Mouse position
- Code: Select all
function getMousePosition(e) {
var bx = canvas.getBoundingClientRect();
textX = (e.changedTouches ? e.changedTouches[0].clientX : e.clientX) - bx.left;
textY = (e.changedTouches ? e.changedTouches[0].clientY : e.clientY) - bx.top;
}
SPIRE.PDF C# CONVERSION
- Code: Select all
private async Task<TextBoxes> CalcTextBoxPosition(TextBoxes textBox)
{
try
{
PdfUnitConvertor converter = new PdfUnitConvertor();
textBox.X = converter.ConvertUnits(textBox.X, PdfGraphicsUnit.Pixel, PdfGraphicsUnit.Point);
textBox.Y = converter.ConvertUnits(textBox.Y, PdfGraphicsUnit.Pixel, PdfGraphicsUnit.Point);
return textBox;
}
catch (Exception ex)
{
return textBox;
}
}
var textBoxCrv = await this.CalcTextBoxPosition(textBox, canvasConfig);
page.Canvas.DrawString(textBoxCrv.Text, fontTextBoxes, PdfBrushes.Black, textBoxCrv.X, textBoxCrv.Y);
but the spire still print the text in the wrong position. is there something wrong that I am doing?