#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Generate PDF: Khác Biệt Nhựa Sơn Nước vs Sơn Dung Môi
"""

from fpdf import FPDF
import os

class PDF(FPDF):
    def header(self):
        if self.page_no() > 1:
            self.set_font('DejaVu', 'I', 8)
            self.cell(0, 8, 'Khac biet co ban cua nhua trong son he nuoc va son he dung moi', 0, 1, 'C')
            self.ln(2)
    
    def footer(self):
        self.set_y(-15)
        self.set_font('DejaVu', 'I', 8)
        self.cell(0, 10, f'Trang {self.page_no()}/{{nb}}', 0, 0, 'C')

    def chapter_title(self, title):
        self.set_font('DejaVu', 'B', 14)
        self.set_text_color(0, 51, 102)
        self.cell(0, 10, title, 0, 1, 'L')
        self.set_draw_color(0, 51, 102)
        self.line(10, self.get_y(), 200, self.get_y())
        self.ln(4)
        self.set_text_color(0, 0, 0)

    def sub_title(self, title):
        self.set_font('DejaVu', 'B', 11)
        self.set_text_color(51, 51, 51)
        self.cell(0, 8, title, 0, 1, 'L')
        self.ln(1)
        self.set_text_color(0, 0, 0)

    def body_text(self, text):
        self.set_font('DejaVu', '', 10)
        self.multi_cell(0, 5.5, text)
        self.ln(2)

    def bullet(self, text):
        self.set_font('DejaVu', '', 10)
        x = self.get_x()
        self.cell(6, 5.5, chr(8226), 0, 0)
        self.multi_cell(0, 5.5, text)

    def bullet_bold_lead(self, bold_part, normal_part):
        self.set_font('DejaVu', '', 10)
        x = self.get_x()
        self.cell(6, 5.5, chr(8226), 0, 0)
        self.set_font('DejaVu', 'B', 10)
        w_bold = self.get_string_width(bold_part + ' ')
        self.cell(w_bold + 1, 5.5, bold_part + ' ', 0, 0)
        self.set_font('DejaVu', '', 10)
        self.multi_cell(0, 5.5, normal_part)

    def info_box(self, text):
        self.set_fill_color(235, 245, 251)
        self.set_draw_color(0, 102, 153)
        self.set_font('DejaVu', 'I', 10)
        y0 = self.get_y()
        self.set_x(12)
        self.multi_cell(186, 5.5, text, border=1, fill=True)
        self.ln(3)


pdf = PDF()
pdf.alias_nb_pages()

# Add Unicode font
FONT_DIR = r"C:\Windows\Fonts"
# Check available fonts
font_names = [f['name'] for f in pdf.fonts.values()]
if os.path.exists(os.path.join(FONT_DIR, 'arial.ttf')):
    FONT = 'Arial'
    font_path = os.path.join(FONT_DIR, 'arial.ttf')
    font_bold = os.path.join(FONT_DIR, 'arialbd.ttf')
    font_italic = os.path.join(FONT_DIR, 'ariali.ttf')
else:
    # fallback: use built-in courier
    FONT = 'Courier'

if FONT != 'Courier':
    pdf.add_font('Main', '', font_path)
    pdf.add_font('Main', 'B', font_bold)
    pdf.add_font('Main', 'I', font_italic)
else:
    FONT = 'Courier'  # built-in does not support unicode well

# Map all references from 'DejaVu' to 'Main'
import re
script_path = __file__
with open(script_path, 'r', encoding='utf-8') as f:
    content = f.read()
# We'll just use variable FONT_NAME instead
FONT_NAME = FONT

# ====== COVER ======
pdf.add_page()
pdf.ln(40)
pdf.set_font('DejaVu', 'B', 22)
pdf.set_text_color(0, 51, 102)
pdf.multi_cell(0, 10, 'KHAC BIET CO BAN CUA NHUA\nTRONG SON HE NUOC VA\nSON HE DUNG MOI', 0, 1, 'C')
pdf.ln(6)
pdf.set_font('DejaVu', '', 12)
pdf.set_text_color(80, 80, 80)
pdf.cell(0, 8, 'Nghien cuu tong hop tu nhieu nguon khoa hoc & ky thuat', 0, 1, 'C')
pdf.cell(0, 8, 'Thang 06/2026', 0, 1, 'C')
pdf.ln(20)
pdf.set_font('DejaVu', 'I', 9)
pdf.cell(0, 6, 'Nguon tham khao: Wikipedia, ACS Omega, ACS Appl. Mater. Interfaces, Gantrade,', 0, 1, 'C')
pdf.cell(0, 6, 'Hempel, Vichem, Resingroup, PMC, Sinogracechem, Kingcat Paint, Stromann', 0, 1, 'C')

# ====== MUC LUC ======
pdf.add_page()
pdf.chapter_title('Muc luc')
pdf.ln(2)
toc = [
    '1.  Ban chat hoa hoc - Cach ton tai trong he',
    '2.  Co che tao mang (Film Formation)',
    '3.  Phan loai nhua theo he',
    '4.  Cau truc phan tu - Nhau nuoc co gi dac biet?',
    '5.  So sanh tinh chat mang - He qua tu khac biet nhua',
    '6.  Ung dung dien hinh',
    '7.  Xuan huong & Cong nghe moi',
    '8.  Tong ket',
    '9.  Tai lieu tham khao',
]
for t in toc:
    pdf.set_font('DejaVu', '', 11)
    pdf.cell(0, 7, t, 0, 1)

# ====== 1. BAN CHAT ======
pdf.add_page()
pdf.chapter_title('1. Ban chat hoa hoc - Cach ton tai trong he')

pdf.info_box('DAY LA KHAC BIET NEN TANG NHAT: Nhựa dung môi TAN THẬT trong dung môi, tạo dung dịch đồng nhất o cấp phan tu. Nhựa nước PHAN TAN thành hạt, phải qua quá trình kết tụ (coalesce) để tạo màng.')

pdf.sub_title('So sanh co ban')
# Comparison table
pdf.set_font('DejaVu', 'B', 10)
col_w = [70, 60, 60]
pdf.set_fill_color(220, 230, 241)
pdf.cell(col_w[0], 7, 'Yeu to', 1, 0, 'C', fill=True)
pdf.cell(col_w[1], 7, 'Nhựa hệ nước', 1, 0, 'C', fill=True)
pdf.cell(col_w[2], 7, 'Nhựa hệ dung moi', 1, 1, 'C', fill=True)

rows = [
    ['Moi truong mang', 'Nuoc', 'Dung moi huu co\n(xylene, toluene,\nbutyl acetate, white spirit)'],
    ['Cach ton tai', 'Phan tan dang hat\ndispersion/emulsion', 'Hoa tan hoan toan\n(solution)'],
    ['Kich thuoc hat', '50-500 nm (hat rieng re)', 'Phan tu polymer rieng le\n(tan thuc su)'],
    ['Hinh thai trong he', 'Hat nhua ran lo lung\ntrong nuoc', 'Chuoi polymer duoi thang\ntrong dung dich'],
]

pdf.set_font('DejaVu', '', 9)
for r in rows:
    y_start = pdf.get_y()
    # Calculate row height
    heights = []
    for i, txt in enumerate(r):
        pdf.set_xy(10 + sum(col_w[:i]), pdf.get_y())
        pdf.multi_cell(col_w[i], 5, txt, 0, 'L')
        heights.append(pdf.get_y())
    row_h = max(heights) - y_start
    # Redraw with borders
    pdf.set_y(y_start)
    for i, txt in enumerate(r):
        pdf.set_xy(10 + sum(col_w[:i]), pdf.get_y())
        pdf.multi_cell(col_w[i], 5, txt, 1, 'L')
    pdf.set_y(y_start + row_h)

pdf.ln(4)
pdf.body_text('Nguon: Wikipedia - Waterborne resin; ACS Omega 2020; Hempel Technical Guideline')

# ====== 2. CO CHE TAO MANG ======
pdf.add_page()
pdf.chapter_title('2. Co che tao mang (Film Formation)')
pdf.body_text('Day la khac biet lon nhat ve mat vat ly giua hai loai nhua, quyet dinh toan bo tinh chat mang sau khi kho.')

pdf.sub_title('Nhựa hệ dung môi: Bay hoi dung moi + Dong dac')
pdf.bullet('Dung moi bay hoi -> nong do polymer tang dan')
pdf.bullet('Chuoi polymer xich lai gan nhau, cuon chat')
pdf.bullet('Cac chuoi polymer DA HOA TAN SAN -> mang tao ra dong nhat o cap do phan tu')
pdf.bullet('Mang dac, it khuyet tat, chiu luc tot ngay sau khi kho')

pdf.ln(2)
pdf.sub_title('Nhựa hệ nước: Bay hoi + Ep chat + Khuech tan (3 giai doan)')
pdf.set_font('DejaVu', 'B', 10)
pdf.cell(0, 6, 'Giai doan 1: Bay hoi nuoc', 0, 1)
pdf.set_font('DejaVu', '', 10)
pdf.bullet('Nuoc bay hoi -> cac hat nhua xich lai gan nhau')
pdf.ln(1)
pdf.set_font('DejaVu', 'B', 10)
pdf.cell(0, 6, 'Giai doan 2: Ep chat (packing)', 0, 1)
pdf.set_font('DejaVu', '', 10)
pdf.bullet('Nuoc bay tiep -> cac hat ep sat nhau thanh mang luc giac')
pdf.ln(1)
pdf.set_font('DejaVu', 'B', 10)
pdf.cell(0, 6, 'Giai doan 3: Hop nhat & Khuech tan (coalescence & interdiffusion)', 0, 1)
pdf.set_font('DejaVu', '', 10)
pdf.bullet('Cac chuoi polymer khuech tan qua ranh gioi hat -> tao mang lien tuc')
pdf.ln(2)

pdf.info_box('LUU Y: Hệ nước can CHAT TRO TAO MANG (coalescing agent) - vi du Texanol, butyl glycol - de tam thoi lam mem hat nhua (ha Tg) giup chung bien dang va hop nhat. Sau do chat nay bay hoi, tra lai do cung cho mang.')

pdf.ln(1)
pdf.sub_title('So sanh muc do hoan thien')
pdf.body_text('Theo nghien cuu dang tren ACS Applied Materials & Interfaces (2024) va PMC:')
pdf.bullet('Mang tu DUNG DICH (solventborne): polymer tan hoan toan -> mang dong nhat, it khuyet tat')
pdf.bullet('Mang tu PHAN TAN (waterborne): von la cac hat rieng -> de co khuyet tat, co tinh va chiu nuoc kem hon')
pdf.ln(1)
pdf.body_text('Nguon: ACS Appl. Mater. Interfaces 2024; PMC11533165; Scott Bader Knowledge Hub')

# ====== 3. PHAN LOAI NHUA ======
pdf.add_page()
pdf.chapter_title('3. Phan loai nhua theo he')
pdf.body_text('Cung mot "gia dinh" hoa hoc nhung bien tinh khac nhau de phu hop voi he nuoc hoac he dung moi:')

pdf.set_font('DejaVu', 'B', 10)
col_w = [35, 75, 75]
pdf.set_fill_color(220, 230, 241)
pdf.cell(col_w[0], 7, 'Loai nhua', 1, 0, 'C', fill=True)
pdf.cell(col_w[1], 7, 'He nuoc (Waterborne)', 1, 0, 'C', fill=True)
pdf.cell(col_w[2], 7, 'He dung moi (Solventborne)', 1, 1, 'C', fill=True)

class_rows = [
    ['Acrylic', 'Nhu tuong acrylic (emulsion)\npolymer hoa nhu tuong tu\nmonomer acrylate + nuoc', 'Acrylic solution\npolymer tan trong dung moi\n(xylene, butyl acetate...)'],
    ['Polyurethane', 'PUD (Polyurethane Dispersion)\nhat PU nano phan tan trong\nnuoc, dung DMPA lam\nchat nhua hoa noi tai', 'PU solution\npolyurethane tan hoan toan\ntrong dung moi'],
    ['Epoxy', 'Nhu tuong epoxy + chat dong ran\nphan tan nuoc; epoxy bien tinh\nco nhom ua nuoc', 'Epoxy + chat dong ran\nhoa tan trong dung moi'],
    ['Alkyd', 'Alkyd bien tinh (gan nhom\ncarboxyl, trung hoa bang\namine) de tan/disperse\ntrong nuoc', 'Alkyd truyen thong\ntan trong dung moi, kho\nbang oxy hoa dau'],
    ['Polyester', 'Polyester tan trong nuoc nho\nnhom carboxyl du, trung hoa\nbang amine', 'Polyester solution\ntrong dung moi'],
]

pdf.set_font('DejaVu', '', 8.5)
for r in class_rows:
    y_start = pdf.get_y()
    heights = []
    for i, txt in enumerate(r):
        pdf.set_xy(10 + sum(col_w[:i]), pdf.get_y())
        pdf.multi_cell(col_w[i], 5, txt, 0, 'L')
        heights.append(pdf.get_y())
    row_h = max(heights) - y_start
    pdf.set_y(y_start)
    for i, txt in enumerate(r):
        pdf.set_xy(10 + sum(col_w[:i]), pdf.get_y())
        pdf.multi_cell(col_w[i], 5, txt, 1, 'L')
    pdf.set_y(y_start + row_h)

pdf.ln(3)
pdf.body_text('Nguon: Wikipedia Waterborne resin; Gantrade - Chemistry of Waterborne PU; Vichem.vn')

# ====== 4. CAU TRUC PHAN TU ======
pdf.add_page()
pdf.chapter_title('4. Cau truc phan tu - Nhựa nuoc co gi dac biet?')
pdf.body_text('De nhua tan/disperse duoc trong nuoc (von ky nuoc), cac nha hoa hoc phai bien doi cau truc phan tu:')

pdf.sub_title('a) Dua nhom ua nuoc vao mach polymer')
pdf.bullet('Nhom carboxyl (-COOH): dung acrylic acid, methacrylic acid, maleic anhydride')
pdf.bullet('Nhom hydroxyl (-OH), ether, amide')
pdf.bullet('Sau do trung hoa bang base (amine, NH4OH) -> tao muoi -> tan trong nuoc')

pdf.sub_title('b) Dung chat nhua hoa noi tai (internal emulsifier)')
pdf.bullet('Trong PUD: dung DMPA (dimethylolpropionic acid) -> tao nhom carboxyl tren mach PU -> trung hoa tao muoi -> tu phan tan')
pdf.bullet('Ham luong DMPA: 4-8% trong luong -> kiem soat kich thuoc hat')
pdf.bullet('Hat PUD thuong o cap nanomet (ban trong suot)')

pdf.sub_title('c) Dung surfactant ngoai (external)')
pdf.bullet('Hat nhua duoc boc boi lop chat hoat dong be mat')
pdf.bullet('Tao luc day tinh dien giua cac hat -> on dinh phan tan trong nuoc')

pdf.ln(1)
pdf.sub_title('Vi du: Cong thuc bien doi nhua Alkyd')
pdf.body_text('Alkyd thuan tuy la polyester tu dau thuc vat + acid + polyol, ky nuoc. De thanh waterborne alkyd: bun dau + modifed de co du nhom carboxyl du -> trung hoa bang amine (TEA, dimethylethanolamine) -> tan/disperse trong nuoc.')
pdf.ln(1)
pdf.body_text('Nguon: ACS Omega 2020 (Advances in Waterborne Acrylic Resins); Gantrade Blog; Sinogracechem')

# ====== 5. SO SANH TINH CHAT ======
pdf.add_page()
pdf.chapter_title('5. So sanh tinh chat mang - He qua tu khac biet nhua')

pdf.set_font('DejaVu', 'B', 10)
col_w2 = [50, 65, 65]
pdf.set_fill_color(220, 230, 241)
pdf.cell(col_w2[0], 7, 'Tinh chat', 1, 0, 'C', fill=True)
pdf.cell(col_w2[1], 7, 'Nhựa he nuoc', 1, 0, 'C', fill=True)
pdf.cell(col_w2[2], 7, 'Nhựa he dung moi', 1, 1, 'C', fill=True)

prop_rows = [
    ['Do bong (gloss)', 'Thap hon - do cau truc hat\ntao be mat nham vi mo', 'Cao hon - mang dong nhat, min'],
    ['Do cung & dai', 'Co the cao nhung thuong\nkem dai hon', 'Can bang giua cung va dai hon'],
    ['Chiu nuoc', 'Yeu hon - do du luong nhom\nua nuoc / surfactant con sot', 'Tot hon nhieu - khong co\nnhom ua nuoc'],
    ['Chiu hoa chat', 'Kem hon', 'Tot hon - mang dac, it khuyet tat'],
    ['Chiu UV/thoi tiet', 'Tot tuy loai (acrylic aliphatic)\nStyrene kem UV', 'Tot neu chon dung loai'],
    ['Toc do kho', 'Phu thuoc RH; cham trong\nmoi truong am', 'Nhanh - dung moi bay hoi manh'],
    ['Nhiet do tao mang\nthap nhat (MFFT)', 'Cao - can chat tro tao mang', 'Thap - polymer tan de tao mang\no moi nhiet do'],
    ['Chong an mon', 'Kem hon ro ret trong moi\ntruong khac nghiet', 'Vuot troi - mang dac, it tham\nnuoc/oxy/ion'],
]

pdf.set_font('DejaVu', '', 8.5)
for r in prop_rows:
    y_start = pdf.get_y()
    heights = []
    for i, txt in enumerate(r):
        pdf.set_xy(10 + sum(col_w2[:i]), pdf.get_y())
        pdf.multi_cell(col_w2[i], 5, txt, 0, 'L')
        heights.append(pdf.get_y())
    row_h = max(heights) - y_start
    pdf.set_y(y_start)
    for i, txt in enumerate(r):
        pdf.set_xy(10 + sum(col_w2[:i]), pdf.get_y())
        pdf.multi_cell(col_w2[i], 5, txt, 1, 'L')
    pdf.set_y(y_start + row_h)

pdf.ln(3)
pdf.body_text('Nguon: ACS Omega 2020; ACS Appl. Mater. Interfaces 2024; Vichem.vn; Resingroup.net; Kingcat Paint')

# ====== 6. UNG DUNG ======
pdf.add_page()
pdf.chapter_title('6. Ung dung dien hinh')

col_w3 = [50, 65, 65]
pdf.set_font('DejaVu', 'B', 10)
pdf.set_fill_color(220, 230, 241)
pdf.cell(col_w3[0], 7, 'Ung dung', 1, 0, 'C', fill=True)
pdf.cell(col_w3[1], 7, 'He nuoc', 1, 0, 'C', fill=True)
pdf.cell(col_w3[2], 7, 'He dung moi', 1, 1, 'C', fill=True)

app_rows = [
    ['Son kien truc\nnoi that', 'Uu the (VOC thap, mui nhe)', 'It dung (mui, VOC cao)'],
    ['Son ngoai that', 'Co the dung (acrylic\ntinh khiet / silicone)', 'Van chiem uu the trong\nm/truong khac nghiet'],
    ['Son cong nghiep', 'Dang phat trien nhanh', 'Chiem uu the'],
    ['Son o to', 'Lop basecoat/color coat', 'Primer, clear coat van\ndung moi'],
    ['Son go', 'Dang thay the dan', 'Truyen thong (PU,\nnitrocellulose)'],
    ['Son tau bien', 'Han che', 'Chiem uu the'],
    ['Son chong an mon', 'Cai thien dan nhung chua bang', 'Vuot troi, nhat la moi\ntruong khac nghiet'],
]

pdf.set_font('DejaVu', '', 9)
for r in app_rows:
    y_start = pdf.get_y()
    heights = []
    for i, txt in enumerate(r):
        pdf.set_xy(10 + sum(col_w3[:i]), pdf.get_y())
        pdf.multi_cell(col_w3[i], 5, txt, 0, 'L')
        heights.append(pdf.get_y())
    row_h = max(heights) - y_start
    pdf.set_y(y_start)
    for i, txt in enumerate(r):
        pdf.set_xy(10 + sum(col_w3[:i]), pdf.get_y())
        pdf.multi_cell(col_w3[i], 5, txt, 1, 'L')
    pdf.set_y(y_start + row_h)

pdf.ln(3)
pdf.body_text('Nguon: Vichem.vn; Hempel Guideline; Mapei Blog; RawlinsPaints')

# ====== 7. XUAN HUONG ======
pdf.add_page()
pdf.chapter_title('7. Xuan huong & Cong nghe moi')
pdf.body_text('Cong nghe nuoc dang tien gan den dung moi nho cac cai tien sau:')

pdf.set_font('DejaVu', 'B', 10)
techs = [
    ('Core-Shell Latex', ': Loi cung (cung, chiu luc) + vo mem (tao mang tot) - ket hop uu diem ca hai'),
    ('Self-crosslinking', ': Nhom chuc khau mach ngay trong qua trinh tao mang -> tang do ben'),
    ('Pickering emulsion', ': On dinh bang hat nano SiO2 thay surfactant -> cai thien chiu nuoc, giam nhom ua nuoc ton du'),
    ('Hybrid Acrylic-PUD', ': Ket hop gia re cua acrylic + do ben co hoc cua polyurethane dispersion'),
    ('Alkyd lai latex', ': Ket hop uu diem bong, dan cua alkyd + thien nhien cua latex waterborne'),
    ('Blocked isocyanate\ncho 2K PUD', ': Isocyanate bi khoa bang blocking agent (MEKO, DMP, e-CAP), mo khoa o 110-180doC de khau mach'),
]
for t, d in techs:
    pdf.set_font('DejaVu', 'B', 10)
    pdf.cell(6, 6, chr(8226), 0, 0)
    pdf.cell(pdf.get_string_width(t), 6, t, 0, 0)
    pdf.set_font('DejaVu', '', 10)
    pdf.multi_cell(0, 5.5, d)
    pdf.ln(1)

pdf.ln(2)
pdf.body_text('Nguon: ScienceDirect 2024 (Pickering PUD); Wikipedia Waterborne resin; Sinogracechem; Gantrade Blog')

# ====== 8. TONG KET ======
pdf.add_page()
pdf.chapter_title('8. Tong ket')

pdf.info_box('BAN CHAT: Nhựa dung môi TAN THAT trong moi truong -> mang dong nhat o cap phan tu. Nhựa nuoc PHAN TAN thanh hat -> phai qua qua trinh hop nhat phuc tap de tao mang. Su khac biet nay la goc re cua moi khac biet ve tinh chat: chiu nuoc, chiu hoa chat, do bong, do ben co hoc.')

pdf.body_text('De nhua nuoc "bang" nhua dung moi, nha cong nghe phai giai quyet 3 van de cot loi:')
pdf.bullet('Lam the nao de cac hat nhua hop nhat hoan hao? (can coalescing agent + nhiet do phu hop)')
pdf.bullet('Lam the nao de loai bo anh huong cua nhom ua nuoc / surfactant con sot trong mang?')
pdf.bullet('Lam the nao de tao mang dac, it khuyet tat nhu dung dich that?')
pdf.ln(3)
pdf.body_text('Day chinh la ly do son nuoc du than thien moi truong hon nhung trong ung dung khac nghiet (chong an mon, tau bien, cong nghiep nang) van chua the thay the hoan toan son dung moi. Tuy nhien, voi toc do phat trien cong nghe hien nay (core-shell, self-crosslinking, Pickering, nano-dispersion), khoang cach dang thu hep lai tung nam.')

# ====== 9. TAI LIEU THAM KHAO ======
pdf.add_page()
pdf.chapter_title('9. Tai lieu tham khao')

refs = [
    '[1] Wikipedia - Waterborne Resins. https://en.wikipedia.org/wiki/Waterborne_resins',
    '[2] ACS Omega (2020) - Advances in Waterborne Acrylic Resins: Synthesis Principle, Modification Strategies, and Their Applications. https://pubs.acs.org/doi/10.1021/acsomega.0c05593',
    '[3] ACS Appl. Mater. Interfaces (2024) - From Wet to Protective: Film Formation in Waterborne Coatings. https://pmc.ncbi.nlm.nih.gov/articles/PMC11533165/',
    '[4] Gantrade - The Chemistry of Waterborne Polyurethane Coatings. https://www.gantrade.com/blog/the-chemistry-of-waterborne-polyurethane-coatings',
    '[5] Hempel Technical Guideline - Water-Borne Coatings. https://www.hempel.com',
    '[6] Vichem - Water-Based Alkyd Resin vs Solvent-Based Alkyd Resin. https://vichem.vn/en/water-based-alkyd-resin-vs-solvent-based-alkyd-resin/',
    '[7] Resingroup - Water-Based or Solvent-Based Polyurethane Finish. https://resingroup.net/en/blogs/case-studies/water-based-or-solvent-based-finishes',
    '[8] SIWO US - Water-based vs Solvent-based Coating. https://www.siwo-us.com/water-based-vs-solvent-based-coating-everything-you-need-to-know/',
    '[9] Sinogracechem - Basic Knowledge of Waterborne Coating Formulation Part 2. https://www.sinogracechem.com',
    '[10] Kingcat Paint - Khac nhau son goc nuoc va son dung moi. https://kingcatpaint.com.vn/su-khac-nhau-giua-son-goc-nuoc-va-son-dung-moi',
    '[11] Stromann - Nhựa tao mang va chat tro tao mang. https://stromann.vn',
    '[12] Rawlins Paints - Water-Based Or Solvent/Oil-Based Paint. https://www.rawlinspaints.com',
    '[13] Mapei - Comparing Solvent-Based And Water-Based Coatings. https://www.mapei.com',
    '[14] Scott Bader - Film Formation in Polymer Coatings. https://www.scottbader.com',
    '[15] Carbodiimide.com - Water-based vs Solvent-based Polyurethane. https://carbodiimide.com',
]

pdf.set_font('DejaVu', '', 9)
for r in refs:
    pdf.multi_cell(0, 5.5, r)
    pdf.ln(0.5)

# ====== SAVE ======
out_dir = r"C:\antigra-DS\CLAW_LAM_VIEC\Mẫu không có tiêu đề (File responses)"
out_path = os.path.join(out_dir, "Khac biet nhua son nuoc vs son dung moi.pdf")
pdf.output(out_path)
print(f"PDF saved to: {out_path}")
print(f"Pages: {pdf.page_no()}")
