The fix is the javascript was opening another document so just I removed that code for creating a document. The print preview window was having a different document. It worked.