Search code examples
javascriptphppdftron

PDFTron draw text sideways


For my specific purpose user draw rectangle annotation on web viewer and later on replace that with Free-Text in the place of Rectangle annotation.

enter image description here

As you can see in above image i have added one rectangle. Now i am using below code to replace that rect annot with free text.

$text = FreeText::Create($pdf->GetSDFDoc(), new Rect( 440.0, 581.89, 454.0, 781.89));
$text->SetContents("The quick brown fox - 2");
$text->SetTextColor(new ColorPt(0.0, 0.0, 0.0), 3);
$text->SetOpacity(1.0);
$text->RefreshAppearance();
$page->AnnotPushBack($text);

enter image description here

FYI - i am getting: 440.0, 581.89, 454.0, 781.89 from DB using GetRect() method. I have saved annotation in DB. As you can see in above image replaced text is sideways.

So how to fix font sideways issue if page is horizontal?


Solution

  • Annotations have rotation property. Rotation value is relative to documents upright position. In your case upright position of document is rotated counter clockwise 90 degrees.

    So when you are creating your free text annotation you need to set rotation value correctly, I believe in your case it would be 270.