Monday, May 12, 2014

ASP.NET กับ Crystal Report เรื่อง ปัญหาขนาด font


สำหรับ ASP.NET ที่เราพัฒนากันนั้น ส่วนใหญ่ (เกือบ 100%) คงได้ใช้ Crystal Report ช่วยในการทำเอกสาร หรือ รายงาน กัน

และเมื่อแสดงผลรายงานทาง Web Browser ตัว ASP.NET Crystal Report โดย Default จะทำการแปลงรายงานไปเป็น PDF ไฟล์แล้วจึงแสดงบน Web Browser

ปัญหาก็คือ ตัว Engine ของ Crystal Report ขณะที่มันแปลงรายงานไปเป็น pdf นั้น มันทำการลดขนาดของ font ลงไปด้วย ทำให้พบปัญหาขนาดตัวอักษรที่ได้ออกแบบไว้ใน Designer กับตอนรันออกมา มีผลลัพธ์ไม่เหมือนกัน

วิธีการแก้ไข จะต้องแก้ไขที่ registry ของเครื่อง Developer (เมื่อนำขึ้น Production ก็ต้องทำที่เครื่อง Web Server ด้วยนะครับ) ดังนี้

** ขอบคุณ jbkumar จาก forums.asp.net/ สำหรับวิธีการแก้ไขนี้ครับ **
To fix the bug, just follow steps below by adding 2 registry keys.

1. Select Start > Run. Type regedit and click OK.

2. For Crystal Reports 2008, Expand HKEY_CURRENT_USER\Software\Business Objects\Suite 12.0\Crystal Reports\Export.

For Crystal Reports 11.0, Expand HKEY_CURRENT_USER\Software\Business Objects\Crystal Reports.

For Crystal Reports 10.0, Expand HKEY_CURRENT_USER\SOFTWARE\Crystal Decisions\10.0\Crystal Reports\Export

For Crystal Reports 9,0, Expand HKEY_CURRENT_USER\software\crystal decisions\9.0\Crystal Reports\Export

3. Right-click the Export folder and select New > Key. This creates a new folder. Name the new folder PDF.

4. Right-click the PDF folder and select New > DWORD Value.

5. Name this 'ForceLargerFonts' with no quotes and note that it is case sensitive.

6. Double-click ForceLargerFonts and change the Value data to 1 and click OK.

7. Close all the registry folders and expand the following registry For Crystal Reports 2008, HKEY_LOCAL_MACHINE\Software\Business Objects\Suite 12.0\Crystal Reports.

For Crystal Reports 11.0, HKEY_LOCAL_MACHINE\Software\Business Objects\Suite 11.0.

For Crystal Reports 10.0, HKEY_LOCAL_MACHINE\SOFTWARE\Crystal Decisions\10.0\Crystal Reports

For Crystal Reports 9.0, HKEY_LOCAL_MACHINE\Software\Crystal Decisions\9.0\Crystal Reports

8. Right-click the Crystal Reports folder and select New > Key. Name this key Export.

9. Right-click the Export folder and select New > Key. This creates a new folder. Name this folder PDF.

10. Repeat steps 4 through 6.

11. Close the Registry Editor and restart Crystal Reports.


After adding these two registry keys, Crystal Reports won't have this font size problem any more.

************* สำหรับตอน Deploy ขึ้น IIS Server ให้ทำแบบนี้แทนครับ *************
Credit: http://www.morovia.com/kb/Font-size-decreases-exporting-PDF-Crystal-Reports-10053.html

 เมื่อแก้ไข Register แล้ว ให้ restart IIS service ด้วยครับ


////////// NooM ///////////

No comments: