asp.net – 反复调用AddImageUrl(url)来汇编pdf文档
发布时间:2020-12-16 09:21:15 所属栏目:asp.Net 来源:网络整理
导读:我正在使用abcpdf,我很好奇我们是否可以递归调用Add ImageUrl()函数来汇编编译多个url的pdf文档? 就像是: int pageCount = 0; int theId = theDoc.AddImageUrl("https://stackoverflow.com/search?q=abcpdf+footer+page+x+out+of+",true,true); //assemble
|
我正在使用abcpdf,我很好奇我们是否可以递归调用Add
ImageUrl()函数来汇编编译多个url的pdf文档?
就像是: int pageCount = 0;
int theId = theDoc.AddImageUrl("https://stackoverflow.com/search?q=abcpdf+footer+page+x+out+of+",true,true);
//assemble document
while (theDoc.Chainable(theId))
{
theDoc.Page = theDoc.AddPage();
theId = theDoc.AddImageToChain(theId);
}
pageCount = theDoc.PageCount;
Console.WriteLine("1 document page count:" + pageCount);
//Flatten document
for (int i = 1; i <= pageCount; i++)
{
theDoc.PageNumber = i;
theDoc.Flatten();
}
//now try again
theId = theDoc.AddImageUrl("https://stackoverflow.com/questions/1980890/pdf-report-generation",true);
//assemble document
while (theDoc.Chainable(theId))
{
theDoc.Page = theDoc.AddPage();
theId = theDoc.AddImageToChain(theId);
}
Console.WriteLine("2 document page count:" + theDoc.PageCount);
//Flatten document
for (int i = pageCount + 1; i <= theDoc.PageCount; i++)
{
theDoc.PageNumber = i;
theDoc.Flatten();
}
pageCount = theDoc.PageCount;
编辑: static void Main(string[] args)
{
Test2();
}
static void Test2()
{
Doc theDoc = new Doc();
// Set minimum number of items a page of HTML should contain.
theDoc.HtmlOptions.ContentCount = 10;// Otherwise the page will be assumed to be invalid.
theDoc.HtmlOptions.RetryCount = 10; // Try to obtain html page 10 times
theDoc.HtmlOptions.Timeout = 180000;// The page must be obtained in less then 10 seconds
theDoc.Rect.Inset(0,10); // set up document
theDoc.Rect.Position(5,15);
theDoc.Rect.Width = 602;
theDoc.Rect.Height = 767;
theDoc.HtmlOptions.PageCacheEnabled = false;
IList<string> urls = new List<string>();
urls.Add("https://stackoverflow.com/search?q=abcpdf+footer+page+x+out+of+");
urls.Add("https://stackoverflow.com/questions/1980890/pdf-report-generation");
urls.Add("http://yahoo.com");
urls.Add("https://stackoverflow.com/questions/4338364/recursively-call-addimageurlurl-to-assemble-pdf-document");
foreach (string url in urls)
AddImage(ref theDoc,url);
//Flatten document
for (int i = 1; i <= theDoc.PageCount; i++)
{
theDoc.PageNumber = i;
theDoc.Flatten();
}
theDoc.Save("batchReport.pdf");
theDoc.Clear();
Console.Read();
}
static void AddImage(ref Doc theDoc,string url)
{
int theId = theDoc.AddImageUrl(url,true);
while (theDoc.Chainable(theId))
{
theDoc.Page = theDoc.AddPage();
theId = theDoc.AddImageToChain(theId); // is this right?
}
Console.WriteLine(string.Format("document page count: {0}",theDoc.PageCount.ToString()));
}
编辑2:遗憾的是,生成pdf文档时多次调用AddImageUrl似乎不起作用… 解决方法
终于找到了可靠的解
我们应该在它自己的Doc文档上执行AddImageUrl()函数,而不是在同一个底层文档上执行AddImageUrl()函数,并构建文档集合,最后我们将使用Append()方法将它们组合成一个文档. 这是代码: static void Main(string[] args)
{
Test2();
}
static void Test2()
{
Doc theDoc = new Doc();
var urls = new Dictionary<int,string>();
urls.Add(1,"http://www.asp101.com/samples/server_execute_aspx.asp");
urls.Add(2,"https://stackoverflow.com/questions/4338364/repeatedly-call-addimageurlurl-to-assemble-pdf-document");
urls.Add(3,"http://www.google.ca/");
urls.Add(4,"http://ca.yahoo.com/?p=us");
var theDocs = new List<Doc>();
foreach (int key in urls.Keys)
theDocs.Add(GetReport(urls[key]));
foreach (var doc in theDocs)
{
if (theDocs.IndexOf(doc) == 0)
theDoc = doc;
else
theDoc.Append(doc);
}
theDoc.Save("batchReport.pdf");
theDoc.Clear();
Console.Read();
}
static Doc GetReport(string url)
{
Doc theDoc = new Doc();
// Set minimum number of items a page of HTML should contain.
theDoc.HtmlOptions.ContentCount = 10;// Otherwise the page will be assumed to be invalid.
theDoc.HtmlOptions.RetryCount = 10; // Try to obtain html page 10 times
theDoc.HtmlOptions.Timeout = 180000;// The page must be obtained in less then 10 seconds
theDoc.Rect.Inset(0,15);
theDoc.Rect.Width = 602;
theDoc.Rect.Height = 767;
theDoc.HtmlOptions.PageCacheEnabled = false;
int theId = theDoc.AddImageUrl(url,true);
while (theDoc.Chainable(theId))
{
theDoc.Page = theDoc.AddPage();
theId = theDoc.AddImageToChain(theId);
}
//Flatten document
for (int i = 1; i <= theDoc.PageCount; i++)
{
theDoc.PageNumber = i;
theDoc.Flatten();
}
return theDoc;
}
}
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- asp.net-mvc – 将冗余信息添加到MVC路由
- asp.net-identity – 为什么一个站点的ASP.NET身份登录可以
- ASP与PHP的编译
- 连续部署到ASP.NET的ASP.NET核心应用程序
- 使用ASP.NET MVC的jQuery表单验证
- asp.net-mvc – jQuery.parseJSON不适用于MVC控制器动作的J
- asp.net – 如何在WCF服务中返回值后继续处理
- asp.net-mvc-4 – 如何将用户没有正确的角色重定向到Not Pe
- asp.net – 是否有任何使用自动生成的视觉工作室标签
- 从ASP.NET SQL memership DB中删除已失效/缺少应用程序的引
推荐文章
站长推荐
热点阅读
