Foxit Quick PDF Library

Use NormalizePage to resolve issues with adding text to pages in PDF files

If you’re experiencing issues with text not appearing correctly or in the right location on the page after using a function such as DrawText then calling the NormalizePage function may resolve this issue for you.

When you create a new PDF it will start off with the origin point (0,0) in the bottom left corner, the rotation in 0 degrees and the units as points (i.e. 72 points per inch), a black pen and a white background. Many PDF’s change these values in the content stream during the creation process. It is good practice to call SaveState (‘q’) as the very first call in the content stream and RestoreState (‘Q’) as the very last operation. Many PDF produces do not restore the graphics state at the end so when Foxit Quick PDF Library appends drawing commands such as DrawText it can be affected by the unknown drawing state and so can be drawn at the wrong angle in the wrong color in the wrong position or even off of the page in many cases.

NormalizePage is designed to place SaveState/RestoreState commands at the start and end of the contentstream(s) respectively so that the drawing state is known and can be trusted. NormalizePage works on 99.9% of problem PDF’s and it generally recommended to be called before adding any text, graphics or logos to an existing PDF file. Sometimes PDF producers add more SaveState calls than RestoreState calls so NormalizePage(1) will attempt to count and then balance out the Save/Restore calls.

In short: NormalizePage moves and/or rotates the contents of the page so that subsequent drawing operations are at the expected position on the page. All the page boundary boxes are adjusted to the physical size of the page and the page’s rotation attribute is reset to zero.

This article refers to a deprecated product. If you are looking for support for Foxit PDF SDK, please click here.

Updated on May 16, 2022

Was this article helpful?
Thanks for your feedback. If you have a comment on how to improve the article, you can write it here: