Frequently Asked Question:
SetOrigin( 1 ) is sometimes bottom left instead of top left. Why and how can I know in advance?
Calling SetOrigin( 1 ) is supposed to be top left, but in some particular PDFs it is bottom left. Why doesn't it set it always to top left?
In those particular PDFs, calling SetOrigin( 0 ), which is supposed to be bottom left comes out top left.
Is there a property in the PDF I can query to know in advance which way SetOrigin( 1 ) will behave?
A link to a PDF where SetOrigin(1) sets to bottom left: http://www.bridgerhunt.com/hp/sample3.pdf
[I am using QuickPDFLite.]
Yes, SetOrigin(1) should set the drawing commands to start from the top left.
If this isn't happening with some of your PDF files then it could be because they have a /Rotate entry in the page dictionary or maybe a command in the transformation matrix in the page content that deals with coordinate spaces in the PDF.
So basically, the SetOrigin function is working correctly, it's just that some other aspect of your PDF file is rotating the page and making it look like it's not working.
Can you edit your question and provide links to a couple of sample documents that exhibit this problem so that we can examine them?
UPDATE:
Thanks for uploading your file. It looks like the page in your file contains a matrix transformation that switches the co-ordinate system to the top of the page.
To cancel this transformation, a "save state" operator can be added to the beginning of the page's content stream with a corresponding "restore state" operator added to the end.
This can be done using the EncapsulateLayer function. Some documents might have the page's content stream split over more than one part so the CombineLayers function might have to be called first to put everything into one stream object.
Here's a quick example:
QP.LoadFromFile("Help474.pdf");
QP.SetLineColor(0, 0, 1);
QP.SetLineWidth(5);
QP.DrawBox(0, 100, 100, 100, 0);
QP.CombineLayers;
QP.EncapsulateLayer;
QP.SetLineColor(1, 0, 0);
QP.SetLineWidth(5);
QP.DrawBox(0, 100, 100, 100, 0);
QP.SaveToFile("Help474b.pdf");
As I noted above, some PDF docs might have pages with a /Rotate entry that could also affect the co-ordinate system orientation. This sometimes has to be taken into account to determine how the particular co-ordinate system transforms are displayed.