Print a locked pdf file after it has been opened and populated using itextsharp.dll but before it's closed. RRS feed

  • Question

  • User-777992925 posted

    Right now I am having trouble printing a pdf from within my backcode for an application I am developing.  Some helpful information to start...

    1) The files I am using are locked pdf files which cannot be saved.

    2) I am using the itextsharp library to help open a template pdf and then fill in a separate pdf based on the templates field structure.

    3) I utilize an in-house function called "SelectString" which is passed a connectionstring, table, column and pieces of a where clause to help grab data from a column for a specific ID.

    4) After using SelectString I then populate an identical copy of the template with the information.

    This is where I'm having an issue.  My code is...

     Protected Sub FillForm()
            Dim pdfTemplate As String = "N:\Projects\TestPage\PositionDescriptions\Includes\SF52.pdf"
            Dim newFile As String = "N:\Projects\TestPage\PositionDescriptions\Includes\SF52_Printable.pdf"
            Dim pdfReader As New PdfReader(pdfTemplate)
            Dim pdfStamp As New PdfStamper(pdfReader, New FileStream(newFile, FileMode.Create))
            Dim pdfFormFields As AcroFields = pdfStamp.AcroFields
            Dim Data As String = ""
            'set form pdfFormFields
            'Set the Action Requests
            Data = FuncLib.SelectString(connectionString, "Action", "Requests", "Request_ID", "1715")
            pdfFormFields.SetField("ActsReq", Data)
            Data = FuncLib.SelectString(connectionString, "InfoName", "Requests", "Request_ID", "1715")
            pdfFormFields.SetField("InfoName", Data)
            Data = FuncLib.SelectString(connectionString, "InfoPhone", "Requests", "Request_ID", "1715")
            pdfFormFields.SetField("InfoPhone", Data)
            Data = FuncLib.SelectString(connectionString, "ProEfDate", "Requests", "Request_ID", "1715")
            pdfFormFields.SetField("ProEfDate", Data)
            Data = FuncLib.SelectString(connectionString, "ActReq", "Requests", "Request_ID", "1715")
            pdfFormFields.SetField("ActReq", Data)
            Data = FuncLib.SelectString(connectionString, "ActDate", "Requests", "Request_ID", "1715")
            pdfFormFields.SetField("ActDate", Data)
            'report by reading values from completed PDF
            Dim sTmp As String = "SF52 Completed by User"
            MessageBox.Show(sTmp, "Finished")
            'flatten the form to remove editting options, set it to false
            'to leave the form open to subsequent manual edits
            pdfStamp.FormFlattening = False
            'close the pdf
        End Sub

    As you can see in my code I do all of the steps above but normally, if you had a non-locked form just closing the pdfStamper object would be enough to force it to save.  However, I cannot do this because the file is locked and cannot be unlocked (it is a government form), so I need the next best thing.  I need to know if there is any possibility of print a locked file after it has been populated with data but before it is closed and saved?

    Friday, January 14, 2011 1:34 PM

All replies

  • User-777992925 posted

    So I've been doing my research and I've found that the main issue I am having stems from the fact that Adobe loves to partition their product into components so they can get the maximum price for functionality that should be built into one solution.

    Apparently, the file cannot be saved because an Adobe Reader extension was not purchased at the time when the form was created so there is no way of recreating a savable version without first purchasing extra extensions and even then the form is restricted to usage terms.

    So one of my unmentioned solutions (find a way of creating a savable version of the file) has been permanently closed due to restrictions in capital.

    Thus, my only solution still remains that once the file is opened for editing within the code I then have to find some way of running a shell command or a command line action or anything that allows me to basically do the same thing as if I were manually filling out the form...

    Basically, I need functionality which hits the print button for me within my application automatically.  Our user would select the printer from the prompt and accept the job manually so I don't need to automate anything more than just having the print window show up.

    Friday, January 14, 2011 3:06 PM
  • User-777992925 posted

    Is there really no one that's had to bypass the Adobe save issue to print a pdf from an application before?  I can't imagine every single person who has ever printed a pdf through an application has purchased the ability to save the forms.

    Tuesday, January 18, 2011 9:51 AM