Visualforce ページ:
<apex:page controller="ViewPdf">
<iframe src="data:{!att.ContentType};base64,{!pdf}" >
</iframe></apex:page>
*注意: 「data:」URI が一部のブラウザでグローバルにサポートされていない場合があります。
たとえば、IE では data: URI が でサポートされていません。
ブラウザによって、Salesforce ではコントロールできない独自のサイズ制限が設けられています。
例:
コントローラー:
public class ViewPdf {
public Attachment att {
get {
if (att == null) {
att = [SELECT Body, ContentType, Name FROM Attachment WHERE ID = '00PG0000004COZU'];
}
return att;
}
private set;
}
public String pdf {
get {
return EncodingUtil.Base64Encode(att.body);
}
}
}
エラー「This content is blocked.Contact the site owner to fix the issue.」(このコンテンツはブロックされています。問題を修正するには、サイト所有者にお問い合わせください。)
注記: Chrome の 2MB 制限は、オブジェクト URL を作成することで回避できます。
// Blob からオブジェクト URL を作成します。
var objectUrl = window.URL.createObjectURL(blob);
実装の例を次に示します:
var objectUrl = window.URL.createObjectURL(blob);
<apex:page showHeader="false" applyHtmlTag="false" cache="true" readOnly="true" controller="HDMS_ViewPDF">
<script>
// この関数はページの読み込み後に呼び出されます
function loadPDF() {
var contentVersion = '{getContentVersionRecord}';
var base64Data2 = btoa(contentVersion.versiondata);
console.log('base64Data2' + base64Data2);
var fileType = contentVersion.fileType;
console.log('fileType' + fileType);
// base64文字列をバイナリデータにデコード
var binaryData = atob(base64Data);
// バイナリデータからUint8Arrayを作成
var byteArray = new Uint8Array(binaryData.length);
for (var i = 0; i < binaryData.length; i++) {
byteArray[i] = binaryData.charCodeAt(i) & 0xff;
}
// Uint8ArrayからBlobを作成
console.log("base64Type.type: "+ base64Data.type);
var blob = new Blob([byteArray], {type: byteArray.type});
//var blob = new Blob([byteArray], {type: "application/pdf"});
// BlobからオブジェクトURLを作成
var objectUrl = window.URL.createObjectURL(blob);
// iframeのsrc属性としてオブジェクトURLを設定
document.getElementById('pdf-viewer').src = objectUrl;
}
</script>
<iframe id="pdf-viewer" height="800px" width="100%" title="TestData"></iframe>
<script>
window.onload = loadPDF;
</script>
</apex:page>
// Apexコントローラからbase64エンコードされたPDFデータを取得
var base64Data = '{!gePdfInfo}';
000385665

We use three kinds of cookies on our websites: required, functional, and advertising. You can choose whether functional and advertising cookies apply. Click on the different cookie categories to find out more about each category and to change the default settings.
Privacy Statement
Required cookies are necessary for basic website functionality. Some examples include: session cookies needed to transmit the website, authentication cookies, and security cookies.
Functional cookies enhance functions, performance, and services on the website. Some examples include: cookies used to analyze site traffic, cookies used for market research, and cookies used to display advertising that is not directed to a particular individual.
Advertising cookies track activity across websites in order to understand a viewer’s interests, and direct them specific marketing. Some examples include: cookies used for remarketing, or interest-based advertising.