Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.

Mon Jan 29, 2024 5:18 pm

Hi Everyone,

.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?

allenprado
 
Posts: 1
Joined: Mon Jan 29, 2024 3:59 pm

Tue Jan 30, 2024 7:33 am

Hello,

Thank you for your inquiry.
Based on your description, I assume that you are using our Spire.PDFViewer and Spire.PDF components. In order to further investigate the issue you mentioned, could you please provide us with a test project that can reproduce the problem? Additionally, it would be helpful if you could provide a screenshot showing the incorrect text receipt on your side. You could attach them here or send them to us via email ([email protected]). Thanks in advance.
By providing these materials, we will be able to analyze the problem more effectively and offer you appropriate solutions.

Sincerely,
Annika
E-iceblue support team
User avatar

Annika.Zhou
 
Posts: 1657
Joined: Wed Apr 07, 2021 2:50 am

Return to Spire.PDF