Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7218715
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T21:31:12+00:00 2026-05-28T21:31:12+00:00

i create a simple PDF creator application using ASP.NET. that application will create a

  • 0

i create a simple PDF creator application using ASP.NET. that application will create a PDF file on the fly with the password for securing that document. here’s my code:

    Sub createPDFFile()
        Dim doc As Document = New Document
        PdfWriter.GetInstance(doc, New FileStream(Request.PhysicalApplicationPath + _
                              "pdf\result.pdf", FileMode.Create))
        doc.Open()
        doc.Add(New Paragraph("Hello World!! only Testing"))
        doc.Close()
        SetPDFPassword(Server.MapPath("~/pdf/result.pdf"), "resultwithpassword.pdf", "12345")
        Response.Redirect("pdf/1.pdf")
    End Sub

and here’s my code for add a password to the PDF file:

     Private Sub SetPDFPassword(ByVal FullPathPdfFileName As String, ByVal DownloadPDFFileName As String, ByVal ForOpenPassword As String)
        Dim sname As String = FullPathPdfFileName
        Dim sname1 As String = New System.IO.FileInfo(FullPathPdfFileName).DirectoryName & "/test.pdf"
        Dim reader As New PdfReader(sname)
        Dim n As Integer = reader.NumberOfPages

        Dim document As New Document(reader.GetPageSizeWithRotation(1))
        Dim writer As PdfWriter = PdfWriter.GetInstance(document, New IO.FileStream(sname1, IO.FileMode.Create))
        writer.SetEncryption(PdfWriter.STRENGTH128BITS, ForOpenPassword, Nothing, PdfWriter.AllowPrinting)
        document.Open()
        Dim cb As PdfContentByte = writer.DirectContent
        Dim page As PdfImportedPage
        Dim rotation As Integer
        Dim i As Integer = 0

        While i < n
            i += 1
            document.SetPageSize(reader.GetPageSizeWithRotation(i))
            document.NewPage()
            page = writer.GetImportedPage(reader, i)
            rotation = reader.GetPageRotation(i)
            If rotation = 90 OrElse rotation = 270 Then
                cb.AddTemplate(page, 0, -1.0F, 1.0F, 0, 0, _
                reader.GetPageSizeWithRotation(i).Height)
            Else
                cb.AddTemplate(page, 1.0F, 0, 0, 1.0F, 0, _
                0)

            End If
        End While

        document.Close()
        writer.Close()

        Dim PDFfile As New IO.FileStream(sname1, IO.FileMode.Open)
        Dim FileSize As Long
        FileSize = PDFfile.Length
        Dim buffer As Byte() = New Byte(CInt(FileSize) - 1) {}
        PDFfile.Read(buffer, 0, CInt(FileSize))
        PDFfile.Close()
        System.IO.File.Delete(sname1)
        Response.AddHeader("Content-Disposition", "attachment;filename=" & DownloadPDFFileName)
        Response.ContentType = "application/pdf"
        Response.BinaryWrite(buffer)
        Response.Flush()
        Response.Close()

    End Sub

that code is works perfectly. it can generate a PDF file and add some password to open, but the PDF file will be send to the user. has anyone know how to generate a PDF file with password but that result file still on the server and only can be shown from web browser (not showing a download prompt)?? thanks in advance.. 😀

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T21:31:12+00:00Added an answer on May 28, 2026 at 9:31 pm

    Correct me if I’m wrong but I think that it is up to the browser to show the pdf in the browser or ask you if you want to download it.

    Adobe Acrobat plug in can be downloaded at http://www.adobe.com/ and is a plug in to help the user display the pdf in the browser.

    How to display the pdf in the broswer with the plugin installed: http://www.okanagan.bc.ca/administration/itservices/edtech/elearn/Configuring_the_browser_to_show_pdf_files.html

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using PDFBox and iText to create a simple (just paragraphs) pdf document from
I want to create a simple program that will convert a pdf to a
I create simple test PDF document using iTextSharp. I'm just using PdfContentByte to show
I have used following code to create a simple PDF file. It executes fine
Is there a framework out there that will allow me to create simple bar
I'm trying to create a simple Automator workflow that will prompt me for where
I'm using XSL-FO to create PDF's. Now I have a label that I want
I'll create a EML file with an attachment using JavaMail. I created a simple
I'm using a simple program that will take tallPDF xml and convert it into
Our company has thousands of PDF documents. How do we create a simple search

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.