pdf - VB.NET 2015 - Extract pages with different orientation -


i found this post extract pages pdf file using itextsharp lib. document have different orientation each page , pagesize ist different to. first of try fix page orientation. here code , im out of ideas perhaps can tell me how this.

public function extractpdfpages(byval sourcefile string, byval targetfile string, byval intstr integer, byval intend integer)     try         dim imppage pdfimportedpage = nothing         dim reader new pdfreader(sourcefile)         dim pagerotation string = ""           dim srcdoc new document(reader.getpagesizewithrotation(intstr))         dim pdfcopyprovider new pdfcopy(srcdoc, new system.io.filestream(targetpath & "\" & targetfile, system.io.filemode.create))          srcdoc.open()         x = intstr intend             imppage = pdfcopyprovider.getimportedpage(reader, x)             dim mydocor rectangle = reader.getpagesize(x)              if mydocor.width >= mydocor.height                 pagerotation = "land"             else                 pagerotation = "port"             end if             ' --- fix orientation              ' --- add page             pdfcopyprovider.addpage(imppage)          next          srcdoc.close()         reader.close()     catch ex exception         throw ex     end try   end function 

this me. else how have same issue here solution :

public function extractpdfpages(byval sourcefile string, byval targetfile string, byval intstr integer, byval intend integer)     try         dim imppage pdfimportedpage = nothing         dim reader new pdfreader(sourcefile)         dim pagerotation string = ""           dim srcdoc new document(reader.getpagesizewithrotation(intstr))         dim pdfcopyprovider new pdfcopy(srcdoc, new system.io.filestream(targetpath & "\" & targetfile, system.io.filemode.create))          srcdoc.open()         x = intstr intend             imppage = pdfcopyprovider.getimportedpage(reader, x)              pdfcopyprovider.setpagesize(new rectangle(0.0f, 0.0f, imppage.width, imppage.height))              pdfcopyprovider.addpage(imppage)          next          srcdoc.close()         reader.close()     catch ex exception         throw ex     end try   end function 

the magic set pagesize.

pdfcopyprovider.setpagesize(new rectangle(0.0f, 0.0f, imppage.width, imppage.height)) 

Comments