NReco PdfGenerator 禁用选择
NReco PdfGenerator disable selection
我想禁用选择,就像图像一样,即使包含文本也是如此。
我知道 PDF 包含图层,但我找不到删除文本图层的位置。
谢谢。
var htmlToPdf = new NReco.PdfGenerator.HtmlToPdfConverter();
htmlToPdf.Size = NReco.PdfGenerator.PageSize.Letter;
htmlToPdf.Margins = new NReco.PdfGenerator.PageMargins()
{
Bottom = 0,
Top = 0,
Left = 0,
Right = 0
};
string ID = "Test";
Response.ContentType = "application/pdf";
Response.AppendHeader("content-disposition", string.Format("inline;FileName=\"{0}.pdf\"", ID));
htmlToPdf.GeneratePdfFromFile("Page.aspx", null, Response.OutputStream);
Response.End();
PdfGenerator 内部使用 wkhtmltopdf 并将文本内容呈现为文本块,默认情况下它们是可选的;这种行为无法改变。如果您想保证无法选择文本,则应将其渲染为图像(=您可以先渲染 HTML 图像,然后生成包含此图像的 PDF)。
另一种方法是使用 iTextSharp 对生成的 PDF 进行加密,请参阅 Lock PDF against editing using iTextSharp 的答案
- 只有 PdfWriter.ALLOW_PRINTING 选项(iTextSharp 的 LGPL 版本 4.1.6 可用于此目的)。
我想禁用选择,就像图像一样,即使包含文本也是如此。
我知道 PDF 包含图层,但我找不到删除文本图层的位置。
谢谢。
var htmlToPdf = new NReco.PdfGenerator.HtmlToPdfConverter();
htmlToPdf.Size = NReco.PdfGenerator.PageSize.Letter;
htmlToPdf.Margins = new NReco.PdfGenerator.PageMargins()
{
Bottom = 0,
Top = 0,
Left = 0,
Right = 0
};
string ID = "Test";
Response.ContentType = "application/pdf";
Response.AppendHeader("content-disposition", string.Format("inline;FileName=\"{0}.pdf\"", ID));
htmlToPdf.GeneratePdfFromFile("Page.aspx", null, Response.OutputStream);
Response.End();
PdfGenerator 内部使用 wkhtmltopdf 并将文本内容呈现为文本块,默认情况下它们是可选的;这种行为无法改变。如果您想保证无法选择文本,则应将其渲染为图像(=您可以先渲染 HTML 图像,然后生成包含此图像的 PDF)。
另一种方法是使用 iTextSharp 对生成的 PDF 进行加密,请参阅 Lock PDF against editing using iTextSharp 的答案 - 只有 PdfWriter.ALLOW_PRINTING 选项(iTextSharp 的 LGPL 版本 4.1.6 可用于此目的)。