2017-07-05 6 views
1

PHP APIを使用してAngular 4アプリケーションを構築しています。アプリ内では、ユーザーはある種の「雑誌」を生成することができます。これにより、ページを並べ替えたり、コンテンツを編集したり、画像を追加することはできますが、WYSIWYGの方法ではなく、「このオプションを選択したものは私が欲しいものです。Angular4とPHPを使用してカスタムPDFサーバーまたはクライアントサイドを生成

最終的なPDFをどのように表示するかを「記述する」MySQLデータベースに格納されている多くのデータで終了します。

問題は、PDFを生成する方法が全くわかりません。私は、クライアント側のソリューションとしてのpdfmakeやjsPDFや、サーバ側のソリューションとしてのtcpdf(これまでのバージョン移行のようです)を知っています。しかし、これらはすべて制限されています。

jsPDFやpdfmakeの制限されたコマンドの代わりにLaTeXコマンドのさまざまな機能を使用できるため、LaTeXコードを生成してそこからいくつかのPDFを生成するのが最善のソリューションだと思います。

角度を使ってLaTeXコードをコンパイルする管理には、標準的なやり方がありますか?

どのようにすればいいですか?サーバー側またはクライアント側?作成しようとしているのLaTeXやPDF、画像の多く、約100〜200ページが含まれてい...

答えて

0

誰もが

CLSIを検索するため、それを管理するための方法であると思われます。 LaTeXのファイルをコンパイルするにはまだ維持されているオープンソースのAPIがあります:実際に私の場合は移動するための方法であるmike42 ... PHPでのLaTeXのコンパイルの別の非常に興味深いexampleからCLSI ShareLaTeX

おかげで...コードは次のようなものに終わるので、一度に有効なLaTeXファイルと有効なPHPファイルである.texファイルを生成することです:

% This file is a valid PHP file and also a valid LaTeX file 
% When processed with LaTeX, it will generate a blank template 
% Loading with PHP will fill it with details 

\documentclass{article} 
% Required for proper escaping 
\usepackage{textcomp} % Symbols 
\usepackage[T1]{fontenc} % Input format 

% Because Unicode etc. 
\usepackage{fontspec} % For loading fonts 
\setmainfont{Liberation Serif} % Has a lot more symbols than Computer Modern 

% Make placeholders visible 
\newcommand{\placeholder}[1]{\textbf{$<$ #1 $>$}} 

% Defaults for each variable 
\newcommand{\test}{\placeholder{Data here}} 

% Fill in 
% <?php echo "\n" . "\\renewcommand{\\test}{" . LatexTemplate::escape($data['test']) . "}\n"; ?> 

\begin{document} 
    \section{Data From PHP} 
    \test{} 
\end{document} 

PHPセーフモードが無効になっていると、サーバーがxelatex/pdflatexをインストールしている場合は、実行直接ファイル上のコマンド...

まず塗りつぶされた LaTeXコードはこのような何か実行して一時ファイルに格納する必要があります選択のエンジンは、出力ファイルを生成するために実行すべきことであるが、後

/** 
* Generate a PDF file using xelatex and pass it to the user 
*/ 
public static function download($data, $template_file, $outp_file) { 
    // Pre-flight checks 
    if(!file_exists($template_file)) { 
     throw new Exception("Could not open template"); 
    } 
    if(($f = tempnam(sys_get_temp_dir(), 'tex-')) === false) { 
     throw new Exception("Failed to create temporary file"); 
    } 

    $tex_f = $f . ".tex"; 
    $aux_f = $f . ".aux"; 
    $log_f = $f . ".log"; 
    $pdf_f = $f . ".pdf"; 

    // Perform substitution of variables 
    ob_start(); 
    include($template_file); 
    file_put_contents($tex_f, ob_get_clean()); 
} 

を:

// Run xelatex (Used because of native unicode and TTF font support) 
$cmd = sprintf("xelatex -interaction nonstopmode -halt-on-error %s", 
     escapeshellarg($tex_f)); 
chdir(sys_get_temp_dir()); 
exec($cmd, $foo, $ret); 

// No need for these files anymore 
@unlink($tex_f); 
@unlink($aux_f); 
@unlink($log_f); 

// Test here 
if(!file_exists($pdf_f)) { 
    @unlink($f); 
    throw new Exception("Output was not generated and latex returned: $ret."); 
} 
関連する問題