0

I'm using html2canvas to generate a PDF from a React resume template. While the icons are perfectly aligned in the HTML preview, they become misaligned when converted to PDF. Here's my setup:

I'm using:

  • html2canvas for PDF generation
  • jsPDF for saving the PDF
  • Lucide React icons
  • Tailwind CSS for styling

The HTML preview looks perfect, but when generating the PDF, icons like Mail, Phone, Building2, etc. appear misaligned relative to their text.

Here's the relevant code:

// PDF Generation
const generatePDF = async () => {
  const content = contentRef.current;
  const canvas = await html2canvas(content, {
    scale: 2,
    useCORS: true,
    logging: false
  });

  const imgData = canvas.toDataURL('image/png');
  const pdf = new jsPDF({
    orientation: 'portrait',
    unit: 'px',
    format: [canvas.width, canvas.height]
  });

  pdf.addImage(imgData, 'PNG', 0, 0, canvas.width, canvas.height);
  pdf.save('resume.pdf');
};

// Icon usage in template
<div className="flex items-center text-slate-700">
  <div className="flex-shrink-0 w-4">
    <Mail className="w-4 h-4 text-blue-600" />
  </div>
  <span className="text-sm ml-3">{email}</span>
</div>
1
  • Like can you give me a basic structure or method to implement Commented Feb 15 at 15:41

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.