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 Dec 17, 2018 9:46 am

Hi

We have a number of Pdf's that have form field / text position's as they relate to Adobe (that is the Y coordinate is from the lower left corner) whereas Spire.PDF starts its positioning from the top left. Is there a way to position Spire.PDF text / form fields from the lower left?

Also is Spire.PDF thread safe?

Thanks in advance

[email protected]
 
Posts: 5
Joined: Mon Dec 17, 2018 12:40 am

Mon Dec 17, 2018 10:37 am

Hi,

Thank you for your inquiry.
Yes, Spire.PDF has a different origin of coordinates from Adobe Reader.
In Adobe Reader, the origin point is on the left bottom for the whole document, while Spire.PDF is on the left top in the displaying area.
To help us better investigate if there's an approach to reach your goal, could you please share a sample PDF document?
As for issue two, sorry Spire.PDF is not thread-safe.

Sincerely,
Jane
E-iceblue support team
User avatar

Jane.Bai
 
Posts: 1156
Joined: Tue Nov 29, 2016 1:47 am

Mon Dec 17, 2018 11:58 am

Hi Jane

Thanks for the quick reply.
As an example we have approx (more on some) 100 X, Y coordinates in the database upon which to write text onto specific Pdf's. These coordinates are all in the unit of "points" using the adobe (and iTextSharp, plus other competitors) notation (left bottom 0,0).

As a quick and dirty way of doing it I could subtract the page size from the point position to transpose it, but I was hoping you would have a better solution built in.

Thanks

[email protected]
 
Posts: 5
Joined: Mon Dec 17, 2018 12:40 am

Tue Dec 18, 2018 5:25 am

Hi

Does anyone have an answer for this one, do you have a better solution than what I suggested to locate coordinates "correctly" as per adobe documents?

Thanks in advance

[email protected]
 
Posts: 5
Joined: Mon Dec 17, 2018 12:40 am

Tue Dec 18, 2018 7:09 am

Hi,

Sorry for the late reply.
Yes, there's another workaround, that is moving the origin of coordinates from top left to bottom left. Please refer to the code below.
Code: Select all
//load the sample file which you want to write content on
PdfDocument doc = new PdfDocument();
doc.LoadFromFile(input);

PdfPageBase page = doc.Pages[0];
//reset the origin of coordinates
page.Canvas.TranslateTransform(0, page.ActualSize.Height);

//draw content at the adobe-based coordinates
float adobeX = 100;
float adobeY = 100;
PdfFont font = new PdfFont(PdfFontFamily.Helvetica, 10f);
page.Canvas.DrawString("e-iceblue", font, PdfBrushes.Red, new PointF(adobeX, -adobeY));

doc.SaveToFile("DrawTextatAdobeBasedCoordinates.pdf");

Also, the default unit is point.

Sincerely,
Jane
E-iceblue support team
User avatar

Jane.Bai
 
Posts: 1156
Joined: Tue Nov 29, 2016 1:47 am

Tue Dec 18, 2018 10:06 am

Thanks Jane, this did not end up working. I did not get to the bottom of why as I ended up implementing a different solution

Regards

Paul

[email protected]
 
Posts: 5
Joined: Mon Dec 17, 2018 12:40 am

Tue Dec 18, 2018 10:14 am

Hi Paul,

Thank you for your response.
Could you please share your sample PDF document and the code you were using as well as the wrong result to help us look into the issue?

Sincerely,
Jane
E-iceblue support team
User avatar

Jane.Bai
 
Posts: 1156
Joined: Tue Nov 29, 2016 1:47 am

Thu Dec 20, 2018 2:29 am

Hi Jane

We have coordinates of PDF form fields in the database as such (as mentioned there may be hundreds for a single page, the below is just an example of a single field)
FieldName = CertificateNo
FontSize = 10
FontName = Helvetica
PositionX = 611.00
PositionY = 534.00
SizeHeight = 21.00
SizeWidth = 115.00
PositionUnit = Point
PageNumber = 1

(The above field position is in the top right(ish) corner)

Speed (or lack of) was a major issue using FormFields, we have therefore moved to using Canvas.DrawString

Using any existing PDF that has an orientation of landscape, where field below is just an object holding the above position values)

var font = new PdfTrueTypeFont(new System.Drawing.Font(field.FontName, float.Parse(field.FontSize), FontStyle.Regular));
PdfPageBase page = pdfDocument.Pages[field.PageNumber - 1];

Doing this positions the text correctly
PointF pointF = new PointF((float)field.PositionX, page.ActualSize.Height - (float)field.PositionY - (float)field.SizeHeight);
page.Canvas.DrawString(text ?? "", font, new PdfSolidBrush(Color.Black), pointF);

Doing this (ignoring the subtle offset by the field.SizeHeight difference) does not place the text on the form
page.Canvas.TranslateTransform(0, page.ActualSize.Height);
PointF pointF = new PointF((float)field.PositionX, (float)field.PositionY);
page.Canvas.DrawString(text ?? "", font, new PdfSolidBrush(Color.Black), pointF);

Regards
Paul

[email protected]
 
Posts: 5
Joined: Mon Dec 17, 2018 12:40 am

Thu Dec 20, 2018 8:34 am

Hi paul,

Kindly note that I was using negative y coordinate in the code snippet I provided. Although the origin of coordinates has been changed, Spire.PDF would always move from top to bottom in the vertical direction。
So, please change your code
Code: Select all
PointF pointF = new PointF((float)field.PositionX, (float)field.PositionY);

to
Code: Select all
PointF pointF = new PointF((float)field.PositionX, -(float)field.PositionY);


Sincerely,
Jane
E-iceblue support team
User avatar

Jane.Bai
 
Posts: 1156
Joined: Tue Nov 29, 2016 1:47 am

Thu Dec 20, 2018 8:51 am

Hi Jane

I did originally try that as well

Regards

Paul

paul.oshea
 
Posts: 1
Joined: Thu Dec 20, 2018 7:19 am

Thu Dec 20, 2018 9:12 am

Hi Paul,

Without your sample file, I could not reproduce the issue and provide the solution accordingly. On my side, everything works well. I would like to investigate if the incorrect result was affected by other factors.
Please provide the following information.
1. A sample PDF document, if your document is too large, you could create a simple one or just delete some pages as long as the issue could be reproduced.
2. The incorrect result PDF on your side.
3. The whole code related to our product.

Sincerely,
Jane
E-iceblue support team
User avatar

Jane.Bai
 
Posts: 1156
Joined: Tue Nov 29, 2016 1:47 am

Return to Spire.PDF

cron