本文整理汇总了C#中Doc.GetData方法的典型用法代码示例。如果您正苦于以下问题:C# Doc.GetData方法的具体用法?C# Doc.GetData怎么用?C# Doc.GetData使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doc
的用法示例。
在下文中一共展示了Doc.GetData方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Page_Load
protected void Page_Load(object sender, EventArgs e)
{
if (Request.QueryString["xID"] == null)
{
SessionObject.RedirectMessage = "No entity ID provided in URL.";
Response.Redirect("~/PortalSelection.aspx", true);
}
else
{
_addendumID = GetDecryptedEntityId(X_ID);
}
Doc doc = new Doc();
doc = Assessment.RenderAssessmentAddendumToPdf(_addendumID, ConfigHelper.GetImagesUrl());
byte[] theData = doc.GetData();
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "inline; filename=MyPDF.PDF");
Response.AddHeader("content-length", theData.Length.ToString());
Response.BinaryWrite(theData);
ThinkgateEventSource.Log.ApplicationEvent(MethodBase.GetCurrentMethod().DeclaringType.ToString() + "->" + MethodBase.GetCurrentMethod().Name, "Finished rendering PDF for addendum " + _addendumID, string.Empty);
}
示例2: Convert
public byte[] Convert(string link)
{
try
{
var theDoc = new Doc();
theDoc.MediaBox.String = "A4";
theDoc.SetInfo(0, "License", "141-819-141-276-8435-093");
theDoc.Rect.Inset(10, 5);
theDoc.HtmlOptions.AddLinks = true;
//theDoc.HtmlOptions.AddMovies = true;
theDoc.Page = theDoc.AddPage();
theDoc.HtmlOptions.PageCacheEnabled = false;
var theId = theDoc.AddImageUrl(link);
while (true)
{
if (!theDoc.Chainable(theId))
break;
theDoc.Page = theDoc.AddPage();
theId = theDoc.AddImageToChain(theId);
}
// Link pages together
theDoc.HtmlOptions.LinkPages();
for (var i = 1; i <= theDoc.PageCount; i++)
{
theDoc.PageNumber = i;
theDoc.Flatten();
}
var buffer = theDoc.GetData();
theDoc.Clear();
return buffer;
}
catch (Exception ex)
{
throw ex;
}
}
示例3: Page_Load
protected void Page_Load(object sender, EventArgs e)
{
if (Request.QueryString["xID"] == null)
{
SessionObject.RedirectMessage = "No entity ID provided in URL.";
Response.Redirect("~/PortalSelection.aspx", true);
}
else
{
_itemID = GetDecryptedEntityId(X_ID);
Boolean success;
if (Boolean.TryParse(Encryption.DecryptString(Request.QueryString["TestQuestion"]),out success))
{
_testQuestion = success;
}
else
{
SessionObject.RedirectMessage = "No Test/Bank parameter provided in URL.";
Response.Redirect("~/PortalSelection.aspx", true);
}
}
Doc doc = new Doc();
Session["PDFimageURL"] = ConfigHelper.GetImagesUrl(); //Bug 16910 fix - images not displaying in PDF
doc = Assessment.RenderAssessmentItemToPdf(_itemID, _testQuestion, ConfigHelper.GetImagesUrl());
byte[] theData = doc.GetData();
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "inline; filename=MyPDF.PDF");
Response.AddHeader("content-length", theData.Length.ToString());
Response.BinaryWrite(theData);
Session.Remove("PDFimageURL"); //Bug 16910 fix - images not displaying in PDF
ThinkgateEventSource.Log.ApplicationEvent(MethodBase.GetCurrentMethod().DeclaringType.ToString() + "->" + MethodBase.GetCurrentMethod().Name, "Finished rendering PDF for" + (_testQuestion ? "test question" : " bank question") + _itemID, string.Empty);
}
示例4: IsQualifiedUrl
/// <summary>
/// Convert the HTML code from the specified URL to a PDF document and send the
/// document as an attachment to the browser
/// </summary>
/// <param name="sessionTokenId">SessionTokenId given by user to authorize</param>
/// <param name="url">The URL of a page that will be rendered</param>
/// <param name="marginLeft"></param>
/// <param name="marginTop"></param>
/// <returns>a byte array that rendered as a PDF, will be null if error</returns>
Stream IPrintServiceV1.ConvertUrlToPdf(string sessionTokenId, string url, int marginLeft, int marginTop)
{
Stream returnStream = null;
if (marginLeft < 10000 && marginTop < 10000)
{
try
{
bool isQualified = IsQualifiedUrl(url.ToString());
if (isQualified)
{
// Create a Doc object
XSettings.InstallRedistributionLicense(licenseKey);
using (Doc theDoc = new Doc())
{
//theDoc.SetInfo(0, "RenderDelay", "1000");
theDoc.HtmlOptions.UseScript = true;
theDoc.HtmlOptions.UseActiveX = true;
theDoc.HtmlOptions.UseVideo = true;
theDoc.HtmlOptions.PageCacheEnabled = true;
theDoc.HtmlOptions.Timeout = 120000; // 120 seconds
theDoc.Rect.Inset(marginLeft, marginTop); // add margin
// Add the first page of HTML. Save the returned ID as this will be used to add subsequent pages
theDoc.Page = theDoc.AddPage();
int theID = theDoc.AddImageUrl(url.ToString());
// Now chain subsequent pages together. Stop when reach a page which wasn't truncated.
while (true)
{
if (!theDoc.Chainable(theID))
break;
theDoc.Page = theDoc.AddPage();
theDoc.Rendering.DotsPerInch = constDotPerInches; // DPI
theDoc.Rendering.SaveQuality = constSaveQuality; // Quality
theID = theDoc.AddImageToChain(theID);
}
// After adding the pages we can flatten them. 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;
theDoc.Flatten();
}
// Get pdf data from the Doc object
returnStream = new MemoryStream(theDoc.GetData());
//returnByte = theDoc.GetData();
theDoc.Clear();
}
}
//TO-DO: Add the HTTP Status Code 403 (Forbidden) when the url is not in supported list
}
catch (UriFormatException uriFormatException)
{
WebOperationContext.Current.OutgoingResponse.StatusCode = HttpStatusCode.BadRequest;
LoggerHelperV1.Error(AssemblyName, AssemblyVersion, Environment.MachineName,
uriFormatException.StackTrace,
HttpUtility.UrlEncode(url.ToString()) + uriFormatException.Message +
uriFormatException.StackTrace);
returnStream = null;
}
catch (WebException webException)
{
WebOperationContext.Current.OutgoingResponse.StatusCode = HttpStatusCode.NotFound;
LoggerHelperV1.Error(AssemblyName, AssemblyVersion, Environment.MachineName, webException.StackTrace,
HttpUtility.UrlEncode(url.ToString()) + webException.Message +
webException.StackTrace);
returnStream = null;
}
catch (Exception ex)
{
WebOperationContext.Current.OutgoingResponse.StatusCode = HttpStatusCode.BadRequest;
LoggerHelperV1.Error(AssemblyName, AssemblyVersion, Environment.MachineName, ex.StackTrace,
HttpUtility.UrlEncode(url.ToString()) + ex.Message + ex.StackTrace);
returnStream = null;
}
if (WebOperationContext.Current != null)
{
WebOperationContext.Current.OutgoingResponse.ContentType = "application/pdf";
HttpResponseHeader cacheHeader = HttpResponseHeader.CacheControl;
WebOperationContext.Current.OutgoingResponse.Headers.Add(cacheHeader,
string.Format(CultureInfo.InvariantCulture,
"max-age={0}, must-revalidate",
CachingDuration));
//Add one day caching
}
//.........这里部分代码省略.........
示例5: btnPrintBtn_Click
protected void btnPrintBtn_Click(object sender, System.Web.UI.ImageClickEventArgs e)
{
Doc theDoc = new Doc();
//clear caching?
theDoc.HtmlOptions.PageCacheEnabled = false;
theDoc.HtmlOptions.UseNoCache = true;
theDoc.HtmlOptions.PageCacheClear();
theDoc.HtmlOptions.PageCachePurge();
theDoc.HtmlOptions.UseResync = true;
theDoc.Rect.String = "20 90 580 750";
string hostURL = (HttpContext.Current.Request.IsSecureConnection ? "https://" : "http://") + HttpContext.Current.Request.Url.Host.ToString();
string callUrl = ResolveUrl("~/Controls/Credentials/PDF/CredentialListPdf.aspx");
int theID;
theID = theDoc.AddImageUrl(hostURL + callUrl);
while (true)
{
if (!theDoc.Chainable(theID))
break;
theDoc.Page = theDoc.AddPage();
theID = theDoc.AddImageToChain(theID);
}
for (int i = 1; i <= theDoc.PageCount; i++)
{
theDoc.PageNumber = i;
theDoc.Flatten();
}
theDoc = AddHeaderFooter(theDoc);
byte[] pdf = theDoc.GetData();
Response.Clear();
Response.ClearHeaders();
Response.ClearContent();
Response.AddHeader("Content-Disposition", "attachment; filename=" + "CredentialList" + ".pdf");
Response.AddHeader("content-length", pdf.Length.ToString());
Response.ContentType = "application/pdf";
Response.BinaryWrite(pdf);
Response.End();
}
示例6: ConvertHtmlString
public byte[] ConvertHtmlString(string customData)
{
try
{
var theDoc = new Doc();
theDoc.MediaBox.String = "A4";
theDoc.SetInfo(0, "License", "141-819-141-276-8435-093");
theDoc.Rect.Inset(10, 5);
theDoc.HtmlOptions.AddLinks = true;
theDoc.Page = theDoc.AddPage();
//AbcPdf cache request for 10 min consider for crucial cases.
var theId = theDoc.AddImageHtml(customData);
while (true)
{
if (!theDoc.Chainable(theId))
break;
theDoc.Page = theDoc.AddPage();
theId = theDoc.AddImageToChain(theId);
}
// Link pages together
theDoc.HtmlOptions.LinkPages();
for (var i = 1; i <= theDoc.PageCount; i++)
{
theDoc.PageNumber = i;
theDoc.Flatten();
}
var buffer = theDoc.GetData();
theDoc.Clear();
return buffer;
}
catch (Exception ex)
{
throw ex;
}
}
示例7: PDFForHtml
public static byte[] PDFForHtml(string html)
{
// Create ABCpdf Doc object
var doc = new Doc();
doc.HtmlOptions.Engine = EngineType.Gecko;
doc.HtmlOptions.ForGecko.ProcessOptions.LoadUserProfile = true;
doc.HtmlOptions.HostWebBrowser = true;
doc.HtmlOptions.BrowserWidth = 800;
doc.HtmlOptions.ForGecko.InitialWidth = 800;
// Add html to Doc
int theID = doc.AddImageHtml(html);
// Loop through document to create multi-page PDF
while (true)
{
if (!doc.Chainable(theID))
break;
doc.Page = doc.AddPage();
theID = doc.AddImageToChain(theID);
}
// Flatten the PDF
for (int i = 1; i <= doc.PageCount; i++)
{
doc.PageNumber = i;
doc.Flatten();
}
// Get PDF as byte array. Couls also use .Save() to save to disk
var pdfbytes = doc.GetData();
doc.Clear();
return pdfbytes;
}
示例8: GetPdfFromHtml
public static byte[] GetPdfFromHtml(string html)
{
Doc thisDoc = new Doc();
thisDoc.Rect.Height = 770;
thisDoc.Rect.Bottom = 15;
int pageId = thisDoc.AddImageHtml(html);
while (thisDoc.Chainable(pageId))
{
thisDoc.Page = thisDoc.AddPage();
pageId = thisDoc.AddImageToChain(pageId);
}
for (int i = 1; i <= thisDoc.PageCount; i++)
{
thisDoc.PageNumber = i;
thisDoc.Flatten();
}
return thisDoc.GetData();
}
示例9: PrintReport_Click
protected void PrintReport_Click(object sender, EventArgs e)
{
Doc theDoc = new Doc();
//HttpCookie cookie = new HttpCookie("userID", userID.ToString());//kc testing
//theDoc.HtmlOptions.HttpAdditionalHeaders = "Cookie: userID=" + userID;
//theDoc.HtmlOptions.NoCookie = true;
theDoc.AddImageUrl("http://"+Request.Url.Authority+"/PrintableReport.aspx?userID=" + userID);
byte[] theData = theDoc.GetData();
Response.Clear();
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "inline; filename=MyPDF.PDF");
Response.AddHeader("content-length", theData.Length.ToString());
Response.BinaryWrite(theData);
Response.End();
}
示例10: btnPrintBtn_Click
protected void btnPrintBtn_Click(object sender, System.Web.UI.ImageClickEventArgs e)
{
int credentialID = Convert.ToInt32(Request.QueryString["credentialID"]);
Doc theDoc = new Doc();
//clear caching?
theDoc.HtmlOptions.PageCacheEnabled = false;
theDoc.HtmlOptions.UseNoCache = true;
theDoc.HtmlOptions.PageCacheClear();
theDoc.HtmlOptions.PageCachePurge();
theDoc.HtmlOptions.UseResync = true;
theDoc.Rect.String = "10 90 600 750";
string selectedCriteria = Session["selectedCriteria"].ToString();
string hostURL = (HttpContext.Current.Request.IsSecureConnection ? "https://" : "http://") + HttpContext.Current.Request.Url.Host.ToString();
string callUrl = ResolveUrl("~/Controls/Credentials/PDF/StudentCountListPdf.aspx?xCriteria=" + selectedCriteria);
int theID;
theID = theDoc.AddImageUrl(hostURL + callUrl);
while (true)
{
if (!theDoc.Chainable(theID))
break;
theDoc.Page = theDoc.AddPage();
theID = theDoc.AddImageToChain(theID);
}
for (int i = 1; i <= theDoc.PageCount; i++)
{
theDoc.PageNumber = i;
theDoc.Flatten();
}
theDoc = AddHeaderFooter(theDoc);
byte[] pdf = theDoc.GetData();
Response.Clear();
Response.ClearHeaders(); // Add this line
Response.ClearContent(); // Add this line
//string filename = lblStudentName.Text.Replace(',', '-') + "EarnedCredentialList";
Response.AddHeader("Content-Disposition", "attachment; filename=" + "CredentialList" + ".pdf");
Response.AddHeader("content-length", pdf.Length.ToString());
Response.ContentType = "application/pdf";
Response.BinaryWrite(pdf);
Response.End();
theDoc.Clear();
}
示例11: Page_Load
protected void Page_Load(object sender, EventArgs e)
{
int assessmentID = 0;
int formID;
string answerKey;
string rawPrintList;
Boolean isAdminInst = false;
if (Request.QueryString["xID"] == null)
{
SessionObject.RedirectMessage = "No entity ID provided in URL.";
Response.Redirect("~/PortalSelection.aspx", true);
}
else
{
assessmentID = GetDecryptedEntityId(X_ID);
}
rawPrintList = Request.QueryString["print_list"];
if(!string.IsNullOrEmpty(Request.QueryString["isAdminInst"]))
{
isAdminInst = Convert.ToBoolean(DataIntegrity.ConvertToInt(Request.QueryString["isAdminInst"]));
}
if (String.IsNullOrEmpty(rawPrintList))
{
isAdminInst = true; /* For All Preview Administration instructions will be visible ,it will be turned on/off while printing */
answerKey = Request.QueryString["answerKey"];
formID = DataIntegrity.ConvertToInt(Request.QueryString["formID"]);
if (formID == 0)
{
SessionObject.RedirectMessage = "No entity ID provided in URL.";
Response.Redirect("~/PortalSelection.aspx", true);
}
Doc doc = Assessment.RenderAssessmentToPdf(assessmentID, formID, String.IsNullOrEmpty(answerKey) ? PdfRenderSettings.PrintTypes.Assessment : PdfRenderSettings.PrintTypes.AnswerKey, ConfigHelper.GetImagesUrl(),isAdminInst);
byte[] theData = doc.GetData();
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "inline; filename=MyPDF.PDF");
Response.AddHeader("content-length", theData.Length.ToString());
Response.BinaryWrite(theData);
ThinkgateEventSource.Log.ApplicationEvent(MethodBase.GetCurrentMethod().DeclaringType.ToString() + "->" + MethodBase.GetCurrentMethod().Name, "Finished rendering assessment " + assessmentID, string.Empty);
}
else
{
var serializer = new System.Web.Script.Serialization.JavaScriptSerializer();
var newItems = serializer.Deserialize<object[]>(rawPrintList);
var assessmentPrintBatchHelpers = new List<AssessmentPrintBatchHelper>();
foreach (var rawset in newItems)
{
var set = ((object[]) rawset);
assessmentPrintBatchHelpers.Add(new AssessmentPrintBatchHelper(DataIntegrity.ConvertToInt(set[(int)_printListFields.FormID]), DataIntegrity.ConvertToInt(set[(int)_printListFields.AssessmentCount]), DataIntegrity.ConvertToInt(set[(int)_printListFields.AnswerKeyCount]), DataIntegrity.ConvertToInt(set[(int)_printListFields.RubricCount])));
/*Doc subdoc = Assessment.RenderAssessmentToPdf(assessmentID, DataIntegrity.ConvertToInt(set[(int)_printListFields.FormID]), (PdfRenderSettings.PrintTypes) set[(int)_printListFields.Type]);
for (var j = 0; j < (int)set[(int)_printListFields.Count]; j++)
{
doc.Append(subdoc);
}*/
}
Doc doc = new Doc();
doc = CreateTestDoc(assessmentID, assessmentPrintBatchHelpers, doc, ConfigHelper.GetImagesUrl(), isAdminInst);
byte[] theData = doc.GetData();
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "inline; filename=MyPDF.PDF");
Response.AddHeader("content-length", theData.Length.ToString());
Response.BinaryWrite(theData);
ThinkgateEventSource.Log.ApplicationEvent(MethodBase.GetCurrentMethod().DeclaringType.ToString() + "->" + MethodBase.GetCurrentMethod().Name, "Finished rendering assessment " + assessmentID, string.Empty);
}
/*
#if DEBUG
// having problem with adobe opening file in browser on my machine, simple work around for development
try
{
doc.Save(@"c:\temp\debug_pdf.pdf");
} catch
{
}
#endif
*/
}
示例12: CreatePdf
public byte[] CreatePdf(PDFService.Settings settings)
{
if (settings == null) throw new ArgumentNullException("settings");
if (!settings.Uris.Any()) throw new ArgumentException("No URIs provided to create PDF from");
using (Doc pdf = new Doc())
{
pdf.HtmlOptions.Engine = EngineType.Gecko;
pdf.HtmlOptions.Timeout = (int)settings.Timeout.TotalMilliseconds;
pdf.HtmlOptions.RetryCount = settings.RetryCount;
pdf.HtmlOptions.PageCacheClear();
pdf.HtmlOptions.PageCacheEnabled = false;
pdf.HtmlOptions.AddForms = settings.UseForms;
pdf.HtmlOptions.AddLinks = settings.UseLinks;
pdf.HtmlOptions.UseScript = settings.UseScript;
pdf.Color.Red = 255;
pdf.Color.Green = 255;
pdf.Color.Blue = 255;
pdf.Rect.Inset(10, 10);
pdf.FillRect();
// If selected, make the PDF in landscape format
if (settings.UseLandscapeOrientation)
{
pdf.Transform.Rotate(90, pdf.MediaBox.Left, pdf.MediaBox.Bottom);
pdf.Transform.Translate(pdf.MediaBox.Width, 0);
pdf.Rect.Width = pdf.MediaBox.Height;
pdf.Rect.Height = pdf.MediaBox.Width;
}
int imageId = 0;
// For each URI provided, add the result to the output doc
foreach (String uri in settings.Uris)
{
if (imageId != 0)
{
pdf.Page = pdf.AddPage();
}
// Render the web page by uri and return the image id for chaining
imageId = pdf.AddImageUrl(uri, paged: true, width: 0, disableCache: false);
while (true)
{
// Stop when we reach a page which wasn't truncated, per the examples
if (!pdf.Chainable(imageId)) break;
// Add a page to the pdf and sets the page id
pdf.Page = pdf.AddPage();
// Add the previous image to the chain and set the image id
imageId = pdf.AddImageToChain(imageId);
}
}
// flatten the pages
for (var ii = 1; ii <= pdf.PageCount; ii++)
{
pdf.PageNumber = ii;
pdf.Flatten();
}
// Return the byte array representing the pdf
return pdf.GetData();
}
}