We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Preserve Extended Rights When Saving PDF To Response Stream .NET

I’m able to get the pdf to save and preserve the extended rights, when following the example code here,
Preserve Extended Rights when Working with Forms

'Open document            
Dim documentName As String = "GC-020.pdf"
Dim documentPath As String = String.Format("{0}\{1}", Server.MapPath("~/Data"), documentName)

Using fs As FileStream = New FileStream(documentPath, FileMode.Open, FileAccess.ReadWrite)
    'Open document
    Dim pdf As Aspose.Pdf.Document = New Aspose.Pdf.Document(fs)

    'Populate document
    Dim formFields As List(Of Aspose.Pdf.Forms.Field) = pdf.Form.Fields.Where(Function(x) x IsNot Nothing AndAlso Not x.ReadOnly).ToList()
    Dim currentFormField As Aspose.Pdf.Forms.Field = formFields.Where(Function(x) x.PartialName = "FillText63").FirstOrDefault()
    If currentFormField IsNot Nothing Then
        Dim txt As TextBoxField = DirectCast(currentFormField, TextBoxField)
        txt.Value = "TEST"
    End If

    'Save document
    Dim opts As New Aspose.Pdf.PdfSaveOptions
    opts.CloseResponse = True
    pdf.Save(Response, "output.pdf", ContentDisposition.Inline, opts)
End Using

But what I need to do is be able to save the pdf to the response output stream while preserving the extended rights.

I can send the pdf in private message just tell me what you need to help me find a solution.



Thank you for contacting support.

As you are able to preserve extended rights by using the incremental approach which is explained in respective article; you may save the incremented PDF file from a FileStream to a MemoryStream and then pass bytes from that MemoryStream to Response object as mentioned in Sending PDF to Browser for Download.

We hope this will be helpful. In case you notice any problem then please share a narrowed down sample application with us so that we may assist you accordingly.

Also, I’m using the original pdf as a template and I don’t want to save any data to the template.
I will try the code out you mentioned to do this.
My goal is to open the pdf, fill the form fields and then send to the browser to download, while preserving the extended rights.

Using the code you mentioned doesn’t allow me to accomplish my goal mentioned previously.
From what I have found you have to save the pdf to the same stream in order to preserve the extended rights.


Would you please share a narrowed down code snippet along with source PDF file so that we may investigate it in our environment and then share our findings with you.


After sleeping on it and revisiting my codes I came up with the following solution to accomplish my goal,

Dim documentName As String = "GC-020.pdf"
Dim documentPath As String = String.Format("{0}\{1}", Server.MapPath("~/Data"), documentName)

If File.Exists(documentPath) Then


        'Use document in memory, populate with data
        'Following this approach will preserve extended rights 
        Using ms As New MemoryStream()

            'Open document with file stream
            Using fs As New FileStream(documentPath, FileMode.Open, FileAccess.Read)

                'Copy file from file stream to memory stream

            End Using

            'Create Apose.Pdf document from the memory stream
            Dim pdf As Aspose.Pdf.Document = New Aspose.Pdf.Document(ms)

            'Populate the document with data
            PopulateFormFieldsOfDocument(pdf, documentName)

            'Save document in memory back to the memory stream

            'Write memory stream to client
            Response.Charset = "UTF-8"
            Response.AddHeader("content-length", ms.Length.ToString())
            Response.AddHeader("content-disposition", String.Format("attachment;filename={0}", documentName))
            Response.ContentType = "application/pdf"

        End Using

    Catch ex As Exception
        'Display ex.Message
    End Try


    'Display message "This file does not exist"

End If

Thanks for your help!


Thank you for your kind feedback.

We are glad to know that you have been able to achieve your requirements with the help of suggested approach. Please keep using our API and in event of any further query, feel free to ask.