Display PDF document within an asp.net page with other controls
Displaying PDF files in ASP.NET is a simple task when you want the PDF to take the entire page. Or even easier when you want the user to have the option of open/save PDF document.
Recently I was required to write an ASP.NET page to display the messages sent using BizTalk Server 2005 orchestration.
Background: I am developing a BAM custom page to let the users view the messages and re-send them again as they desire.
the page had to have a big text box showing the incoming message, and another:
1. text box to display the outgoing message in case of text or XML formats
or
2. PDF viewer if the document is PDF.
The solution to this was to use an iFrame that calls the same page referencing the PDF document to load it.
watch.. watch the magic
create an iFrame
(just look it up somewhere else... it's rendering here.. i dont wann deal with it now)
and in your C# code behind file:
if (Request.Params["pdf"] != null) DisplayPDF();
else
{
TextBox1.Visible = true;
}
public void DisplayPDF()
{
//using the BamManagementService to get the data
localhost.BamManagementService oBMS = new localhost.BamManagementService();
oBMS.UseDefaultCredentials = true; //this line gets rid of your 401 unauthorized access error when using the web service
localhost.Reference oRef = new localhost.Reference();
//
oRef = oBMS.GetReferences("EndToEnd", "EndToEndActivity", "1", "MessageBody")[0];
//oRef = oBMS.GetReferences(" ", "Ordering Progress Status", "5ce82c99-5af9-4913-ad9a-33f9a2e66600", "MessageBody")[0];
String PDFString = oRef.LongReferenceData.ToString();
//my PDF is encoded so im decoding it.. you may skip this
byte[] Bytes = new byte[PDFString.Length];
Bytes = System.Convert.FromBase64String(PDFString);
//just in case Response has stuff in it
Response.Clear();
//to show PDF because it's foreign to .NET
Response.ContentType = "application/pdf";
//writing the stream of bytes to create the PDf
Response.BinaryWrite(Bytes);
Response.Flush();
}
im sure i'll run into this.. so im documenting it!
have fun hunting BAM
Recently I was required to write an ASP.NET page to display the messages sent using BizTalk Server 2005 orchestration.
Background: I am developing a BAM custom page to let the users view the messages and re-send them again as they desire.
the page had to have a big text box showing the incoming message, and another:
1. text box to display the outgoing message in case of text or XML formats
or
2. PDF viewer if the document is PDF.
The solution to this was to use an iFrame that calls the same page referencing the PDF document to load it.
watch.. watch the magic
create an iFrame
and in your C# code behind file:
if (Request.Params["pdf"] != null) DisplayPDF();
else
{
TextBox1.Visible = true;
}
public void DisplayPDF()
{
//using the BamManagementService to get the data
localhost.BamManagementService oBMS = new localhost.BamManagementService();
oBMS.UseDefaultCredentials = true; //this line gets rid of your 401 unauthorized access error when using the web service
localhost.Reference oRef = new localhost.Reference();
//
oRef = oBMS.GetReferences("EndToEnd", "EndToEndActivity", "1", "MessageBody")[0];
//oRef = oBMS.GetReferences(" ", "Ordering Progress Status", "5ce82c99-5af9-4913-ad9a-33f9a2e66600", "MessageBody")[0];
String PDFString = oRef.LongReferenceData.ToString();
//my PDF is encoded so im decoding it.. you may skip this
byte[] Bytes = new byte[PDFString.Length];
Bytes = System.Convert.FromBase64String(PDFString);
//just in case Response has stuff in it
Response.Clear();
//to show PDF because it's foreign to .NET
Response.ContentType = "application/pdf";
//writing the stream of bytes to create the PDf
Response.BinaryWrite(Bytes);
Response.Flush();
}
im sure i'll run into this.. so im documenting it!
have fun hunting BAM
