我正在嘗試製作在Google地圖上顯示位置的網頁的pdf。唯一的問題是,在ABCpdf呈現pdf時,Javascript並沒有完全完成。它不完整。在呈現pdf之前,如何讓ABDpdf等到JavaScript完成100%完成。這是我到目前爲止所嘗試的。讓HTML在呈現PDF之前完成Javascript pdf
Doc theDoc = new Doc();
string theURL = url;
// Set HTML options
theDoc.HtmlOptions.AddLinks = true;
theDoc.HtmlOptions.UseScript = true;
theDoc.HtmlOptions.PageCacheEnabled = false;
//theDoc.HtmlOptions.Engine = EngineType.Gecko;
// JavaScript is used to extract all links from the page
theDoc.HtmlOptions.OnLoadScript = "var hrefCollection = document.all.tags(\"a\");" +
"var allLinks = \"\";" +
"for(i = 0; i < hrefCollection.length; ++i) {" +
"if (i > 0)" +
" allLinks += \",\";" +
"allLinks += hrefCollection.item(i).href;" +
"};" +
"document.documentElement.abcpdf = allLinks;";
// Array of links - start with base URL
theDoc.HtmlOptions.OnLoadScript = "(function(){window.ABCpdf_go = false; setTimeout(function(){window.ABCpdf_go = true;}, 1000);})();";
ArrayList links = new ArrayList();
links.Add(theURL);
for (int i = 0; i < links.Count; i++)
{
// Stop if we render more than 20 pages
if (theDoc.PageCount > 20)
break;
// Add page
theDoc.Page = theDoc.AddPage();
int theID = theDoc.AddImageUrl(links[i] as string);
// Links from the rendered page
string allLinks = theDoc.HtmlOptions.GetScriptReturn(theID);
string[] newLinks = allLinks.Split(new char[] { ',' });
foreach (string link in newLinks)
{
// Check to see if we allready rendered this page
if (links.BinarySearch(link) < 0)
{
// Skip links inside the page
int pos = link.IndexOf("#");
if (!(pos > 0 && links.BinarySearch(link.Substring(0, pos)) >= 0))
{
if (link.StartsWith(theURL))
{
links.Add(link);
}
}
}
}
// Add other pages
while (true)
{
theDoc.FrameRect();
if (!theDoc.Chainable(theID))
break;
theDoc.Page = theDoc.AddPage();
theID = theDoc.AddImageToChain(theID);
}
}
// Link pages together
theDoc.HtmlOptions.LinkPages();
// Flatten all pages
for (int i = 1; i <= theDoc.PageCount; i++)
{
theDoc.PageNumber = i;
theDoc.Flatten();
}
byte[] theData = theDoc.GetData();
Response.Buffer = false; //new
Response.Clear();
//Response.ContentEncoding = Encoding.Default;
Response.ClearContent(); //new
Response.ClearHeaders(); //new
Response.ContentType = "application/pdf"; //new
Response.AddHeader("Content-Disposition", "attachment; filename=farts");
Response.AddHeader("content-length", theData.Length.ToString());
//Response.ContentType = "application/pdf";
Response.BinaryWrite(theData);
Response.End();
theDoc.Clear();
請更具體地說明在其他部分完成之前您希望等待執行哪部分代碼。 – jfriend00 2012-04-17 15:41:16