Fixed cyclic scanning/writings in pdfwriter.c

By marking nodes in new xref tree using negative ref-number, solves the cyclic writing problem.
Also fills in the Root node and Pages node as 1 and 2 in the new ref tree, stops cyclic scanning.