How to split pdf document properly?


Could you please tell me why the attached pdf is being turned upside
when I split the pages into individual files? My code is as follows:


            Dim in_doc As PDFDoc = New PDFDoc(input_document)

            Dim builder As ElementBuilder = New ElementBuilder
            Dim writer As ElementWriter = New ElementWriter

            Dim page_end As PageIterator = in_doc.PageEnd()
            Dim itr As PageIterator = in_doc.PageBegin()

            While Not itr.Equals(page_end)
                Dim src_page As Page = itr.Current()
                Dim new_doc As PDFDoc = New PDFDoc
                Dim media_box As Rect = New Rect(0, 0,
src_page.GetPageWidth, src_page.GetPageHeight)
                Dim new_page As Page = new_doc.PageCreate(media_box)
                Dim element As Element = builder.CreateForm(src_page,
                Dim pdfPageLocation As String = FileLocation &
& "\"
                If Not IO.Directory.Exists(pdfPageLocation) Then
                Dim pdfOutputFilename As String = pdfPageLocation &
"page" & itr.GetPageNumber & ".pdf"
                Dim reader As ElementReader = New ElementReader
"application/pdf", smMaxHeight, smMaxWidth, smThumbName, lgMaxHeight,
lgMaxWidth, lgThumbName, False, Nothing, Nothing)
                Dim content As String = GetTextFromPdf(reader,
            End While



Based on your code you are not directly splitting the document, but are
doing PDF imposition.
A simpler (and better) way to split PDF documents is to create a
temporary PDFDoc, copy one (or more) pages to the temporary document,
and then save. This is illustrated in PDFPage same project:

You may also want to read the following section:

You can also tweak your PDF page imposition/placement code to account
for effects of page rotation (i.e. page.GetRotation()) by setting the
transformation matrix
(element.SetTransform(page.GetDefaultMatrix(...))) on form XObject.