Translate

2011年5月6日金曜日

VisualforceページをPDF化サンプル

以下のコードは、

Visualforceページの<apex:page>タグの

属性renderAsを使うことで

HTMLではなくPDFとしてユーザに渡すことができるサンプルである。



出自はForce.com開発者コースのVisualforce演習にて

提供されたコードである。






<!-- Visualforce 演習2-1 Visualforce でのPDFの生成 -->
<!-- 申し込み応募用紙をPDFとして提供する -->
<!-- 申し込みの意思表示のために署名させるためにPDFとして提供しているようだ -->
<!-- 申込(Offer__c)の標準コントローラを使用 -->
<!-- pageタグにはrenderAs属性がありこれをpdfと指定するとPDF化して表示できる -->
<apex:page standardController="Offer__c" showHeader="false" renderAs="pdf">
<body>
<center>
<!-- HTMLのtableタグになる -->
<apex:panelGrid columns="1" width="100%">
<!-- 組織の「組織名」 -->
<apex:outputText value="{!$Organization.Name}" styleClass="companyName"/>
<!-- 組織の「町名・番地」 -->
<apex:outputText value="{!$Organization.Street}"/>
<!-- 組織の「市区群」「都道府県」「郵便番号」 -->
<apex:outputText value="{!$Organization.City}, {!$Organization.State} {!$Organization.PostalCode}"/>
<!-- 組織の「電話番号」
<apex:outputText value="{!$Organization.Phone}"/>
</apex:panelGrid>
</center>
<p>
<br/><br/>
<!-- 申込日の表示を英語表記にしている-->
<apex:outputText value="{!CASE( MONTH(Offer__c.Offer_Date__c) ,
1, "January",
2, "February",
3, "March",
4, "April",
5, "May",
6, "June",
7, "July",
8, "August",
9, "September",
10, "October",
11, "November",
12, "December",
"None")} {!DAY(Offer__c.Offer_Date__c)}, {!YEAR(Offer__c.Offer_Date__c)}" />
<br/><br/><br/>
</p>
<p>
<!-- HTMLのtableタグ -->
<apex:panelGrid columns="1" width="100%">
<!-- 応募者氏名 -->
<apex:outputText value="{!Offer__c.Job_Application__r.Candidate__r.First_Name__c} {!Offer__c.Job_Application__r.Candidate__r.Last_Name__c}" styleClass="candidateName"/>
<!-- 応募者住所1 -->
<apex:outputText value="{!Offer__c.Job_Application__r.Candidate__r.Street_Address_1__c}" />
<!-- 応募者住所1 -->
<apex:outputText value="{!Offer__c.Job_Application__r.Candidate__r.Street_Address_2__c}" rendered="{!NOT(ISNULL(Offer__c.Job_Application__r.Candidate__r.Street_Address_2__c))}" />
<!-- 応募者市区群+都道府県+郵便番号 -->
<apex:outputText value="{!Offer__c.Job_Application__r.Candidate__r.City__c}, {!Offer__c.Job_Application__r.Candidate__r.State_Province__c} {!Offer__c.Job_Application__r.Candidate__r.Zip_Postal_Code__c}" />
<!-- 応募者国名(定義されていた場合のみ) -->
<!-- rendered属性が真であれば有効になる -->
<apex:outputText value="{!Offer__c.Job_Application__r.Candidate__r.Country__c}" rendered="{!NOT(ISNULL(Offer__c.Job_Application__r.Candidate__r.Country__c))}" />
<br/>
<!-- Dear+名前 -->
<apex:outputText value="Dear {!Offer__c.Job_Application__r.Candidate__r.First_Name__c}," />
<!-- テキスト -->
<apex:outputText >
<p>
<!-- 募集職種への申し込み開始云々 -->
I am pleased to offer you a position with Universal Containers (the "Company") as a {!Offer__c.Job_Application__r.Position__r.Name} for a start date of {!MONTH(Offer__c.Job_Application__r.Position__r.Start_Date__c)}/{!DAY(Offer__c.Job_Application__r.Position__r.Start_Date__c)}/{!YEAR(Offer__c.Job_Application__r.Position__r.Start_Date__c)}, reporting to {!Offer__c.Job_Application__r.Position__r.Hiring_Manager__r.Name}.
</p>
<p>
<!-- 給与やボーナスの話 -->
If you decide to join us, you will receive an annual base salary of ${!ROUND(Offer__c.Actual_Salary__c,0)} less applicable withholding, which will be paid semi-monthly in accordance with the Company's normal payroll procedures. In addition, you will be eligible to receive a discretionary {!ROUND(Offer__c.Bonus_Percentage__c,0)}% bonus based on individual performance, Company performance, and corporate matrix.
</p>
<p>
<!-- ストックオプションの話 -->
Subject to approval of the Company's Board of Directors, you will be granted an option to acquire {!ROUND(Offer__c.Stock_Options__c,0)} shares of Common Stock, vesting 25% on the first anniversary of the grant date and 1/48th of the grant amount each month thereafter, so long as your employment with the Company continues. The grant price of the stock option and vesting date of the stock option will be set upon Board approval.
</p>
<p>
<!-- 締め切りの話 -->
As a Company employee, you are also eligible to receive certain employee benefits. The Company reserves the right to change the benefits and compensation programs at any time. This offer expires on {!MONTH(Offer__c.Offer_Expiration_Date__c)}/{!DAY(Offer__c.Offer_Expiration_Date__c)}/{!YEAR(Offer__c.Offer_Expiration_Date__c)}, and is contingent upon the results of your background investigation.
</p>
<p>
<!-- 応募者の権利の話 -->
If you choose to accept this offer, your employment with the Company will be voluntarily entered into and will be for no specified period. As a result, you will be free to resign at any time, for any reason or for no reason, as you deem appropriate. The Company will have a similar right and may conclude its employment relationship with you at any time, with or without cause. In addition, you will be required to gain approval from Universal Containers in the event that you are a member of or would like to participate on the board of any existing or new companies.
</p>
<p>
<!-- 身分証明の話 -->
For purposes of federal immigration law, you will be required to provide the Company documentary evidence of your identity and eligibility for employment in the United States. Such documentation must be provided to us within three (3) business days of your hire date, or our employment with you may be terminated.
</p>
<p>
<!-- 申込時合意事項の話 -->
This offer letter fully sets forth all of your compensation information and expectations, and you agree that in making your decision to join the Company you are not relying on any oral or other representations concerning any other compensation or consideration or the duration of your employment with the Company, including but not limited to any value associated with your stock options.
</p>
<p>
<!-- サインして提出云々 -->
To indicate your acceptance of the Company’s offer, please sign and date this letter in the space provided below and return it to me. A duplicate original is enclosed for your records. You will be required to sign an Employee Inventions and Proprietary Rights Assignment Agreement as a condition of your employment. This letter, along with any agreements relating to proprietary rights between you and the Company, set forth the terms of your employment with the Company and supersede any prior representations or agreements, whether written or oral. This letter may not be modified or amended except by a written agreement, signed by the Company and by you.
</p>
<p>
<!-- オリエンテーションの話 -->
If you accept this job offer, your hire date will be on the day that you attend new-hire orientation. Plan to work for the remainder of the business day after new-hire orientation ends.
</p>
<p>
<!-- 申込追加コメント -->
{!Offer__c.Additional_Instructions__c}
</p>
<p>
<!-- しめくくり -->
We look forward to working with you at Universal Containers. Welcome aboard!
</p>
<p>
<!-- 草々 -->
Best Regards,
</p>
<p>
<br/>
<br/>
<br/>
________________________________
<br/>
<!-- 募集職種担当者(所有者)名前 -->
{!Offer__c.Job_Application__r.Position__r.Owner.Name}
<br/>
<!-- 採用担当 -->
Hiring Coordinator, Human Resources
</p>
<p>
<br/>
<!-- 申し込み用紙 -->
<h4>Accept Job Offer</h4>
By signing and dating this letter below, I, {!Offer__c.Job_Application__r.Candidate__r.First_Name__c} {!Offer__c.Job_Application__r.Candidate__r.Last_Name__c}, accept the job offer of {!Offer__c.Job_Application__r.Position__r.Name} by Universal Containers.
<br/>
Signature:__________________________________ Date:_____________
</p>
</apex:outputText>
</apex:panelGrid>
</p>
</body>
</apex:page>





Force.com上のDBデータを使ってPDFが作成できるので

ユーザ間で紙文書としてのやり取りが必要な場合には

活用できる。



ただHTMLとして表現できないものはダメなので

そのへんは癖が結構あると考えた方がいいだろう。

0 件のコメント:

既存アプリケーションをK8s上でコンテナ化して動かす場合の設計注意事項メモ

既存アプリをK8sなどのコンテナにして動かすには、どこを注意すればいいか..ちょっと調べたときの注意事項をメモにした。   1. The Twelve Factors (日本語訳からの転記) コードベース   バージョン管理されている1つのコードベースと複数のデプロイ 依存関係 ...