I am using miktex on windows system. I try to convert .tex file to html and then copy it to word. The challenge comes from .pdf figure
Converting process can be achieved by the previous post converting .pdf figure to .png figure that html can recognize, the import point here is to change gs to mgs for unix system.
However the converted figure has some format problems,
1 the converted figure is doubled size, right blank part is extra due to the convert code. 2 the size of the figure in html is way too large, it holds many times of the page width.
To control the figure size, i try some code from below, width="\expandafter\the\csname Gin@req@width\endcsname" align=center border=0 onerror="this.src='missing.png'" after using the code, the figure becomes too small.
\Preamble{xhtml}
\Configure{graphics*}
{pdf}
{\Needs{"convert '\csname Gin@base\endcsname.pdf'
'\csname Gin@base\endcsname.png'"}%
\Picture[pict]{\csname Gin@base\endcsname.png width="\expandafter\the\csname Gin@req@width\endcsname" align=center border=0 onerror="this.src='missing.png'"}%
\special{t4ht+@File: \csname Gin@base\endcsname.png}
}
\DeclareGraphicsExtensions{.pdf,.png,.jpg,.eps}
\begin{document}
\EndPreamble
Is there some more setting needs to define the pdfconvert and also more setting on the figure style?
1 the blank white margin has been removed by adding a switch in the pdf converting commands as below
\Preamble{xhtml}
\makeatletter
\Configure{PdfConvert}{png}{"mgs -q -dNOPAUSE -dBATCH -sDEVICE=pngalpha -dUseCropBox -r300 \ifx\Gin@page\@empty\else -dFirstPage="\Gin@page" -dLastPage="\Gin@page"\fi\space -sOutputFile="\Gin@base-\Gin@page.png" "\Gin@base.pdf" "}
\makeatother
\begin{document}
\EndPreamble
With the switch -dusecropbox, the resolution could be set as high as 300 or higher. However, you will need an extra styl formatting file to define the format.
the style file code are below. basically the two .cfg figure files can not be merged easily to have same figures format as from 2 separate files.
\Preamble{xhtml}
\Configure{@HEAD}{\HCode{<link href="basic.css" rel="stylesheet" type="text/css" />\Hnewline}}
\DeclareGraphicsRule{.png}{bmp}{.xbb}{}
\ConfigureEnv{table}
{\ifvmode\IgnorePar\fi\EndP\HCode{<div class="table"\Hnewline>}%
\bgroup \Configure{float}{\ShowPar}{}{}%
}
{\egroup
\ifvmode\IgnorePar\fi\EndP\HCode{</div>}\ShowPar
\par}
{}{}
\ConfigureEnv{figure}
{\ifvmode\IgnorePar\fi\EndP\HCode{<div class="figure"\Hnewline>}%
\bgroup \Configure{float}{\ShowPar}{}{}%
}
{\egroup
\ifvmode\IgnorePar\fi\EndP\HCode{</div>}\ShowPar
\par}
{}{}
\ConfigureEnv{subfigure}
{\ifvmode\IgnorePar\fi\EndP\HCode{<div class="subfigure">}}
{\ifvmode\IgnorePar\fi\EndP\HCode{</div>}}{}{}
\Css{.subfigure{display: inline-block;}}
\Css{.subfigure img{display:block;}}
\Css{div.caption {text-align:left;font-size:83\%;text-indent:0em; margin-left:2em; margin-right:2em; }}
%%%font-variant has 4 values, 1 normal 2 small-caps 3 initial 4 inherit
\Css{div.caption span.id{font-variant: initial; white-space: nowrap; }}
%\Css{div.caption span.id{font-variant: small-caps; white-space: nowrap; }} %%originial
%%%font-variant has 4 values, 1 normal 2 small-caps 3 initial 4 inherit
\Css{.figure div.caption{text-align: center;}}
\Css{.subfigure div.caption{text-align: center;}}
\Css{div.figure{text-align:center;clear:both;overflow:auto;width:100\%;margin-bottom:1em;}}
%%%%% for table
%\Css{div.caption{text-align:center;}}
%\Configure{float}{\csname par\endcsname\ShowPar}
%{\ifvmode\IgnorePar\fi\EndP\HCode{<div class="float">}}
%{\ifvmode\IgnorePar\fi\EndP\HCode{</div>}\ShowPar}
%%%%%for table
\begin{document}
\makeatletter
% Various helper functions
% default font size
\newcommand\emwidth{16}
\let\emwidth\f@size
% convert pt to rem
\newcommand\CalcRem[1]{\strip@pt\dimexpr(#1)/\emwidth}
%%%%%%convert pdf to png and set the figure size %%%%%%%%%%
\Configure{graphics*}
{pdf}
{\Needs{"convert '\csname Gin@base\endcsname.pdf'
'\csname Gin@base\endcsname.png'"}%
\Picture[pict]{\csname Gin@base\endcsname.png width="\expandafter\the\csname Gin@req@width\endcsname" align=center border=0 onerror="this.src='missing.png'"}%
\special{t4ht+@File: \csname Gin@base\endcsname.png}
}
%%%%%convert pdf to png and another method to set figure size%%%%%%%%
%% you must add the file extension with
% \Configure{graphics*}
% {pdf}
% {\Needs{"convert '\csname Gin@base\endcsname.pdf'
% '\csname Gin@base\endcsname.png'"}%
% \Picture[pict]{\csname Gin@base\endcsname.png
% \space style="width:\CalcRem{\Gin@req@width}em;"}%
% \special{t4ht+@File: \csname Gin@base\endcsname.png}
%
% }
\Configure{graphics*}
{png}
{% we must add the image to the list of output files
\special{t4ht+@File: \csname Gin@base\endcsname.png}
\Picture[pict]{\csname Gin@base\endcsname\PictExt
\space style="width:\CalcRem{\Gin@req@width}em;"
}%
}
\makeatother
\EndPreamble

tex4htconfiguration file? is it CSS? – michal.h21 Sep 11 '19 at 19:36mgsstuff :) – michal.h21 Sep 13 '19 at 06:28