如何使用密码在.net中创建PDF文件 [英] how to create PDF file in .net , with password

查看:68
本文介绍了如何使用密码在.net中创建PDF文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在pdf文件中返回创建代码。但它显示错误



我的代码:

hi here i return my code for creation on pdf file. but it is showing error

my code:

public void pdf()
        {            
            int i = 0;
            // r is for random file names...
            Random r = new Random();
            i = r.Next(1, 999999999);
            string filename = i.ToString() + ".pdf";
            //path where to save...
            string path = "D:/Test/" + filename;     
            Document document = new Document();
            PdfWriter writer;
            writer = PdfWriter.GetInstance(document, new FileStream(path, System.IO.FileMode.Create));
            // Set password ...replace mypass with your password .......
            writer.SetEncryption(PdfWriter.STRENGTH128BITS, "mypass", null, PdfWriter.AllowCopy);

            document.Open();
            //document as many properties .. for time begin i am using only one ..
            //document.add is to add contant to your file..
            document.Add(new Paragraph("This document is Top Secret!"));
            document.Close();
        }

推荐答案

如果您使用外部库,至少告诉我们它是什么。您最好的选择是阅读文档并在论坛上询问您正在使用的产品,
If you use an external library, at least tell us what it is. Your best bet is to read the docs and ask on the forums for the product you;re using,


这篇关于如何使用密码在.net中创建PDF文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