checking if line orientation is NaN
if the first line is not header, empty header line is inserted
removing duplicate chunks and chunks outside the page rectangle