LaTeX forum ⇒ XeTeXGenerating small business cards

Information and discussion about XeTeX, an alternative for pdfTeX based on e-Tex
bartzmc
Posts: 10
Joined: Thu Apr 06, 2017 9:15 pm

Generating small business cards

Postby bartzmc » Tue Feb 26, 2019 6:25 pm

Based on https://www.overleaf.com/latex/examples/mailmerged-business-cards/gnnhcjvkvcfd

I'm trying to implement a project that would generate small business cards based on a csv file.
I created a code similar to here:

https://tex.stackexchange.com/questions/153834/print-business-cards-in-latex

That is, compiling one business card to the first.pdf file, and for the next compilation inserting it into the second page so that you can cut them according to the pattern. It's a two step process. I want these small business cards to be generated straight away from the file. I want to achive only second side of my file and in addition not only one person's business card but one by one each line from the file. But not necessarily, I care more about small business cards, it can be one person's data.

Image

Data.csv looks like:
Code: [Select all] [Expand/Collapse] [Download] ({untitled.tex})
  1. Name,Subtitle,Division,Employer,JobTitle,Speciality1,Speciality2,Speciality3,Web,Email1,Email2,Mobile,GPG
  2. {Helena Doe},subtitle,Division,Employer,Job Title,Speciality 1,Speciality 2,Speciality 3,https://fqdn/,helena@univ.edu,hxr42@gmail.com,+1 123 456 7890,425B 030A B8D2 0316 CA1B 4709 CA83 5DDA EC31 CA56

Image

My code:
Code: [Select all] [Expand/Collapse] [Download] ({untitled.tex})
  1. \documentclass[11pt,a4paper]{article}
  2.  
  3. \setstocksize{55mm}{85mm} % UK Stock size
  4. \setpagecc{55mm}{85mm}{*}
  5. \settypeblocksize{45mm}{75mm}{*}
  6. \setulmargins{5mm}{*}{*}
  7. \setlrmargins{5mm}{*}{*}
  8. \usepackage{xcolor}
  9. \usepackage{datatool}
  10. \DTLloaddb{namelist}{data.csv}
  11.  
  12. \setheadfoot{0.1pt}{0.1pt}
  13. \setheaderspaces{1pt}{*}{*}
  14.  
  15. \checkandfixthelayout[fixed]
  16.  
  17. \pagestyle{empty}
  18.  
  19. \usepackage{pstricks}
  20. \usepackage{auto-pst-pdf,pst-barcode}
  21.  
  22. %% These packages only for typesetting the instructions
  23. \usepackage{listings}
  24. \usepackage{enumitem}
  25.  
  26. \usepackage{stackengine}
  27. \usepackage{graphicx}
  28.  
  29. \newlength\plusheight
  30. \newlength\stackvgap
  31.  
  32. \def\myvgap{1ex}
  33. \def\myhgap{1ex}
  34.  
  35. \def\myimg{\protect\includegraphics[scale=1.0]{first}}
  36. \def\myimgwd{\widthof{\myimg}-\widthof{+}}
  37. \def\imgline{\myimg\protect\hspace{\myhgap}\myimg}
  38. \def\seperatorline{+\protect\rule{\myimgwd+\myhgap}{0pt}+\protect\rule{\myimgwd+\myhgap}{0pt}+}
  39. \setlength\plusheight{\heightof{+}}
  40. \addtolength\plusheight{\depthof{+}}
  41. \setlength\stackvgap{\myvgap-\the\plusheight}
  42. \setlength\stackvgap{.5\stackvgap}
  43. \setstackgap{S}{\the\stackvgap}
  44.  
  45. \pagestyle{empty}
  46. \usepackage{scrextend}
  47.  
  48. \begin{document}
  49.  
  50. %% For each line in namelist (which was loaded from data.csv),
  51. %% output the following text (with mailmerged field values)
  52. \DTLforeach{namelist}{%
  53. %% Map each column header in your .csv file to a command
  54. \Name=Name,%
  55. \Subtitle=Subtitle,%
  56. \Division=Division,%
  57. \Employer=Employer,%
  58. \JobTitle=JobTitle,%
  59. \SpecialityOne=Speciality1,%
  60. \SpecialityTwo=Speciality2,%
  61. \SpecialityThree=Speciality3,%
  62. \Web=Web,%
  63. \EmailOne=Email1,%
  64. \EmailTwo=Email2,%
  65. \Mobile=Mobile,%
  66. \GPG=GPG%
  67. }{%%% Start designing your output text!
  68. %%% Mailmerged field values can be inserted using the commands
  69. %%% you've just mapped above.
  70.  
  71. \begin{Spacing}{0.75}%
  72. \noindent
  73. \textbf{\Name}\\[3pt]
  74. \tiny\mbox{}\Subtitle \hfill {\color{gray}\Division{} / \Employer}\\
  75. \rule{\textwidth}{.3mm}\\
  76. \begin{minipage}[t]{30mm}
  77. \vspace{-0mm}%
  78. \begin{pspicture}(25mm,25mm)
  79. % The MECARD format is used to exchange contact information. More information at:
  80. % <!-- m --><a class="postlink" href="https://www.nttdocomo.co.jp/english/service/developer/make/content/barcode/function/application/addressbook/index.html">https://www.nttdocomo.co.jp/english/ser ... index.html</a><!-- m -->
  81. \psbarcode{MECARD:N:\Name;URL:\Web;EMAIL:\EmailOne;TEL:\Mobile;NOTE:GPG key fingerprint: \GPG;}{eclevel=L width=1 height=1}{qrcode}
  82. \end{pspicture}
  83. \end{minipage}
  84. \hspace{1mm}
  85. \begin{minipage}[t]{42mm}
  86. \vspace{-0mm}%
  87. \begin{flushleft}
  88. {\scriptsize
  89. \begin{Spacing}{1}%
  90. \textbf{\JobTitle}\\[5mm]
  91. % \hspace{5mm}\mbox{}\SpecialityOne\\
  92. \mbox{}\SpecialityOne\\
  93. \mbox{}\SpecialityTwo\\
  94. \mbox{}\SpecialityThree \vspace{2mm}\\
  95. \end{Spacing}
  96. }
  97. {\tiny
  98. \begin{tabular}{@{}rl@{}l}
  99. {\color{gray}email}: & \EmailOne & \\
  100. {\color{gray}mobile}:& \Mobile & \\
  101. \end{tabular}
  102. \vspace*{2mm}
  103. }
  104. \end{flushleft}
  105. \end{minipage}
  106. \rule{74mm}{0mm}\\
  107. \texttt{\fontsize{2.84mm}{3.55mm}\selectfont \GPG} % GPG KEY ID
  108. \end{Spacing}
  109. }
  110.  
  111. \eject \pdfpagewidth=210mm \pdfpageheight=297mm
  112. \leftskip10mm
  113.  
  114. \vfill
  115. \Shortstack{%
  116. {\seperatorline}
  117. {\imgline} {\seperatorline}
  118. {\imgline} {\seperatorline}
  119. {\imgline} {\seperatorline}
  120. {\imgline} {\seperatorline}
  121. {\imgline} {\seperatorline}}
  122. \vfill
  123.  
  124. \end{document}
