I need to open a secured password protected PDF files programatically in ASP.NET using C#
I don't want to enter the password manually when it opens.
When the file is downloaded to the local drive it must ask the password to download or print the file.
I am using PDFsharp
You can specify the password in the call to PdfReader.Open to open the document. You can then create an unprotected copy of the PDF, e.g. to print it without password prompt.
See also:
http://www.pdfsharp.net/wiki/UnprotectDocument-sample.ashx
Related
I have a USB token (Epass-Capricorn) and my requirement is to sign text/flat files using the same.
PS: I believe I have to get the "START-SIGNATURE", "START-CERTIFICATE" and "SIGNER-VERSION" data from the code and append at the end of the file, attached a screenshot of same.
Can someone guide me how can I achieve the same using C#?
I converted text files to PDF documents using CutePDF Writer printer in windows forms application.It's working as expected but same block of code I used in c# windows service application to convert text files to PDF files.I'm not getting any exceptions while executing the code and not generating any PDF documents.
I created the following registry key settings for CutePDF writer
Setting the display mode:
HKEY_CURRENT_USER\Software\CutePDF Writer\BypassSaveAs
(0 = show Save as dialog box after spooling, 1 = do not show Save as dialog box.)
(This value is of type REG_SZ, not REG_DWORD)
Setting the filename:
HKEY_CURRENT_USER\Software\CutePDF Writer\OutputFile
(Use the key above to set the output file for the PDF. A full pathname
(e.g. d:\your folder\your file.pdf) is required.)
Not familiar with CutePDF Writer - but: as which user is the service running?
To clarify this: if the service runs as LocalService, the registry key HKEY_CURRENT_USER is not the same as the one from loged in user.
If that is the case, try HKEY_USERS\S-1-5-19 instead of HKEY_CURRENT_USER.
I have Encrypted PDF File and i have convert encypted PDF file To Base64 string. I want Base64 string convert into PDF File (Means PDF file will write without password). PDF File should open.
Encrypted Base64 string is perfectly convert into pdf file but when i am trying to open the pdf file it is asking password.
I want when file is convert into Encryted base64 to PDF File then it should open without password .File is saving on my folder.
How i can do it. with asp.net with c#.
Can’t be done.
Otherwise the mere act of emailing a password protected PDF removes the protection and I’m pretty sure the payslips I get are protected.
I am building a method that will build an XLS file and uploading it on user's computer.
I am using this guide:
http://csharp.net-informations.com/excel/csharp-create-excel.htm
So code that will define my destination address is:
xlWorkBook.SaveAs("C:\\Something\\csharp-Excel.xls", Excel.XlFileFormat.xlWorkbookNormal);
Now it is default, but i want to allow user to define it by him self, so as far as i understand, i need an html field, which will open common "browse window" and save file path to string, which will be later used in xlWorkBook.SaveAs function. I have read a bit about FileUpload, but i don't really sure that it is what i am looking for.
The code that you have there will save the file on the web server itself, not on the user's computer. You'll need to stream the file down to the user via the browser, and then they will be able to choose where to save it.
You could save the file on the server and then stream it to the user using Response.WriteFile, or you could stream it from memory if you don't want to keep a copy of the file on the server.
This code will create a file on the server, not on the users/clients computer. If you want the user to be able to download the file to his/her computer and select the location where the file is stored, you need to create a file (.aspx file or controller method, depending on wether you are using webforms or MVC) and have it stream the file to the user's browser. The browser will then take care of displaying the "Save as" dialog where the user can select the destination location.
I use open XML to export excel file. SpreadsheetDocument.Create requires a file destination.
I want to get this file destination from user similar to a SaveFileDialog in Winforms.
How I get file destination from user? I use Asp.Net 4.0 and OpenXML SDK 2.5 .
SpreadsheetDocument spreadsheetDocument = SpreadsheetDocument.Create(destination, SpreadsheetDocumentType.Workbook);
For this functionality even if you use open/save dialog, it would show the client locations not the server locations. So here question is, do you want to save that file to the client machine or at the server machine?
If you want to save it to client machine then first save it on the server by any name and location you want and then initiate a download after that. It will automatically prompt download dialog in the client browser and there user would be able to select the location and filename (depending on the client browser settings).
If you want to save it only on server then just before generating the spreadsheet, prompt user for entering the filename (on the page from where the request is generated). If some of your folders are accessible to user then you can also prompt user to select one of the folders, otherwise choose one as per your choice/requirement. Use the filename and the location to generate the spreadsheet.
when a webserver is streaming a file down to the client, you don't have control of the destination folder. All you can do is:
specify the contents type (to aid client in determining how to handle)
specify filename
(I think) tell the client browser to save the file vs. displaying it automatically in the registered application (for example, PDFs usually display in the browser, but setting up the streaming correctly could force Save File dialog instead)
If you need to "cache" the file ion the web server, you export to a server folder that your server process has write permissions to. Then you stream to the client - the client will get the prompt from their browser and save where they want.
Look at Server.MapPath for example - it'll map virtual path to physical on your server. the question of permissions remains.
Depending on your particular case, you may be able to avoid saving to the server, if the export library has a way of returning a byte array or a stream, instead of saving to a file. In that case you just stream the return result to requester.
I am not familiar with the SDK you're using, but quick googling reveals this method of returning the document in a stream:
using (MemoryStream stream = new MemoryStream())
{
using (SpreadsheetDocument spreadsheetDocument = SpreadsheetDocument.Create(stream, SpreadsheetDocumentType.Workbook, true))
{
... work with the spreadsheetDocument, if needed
... prepare and stream to browser
}
}
Here's one of the references to your SDK I found
Use Environment.SpecialFolder enumerations. If you are looking for my documents then:
var destination = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)
SpreadsheetDocument spreadsheetDocument = SpreadsheetDocument.Create(destination, SpreadsheetDocumentType.Workbook);