Free Support Forum - aspose.com

How to open and show a Pdf doc to user

Hi,

I am new to Aspose and i need to use it for the following purpose.

in my application, I need open an existing pdf document and depends on the role, i should show the original document or xerox document. Suppose if the user is administrator i will show the original document itself. if the user is guest then i should take a copy of the original document in temp file and should show to the user with the user name as a water mark.

I am not able to find any method to open an existing pdf doc using aspose and show it to the user. Kindly help me how to open and show the existing pdf document to the user and how to take a copy of the existing document in a memory stream or a temp file?

Can we add a watermark at runtime without saving the file to the disk? The content will be in the memory and that content will be shown to the user from memory as pdf. is it possible to show like this? any show() method is there to show the pdf doc to user through code, instead of opening by double clicking the doc manually? Once the user closes the file the memory stream should be flushed. Kindly help on this.

Regards

Srirangam K

Hello Srirangam,

Thanks for considering Aspose.

We looking into your query and finding the best possible solution that can serve your purpose. Soon you will be udpated. Sorry for delay.

Hello Srirangam,

Thanks for considering Aspose.

Open a Pdf file. We have a class named PdfViewer that is used to open the pdf files (available with Aspose.Pdf.Kit). But this feature is not supported in .Net only in JAVA (still that feature does not work well). There is another option if your application is Web you can open the pdf file in Browser.

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

public void Save(string,SaveType,HttpResponse);

If you use that method, the PDF will be displayed in the web browser. For more information kindly visit our online demos. Also refer to 129186

Pdf file can be opened using Adobe Reader with default settings. System.Diagnostics.Process.Start(@"c:/pdftest/Nayyer.pdf");But the PDF reader must be installed in your system.

Even if you need to display the Pdf files in .Net application other than Web, there is a way, you can convert the Pdf file in to Image and display it in your application. For more information kindly visit Convert the PDF Document to Specified Images

2- Regarding creating a Xerox copy or temp its quiet easy. You can use System.IO.File.Copy(). To create the copy of file over system. Pdf file can also be opened in a Memory Stream. To create a copy of Pdf file through Memory Stream please use

MemoryStream inms = new MemoryStream(File.ReadAllBytes(@"c:/pdftest/Nayyer.pdf"));

MemoryStream temp = inms;

User name can be added as a Water mark, for this purpose we have a class PdfFileStamp and watermark object is represented by Stamp Class. These classes are available in Aspose.Pdf.Kit component.

See the following piece of code.

Stamp aStamp = new Stamp();

aStamp.BindLogo(new FormattedText("Hello UserName"));

aStamp.IsBackground = false;

aStamp.Pages = new int[] { 1 };

aStamp.Rotation = 90;

aStamp.SetOrigin(50, 50);

PdfFileStamp stamper = new PdfFileStamp(inms, outms);

stamper.AddStamp(aStamp);

stamper.Close();

inms.Close(); // closes current stream & releases all resources.

temp.Close();

For more information on adding username as watermark, please visit http://www.aspose.com/documentation/file-format-components/aspose.pdf.kit-for-.net-and-java/add-logo.html