Last edited by bartzmc on Sun Mar 03, 2019 12:20 pm, edited 4 times in total.

rais
Posts: 235
Joined: Sun Nov 16, 2014 8:51 pm

Postby rais » Fri Mar 01, 2019 7:30 pm

You could try putting the card in a box, say
Code: [Select all] [Expand/Collapse] [Download] ({untitled.tex})
  1. \documentclass[11pt,a4paper]{article}
  2. \usepackage{xcolor}
  3. \usepackage{filecontents}
  4. \begin{filecontents*}{\jobname-dat.csv}
  5. Name,Subtitle,Division,Employer,JobTitle,Speciality1,Speciality2,Speciality3,Web,Email1,Email2,Mobile,GPG
  6. {Helena Doe},subtitle,Division,Employer,Job Title,Speciality 1,Speciality 2,Speciality 3,https://fqdn/,helena@univ.edu,hxr42@gmail.com,+1 123 456 7890,425B 030A B8D2 0316 CA1B 4709 CA83 5DDA EC31 CA56
  7. {Jane Doe},subtitle,Division,Employer,Job Title,Speciality 1,Speciality 2,Speciality 3,https://fqdn/,jane@univ.edu,hxr42@gmail.com,+1 123 456 7890,425B 030A B8D2 0316 CA1B 4709 CA83 5DDA EC31 CA56
  8. \end{filecontents*}
  9. \usepackage{datatool}
  10. \usepackage[left=1cm, right=1cm, top=1cm, bottom=1cm]{geometry}
  11. \DTLloaddb{namelist}{\jobname-dat.csv}
  12.  
  13. \usepackage{fontspec}
  14. \setmainfont{Universalis ADF Std}
  15.  
  16. \pagestyle{empty}
  17.  
  18. \usepackage{pstricks}
  19. \usepackage{auto-pst-pdf,pst-barcode}
  20.  
  21. \newsavebox\currbizcard
  22.  
  23. \pagestyle{empty}
  24.  
  25. \usepackage{scrextend}
  26. \newlength\xbetweencards
  27. \newlength\ybetweencards
  28. \setlength\xbetweencards{24pt}
  29. \setlength\ybetweencards{24pt}
  30.  
  31. \begin{document}
  32.  
  33. %% For each line in namelist (which was loaded from \jobname-dat.csv),
  34. %% output the following text (with mailmerged field values)
  35. \DTLforeach*{namelist}{% Map each column header in your .csv file to a command
  36. \Name=Name, \Subtitle=Subtitle, \Division=Division, \Employer=Employer,%
  37. \JobTitle=JobTitle, \SpecialityOne=Speciality1, \SpecialityTwo=Speciality2, \SpecialityThree=Speciality3,%
  38. \Web=Web, \EmailOne=Email1, \EmailTwo=Email2, \Mobile=Mobile, \GPG=GPG%
  39. }{%
  40. \sbox\currbizcard{%
  41. \begin{minipage}{74mm}%
  42. \noindent
  43. \textbf{\Name}\\[3pt]
  44. \tiny \Subtitle \hfill {\color{gray}\Division{} / \Employer}\\
  45. \rule{\textwidth}{.3mm}\\
  46. \begin{minipage}[t]{30mm}
  47. \vspace{-0mm}%
  48. \begin{pspicture}(25mm,25mm)
  49. \psbarcode{MECARD:N:\Name;URL:\Web;EMAIL:\EmailOne;TEL:\Mobile;NOTE:GPG key fingerprint: \GPG;}{eclevel=L width=1 height=1}{qrcode}
  50. \end{pspicture}
  51. \end{minipage}%
  52. \hspace{1mm}%
  53. \begin{minipage}[t]{42mm}
  54. \vspace{-0mm}%
  55. \begin{flushleft}
  56. {\scriptsize
  57. % \begin{Spacing}{1}%
  58. \textbf{\JobTitle}\\[5mm]
  59. \SpecialityOne\\
  60. \SpecialityTwo\\
  61. \SpecialityThree \vspace{2mm}\\
  62. % \end{Spacing}
  63. }
  64. {\tiny
  65. \begin{tabular}{@{}rl@{}}
  66. {\color{gray}email}: & \EmailOne\\
  67. {\color{gray}mobile}:& \Mobile\\
  68. \end{tabular}
  69. \vspace*{2mm}
  70. }
  71. \end{flushleft}
  72. \end{minipage}
  73. \rule{74mm}{0mm}\\
  74. \texttt{\fontsize{2.84mm}{3.55mm}\selectfont \GPG} % GPG KEY ID
  75. \end{minipage}
  76. }%
  77. \centering
  78. \null\vfill
  79. \usebox\currbizcard\hspace{\xbetweencards}\usebox\currbizcard\\[\ybetweencards]
  80. \usebox\currbizcard\hspace{\xbetweencards}\usebox\currbizcard\\[\ybetweencards]
  81. \usebox\currbizcard\hspace{\xbetweencards}\usebox\currbizcard\\[\ybetweencards]
  82. \usebox\currbizcard\hspace{\xbetweencards}\usebox\currbizcard\\[\ybetweencards]
  83. \usebox\currbizcard\hspace{\xbetweencards}\usebox\currbizcard\par
  84. \vfill\clearpage
  85. }
  86. \end{document}

I may have thrown out a bit too much from the code, but hey...
The font you used I don't have on this machine, I opted for a font that ships with TL'18 instead.(that's not part of my
suggestion)
I renamed the csv file, because the filecontents package lets the filecontents environment overwrite any existing file with the filename given to this environment (to be able to make changes from within the .tex file)---in short, I didn't want to overwrite your data.csv by accident;-)

KR
Rainer

bartzmc
Posts: 10
Joined: Thu Apr 06, 2017 9:15 pm

Postby bartzmc » Sun Mar 03, 2019 10:11 am

Thank you for this solution.


Return to “XeTeX”

Who is online

Users browsing this forum: No registered users and 0 guests