Correct way to flatten a PDF

I am reading multiple pdf's in to a list of memorystreams.  Once I have all the pdf's added to the list of memoryStream, this is my code to flatten and save to pdfFileName  Does this vb code look correct or is there another way to flatten the pdfFileName?

        Dim finalDoc As New PdfDocument
        ''Merge the PDFs stored in the Array into one PDF
        Dim mStreamArray As MemoryStream() = pMemeoryStream.ToArray()
        mStreamList.Clear()  ''Empty the list of PDF's
        PdfDocumentBase.Merge(finalDoc, mStreamArray)
        finalDoc.Save(pdfFileName)
        finalDoc.Close()

        '' load existing document to flatten it again
        Dim loadedDocument As PdfLoadedDocument = New PdfLoadedDocument(pdfFileName)
        For Each loadedPage As PdfLoadedPage In loadedDocument.Pages
            For Each annotation As PdfLoadedAnnotation In loadedPage.Annotations
                annotation.Flatten = True
            Next
        Next
        'Dim loadedForm As PdfLoadedForm = loadedDocument.Form
        loadedDocument.Form.Flatten = True
        loadedDocument.Save(pdfFileName)
        loadedDocument.Close(True)
        loadedDocument.Dispose()



1 Reply

RB Ravikumar Baladhandapani Syncfusion Team March 16, 2020 12:58 PM UTC

Hi Karla, 
 
Thank you for using Syncfusion products. 
 
Yes. You can use this provided code snippet for flatting the pdf documents. Please refer the below UG link for more details about flattening the documents. 
 
Please let us know if you need any further assistance on this. 
 
 
Regards, 
Ravikumar 


Loader.
Up arrow icon