• thang
  • NEWBIE
  • 0 Points
  • Member since 2013

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 2
    Replies

Hello guys,

 

I am a newbie in apex development. Can you please help if you have any solution as per my code below?

 

I have a .NET web page (ASPX page) that reading a pdf file in webserver and write to HttpResponse as binary as following. The ASPX page using a hash key as a query string parameter to authenticate the valid request. The following 

 

Dim FullPath As String = Server.MapPath(ModuleURL)
Dim content() As Byte = Utilities.ReadBinaryFromFile(FullPath)

Response.ClearHeaders()
Response.ClearContent()
Response.ContentType = "application/pdf"
Response.AddHeader("Content-Disposition", "inline; filename=" & Path.GetFileName(FullPath))
Response.BinaryWrite(content)
Response.End()

 

If I open that on Chrome/IE, the requested pdf file opens correctly.

 

I am trying to use Apex callout and capture the pdf file as a Blob and display the Blob content as pdf in a Visualforce page as following:

 

Visualforce page:

 

<apex:page sidebar="false" showHeader="false" controller="TestGenContentController" contentType="application/pdf">

          <script>
                window.location.href = "data&colon;application/pdf;base64,{!ContentFile}";
          </script>

</apex:page>

 

Controller:

 

public class TestGenContentController {
Public String getContentFile(){
Http h = new Http();
HttpRequest req = new HttpRequest();
HttpResponse res = new HttpResponse();

req.setEndpoint(contentURL);
req.setMethod('GET');
req.setHeader('content-type', 'application/pdf');

//invoke Http request
res = h.send(req);
Blob retBlob = res.getBodyAsBlob();
String retContentFile = EncodingUtil.base64Encode(retBlob);

return retContentFile;

}

 

I alway get incorrect format of the pdf file when executing the visualforce page.

 

 

If I change the statement:

Blob retBlob = res.getBodyAsBlob();

 

to:

String retData = res.getBody();

System.Debug(strData);

 


The debug log in the body of the Respone is as follow:

 <html><head><title>Object moved</title></head><body><h2>Object moved to <a href="/aspx/Pdf/RiskProfileDefinitions.pdf">here</a>.</h2></body></html>

 

Thanks.

 

 

 

 

 

 

 

 

 

  • December 11, 2013
  • Like
  • 0

Hello guys,

 

I am a newbie in apex development. Can you please help if you have any solution as per my code below?

 

I have a .NET web page (ASPX page) that reading a pdf file in webserver and write to HttpResponse as binary as following. The ASPX page using a hash key as a query string parameter to authenticate the valid request. The following 

 

Dim FullPath As String = Server.MapPath(ModuleURL)
Dim content() As Byte = Utilities.ReadBinaryFromFile(FullPath)

Response.ClearHeaders()
Response.ClearContent()
Response.ContentType = "application/pdf"
Response.AddHeader("Content-Disposition", "inline; filename=" & Path.GetFileName(FullPath))
Response.BinaryWrite(content)
Response.End()

 

If I open that on Chrome/IE, the requested pdf file opens correctly.

 

I am trying to use Apex callout and capture the pdf file as a Blob and display the Blob content as pdf in a Visualforce page as following:

 

Visualforce page:

 

<apex:page sidebar="false" showHeader="false" controller="TestGenContentController" contentType="application/pdf">

          <script>
                window.location.href = "data&colon;application/pdf;base64,{!ContentFile}";
          </script>

</apex:page>

 

Controller:

 

public class TestGenContentController {
Public String getContentFile(){
Http h = new Http();
HttpRequest req = new HttpRequest();
HttpResponse res = new HttpResponse();

req.setEndpoint(contentURL);
req.setMethod('GET');
req.setHeader('content-type', 'application/pdf');

//invoke Http request
res = h.send(req);
Blob retBlob = res.getBodyAsBlob();
String retContentFile = EncodingUtil.base64Encode(retBlob);

return retContentFile;

}

 

I alway get incorrect format of the pdf file when executing the visualforce page.

 

 

If I change the statement:

Blob retBlob = res.getBodyAsBlob();

 

to:

String retData = res.getBody();

System.Debug(strData);

 


The debug log in the body of the Respone is as follow:

 <html><head><title>Object moved</title></head><body><h2>Object moved to <a href="/aspx/Pdf/RiskProfileDefinitions.pdf">here</a>.</h2></body></html>

 

Thanks.

 

 

 

 

 

 

 

 

 

  • December 11, 2013
  • Like
  • 0