asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -
i'm using abcpdf , i'm curious if can recursively call addimageurl() function assemble pdf document compile multiple urls?
something like:
int pagecount = 0; int theid = thedoc.addimageurl("http://stackoverflow.com/search?q=abcpdf+footer+page+x+out+of+", true, 0, 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 (int = 1; <= pagecount; i++) { thedoc.pagenumber = i; thedoc.flatten(); } //now try again theid = thedoc.addimageurl("http://stackoverflow.com/questions/1980890/pdf-report-generation", true, 0, 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 (int = pagecount + 1; <= thedoc.pagecount; i++) { thedoc.pagenumber = i; thedoc.flatten(); } pagecount = thedoc.pagecount;
edit: code seems work based on 'hunter' solution:
static void main(string[] args) { test2(); } static void test2() { doc thedoc = new doc(); // set minimum number of items page of html should contain. thedoc.htmloptions.contentcount = 10;// otherwise page assumed invalid. thedoc.htmloptions.retrycount = 10; // try obtain html page 10 times thedoc.htmloptions.timeout = 180000;// page must obtained in less 10 seconds thedoc.rect.inset(0, 10); // set 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("http://stackoverflow.com/search?q=abcpdf+footer+page+x+out+of+"); urls.add("http://stackoverflow.com/questions/1980890/pdf-report-generation"); urls.add("http://yahoo.com"); urls.add("http://stackoverflow.com/questions/4338364/recursively-call-addimageurlurl-to-assemble-pdf-document"); foreach (string url in urls) addimage(ref thedoc, url); //flatten document (int = 1; <= 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, 0, true); while (thedoc.chainable(theid)) { thedoc.page = thedoc.addpage(); theid = thedoc.addimagetochain(theid); // right? } console.writeline(string.format("document page count: {0}", thedoc.pagecount.tostring())); }
edit 2:unfortunately calling addimageurl multiple times when generating pdf documents doesn't seem work...
finally found reliable solution. instead of executing addimageurl() function on same underlying document, should execute addimageurl() function on it's own doc document , build collection of documents @ end assemble 1 document using append() method. here code:
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, "http://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 page of html should contain. thedoc.htmloptions.contentcount = 10;// otherwise page assumed invalid. thedoc.htmloptions.retrycount = 10; // try obtain html page 10 times thedoc.htmloptions.timeout = 180000;// page must obtained in less 10 seconds thedoc.rect.inset(0, 10); // set document thedoc.rect.position(5, 15); thedoc.rect.width = 602; thedoc.rect.height = 767; thedoc.htmloptions.pagecacheenabled = false; int theid = thedoc.addimageurl(url, true, 0, true); while (thedoc.chainable(theid)) { thedoc.page = thedoc.addpage(); theid = thedoc.addimagetochain(theid); } //flatten document (int = 1; <= thedoc.pagecount; i++) { thedoc.pagenumber = i; thedoc.flatten(); } return thedoc; } }
Comments
Post a Comment