Print Page | Close Window

Centering text not working.. why??

Printed From: Debenu Quick PDF Library - PDF SDK Community Forum
Category: For Users of the Library
Forum Name: I need help - I can help
Forum Description: Problems and solutions while programming with the Debenu Quick PDF Library and Debenu PDF Viewer SDK
URL: http://www.quickpdf.org/forum/forum_posts.asp?TID=1958
Printed Date: 17 Mar 26 at 7:47PM
Software Version: Web Wiz Forums 11.01 - http://www.webwizforums.com


Topic: Centering text not working.. why??
Posted By: peterlen
Subject: Centering text not working.. why??
Date Posted: 14 Sep 11 at 7:24PM
Hello,
 
I am using QuickPDF Lite 7.25.  I wanted to center my title so I tried:
 
library.SetTextAlign(1); // 1 = center align
library.Drawtext(10,20, "My Title");
 
This would draw my title all the way to the left edge and halfway off the page.  When I do SetTextAlign(0) for the default left alignment, all works well, but even if I try the right alignment (3), the text is displayed halfway off of the left side of the page.
 
Not sure what I amy be missing here.  Must be something stupid I am not doing.  Any clues? 
 
Thanks - Peter 



Replies:
Posted By: Ingo
Date Posted: 14 Sep 11 at 11:10PM
Could it be that the pdf was rotated internally?

Cheers, Ingo


Posted By: peterlen
Date Posted: 14 Sep 11 at 11:59PM
Ingo - Thanks for the reply.  I know the code didn't change any rotation.  The left align is correct and the X, Y coords are good as well, so I am unsure how the page rotation would be off.  The Lite version does has one method that deals with rotation I believe so I will test some things there to see.


Posted By: AndrewC
Date Posted: 20 Sep 11 at 4:46PM
This code works as expected 

            QP.SetOrigin(1);
            QP.SetTextAlign(0); // 0= left align
            QP.DrawText(100, 20, "My Title");
            QP.SetTextAlign(1); // 1 = center align
            QP.DrawText(100, 40, "My Title");
            QP.SetTextAlign(2); // 2 = right align
            QP.DrawText(100, 60, "My Title");

If you are drawing text onto an existing page then it is possible that the coodinate system and scaling on the page is not what you expect.  Some pages can render the text upside down and right to left.  We have a function called QP.NormalizePage() in the full QPL version that resets a page to a standard coordinate system.

If you still cannot get it to work then you could send your code and PDF fiels to 

   http://www.quickpdflibrary.com/support/support-query.php - http://www.quickpdflibrary.com/support/support-query.php

Andrew



Posted By: Dan
Date Posted: 05 Nov 11 at 6:10PM
I was thrown off by centering as well and I think I know your problem. For the XPos, use PageWidth / 2 so your code would look like:

library.SetTextAlign(1); // 1 = center align
library.Drawtext( (library.PageWidth / 2) , 20, "My Title");

Centering is done around the coordinates, not on the vertical line you specify.

Dan


Posted By: AndrewC
Date Posted: 08 Nov 11 at 2:53AM
Dan is right.  The DrawText uses the x,y coordinate as the point to align to.  So if the alignment is set to RightAlign and you DrawText(50, 20, "Hello") then the right most past of the text will be a the horizontal position of x = 50.



Print Page | Close Window

Forum Software by Web Wiz Forums® version 11.01 - http://www.webwizforums.com
Copyright ©2001-2014 Web Wiz Ltd. - http://www.webwiz.co.uk