0
我使用ABC.PDF从我现有的系统生成pdf。它具有表单认证机制。当我生成pdf时,它总是生成登录页面。 这是我的功能。请帮助我,谢谢inadvanced。在表单认证系统中使用ABCpdf.net生成PDF
私人文件GeneratePDFPage(){
var theDoc = new Doc();
theDoc.HtmlOptions.Engine = EngineType.MSHtml;
theDoc.HtmlOptions.AddLinks = true;
var uri = Context.Request.Url.ToString();
theDoc.HtmlOptions.LogonName = Context.User.Identity.Name;
theDoc.HtmlOptions.LogonPassword = "7126c198-5aee-47b2-8e6a-09c558892703";
var html = Response.Filter;
int theId = theDoc.AddImageUrl(uri);
//We now chain subsequent pages together. We stop when we reach a page which wasn't truncated
while (true)
{
theDoc.FrameRect();
if (!theDoc.Chainable(theId))
break;
theDoc.Page = theDoc.AddPage();
theId = theDoc.AddImageToChain(theId);
}
////////////////////////////////////////////////////
// Set pagenumber
////////////////////////////////////////////////////
theDoc.HtmlOptions.LinkPages();
//Set the position for the page number
////theDoc.Rect.String = "35 30 580 50";
////theDoc.Font = theDoc.AddFont("Trebuchet");
////theDoc.FontSize = 11;
////theDoc.HtmlOptions.UseScript = true;
int pagenumber = 1;
//flatten the pages. We can't do this until after the pages have been added because flattening will invalidate our previous ID and break the chain.
for (int i = 1; i <= theDoc.PageCount; i++)
{
theDoc.PageNumber = i;
//Add page number
//========================================
string txt = pagenumber.ToString(CultureInfo.InvariantCulture);
////theDoc.Color.String = "169 169 169"; //Dark grey text
//Positioning depends on if the page is even or odd
theDoc.VPos = 1.0;
theDoc.HPos = (i % 2) == 0 ? 0.01 : 0.99;
//Add the page number
theDoc.AddText(txt);
//Add a line above page number
theDoc.AddLine(21, 55, 590, 55);
//Flatten page
theDoc.Flatten();
//Increase the page number count
pagenumber++;
}
return theDoc;
}
谢谢您的回复,但我需要表单身份验证。没有任何方法来生成带有认证机制的PDF – Denuka
很难找到确切的解决方案,在ASP.NET窗体身份验证环境中将URL内容转换为PDF,而不禁用表单身份验证。我试了几天,但没用。我建议谁打算购买此产品,请尝试使用表单认证。他们建议的机制也不安全。请参阅以下以获取更多信息。 [http://codeasp.net/blogs/vivek_iit/microsoft-net/2190/hiqpdf-one-of-the-best-pdf-libraries-in-net] – Denuka