Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Need assistance in understanding TransformRotate() #20

Closed
wneessen opened this issue Apr 28, 2022 · 1 comment
Closed

Need assistance in understanding TransformRotate() #20

wneessen opened this issue Apr 28, 2022 · 1 comment

Comments

@wneessen
Copy link

Hi,

I am currently trying to rotate a block of text vertically in my PDF document and I have a hard time to understand how TransformRoate() operates - especially how to position the rotated element on my page. It seems that the X and Y parameters work in a different way that I would expect it.

Here is some example code I wrote:

func main() {
	pdf := fpdf.New("P", "mm", "A4", "")
	pdf.AddUTF8Font("opensans", "", "OpenSans-Regular.ttf")
	pdf.AddUTF8Font("opensans", "B", "OpenSans-Bold.ttf")
	pdf.AddUTF8Font("opensans", "I", "OpenSans-Italic.ttf")
	pdf.AddUTF8Font("opensans", "BI", "OpenSans-BoldItalic.ttf")
	pdf.AddPage()
	pdf.SetFont("opensans", "", 10)

	for i := 0.0; i <= 90; i = i + 10 {
		pdf.AddLayer(fmt.Sprintf("%f", i), true)
		pdf.SetXY(210.0/2, 297.0/2)
		pdf.TransformBegin()
		pdf.TransformRotate(i, 0, 0)
		pdf.CellFormat(0, 5, fmt.Sprintf("Angel: %f", i), "", 0, "", false, 0, "")
		pdf.TransformEnd()
	}
	if err := pdf.OutputFileAndClose("hello.pdf"); err != nil {
		fmt.Printf("error generating PDF: %s\n", err)
		os.Exit(1)
	}
}

I would expect that I have a piece of text that is starting centered on the page and is rotated from there in 10° increments. But in reallity it seem that the text is skewed in some weird way, even though the X and Y parameters are always 0. The result looks like this:

image

Does anybody has some advice or pointer to what I am doing wrong? As final goal I'd like to position vertical text boxes and a QR code in the upper left corner of the document, but given that I am basically blindly guessing right now where the rotated element would end up, I am not getting reliable re-producable results.

Any assistance is highly appreciated.

@wneessen
Copy link
Author

Hi again,

I believe I was able to figure it out by now. I think my error was to think that the pdf.SetXY(210.0/2, 297.0/2) would be enough to manifest the position of the transformed element and I should use 0 as value for X and Y in the TransformRotate(). When I specify the same XY coordinates in the TransformRotate() the result looks like what I was looking for. Sorry for the confusion.
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant