私は2つのPDFバイト配列を生成し、それらの配列の両方を1バイト配列に結合しました。今度はActionMethod
でPDFをController
にレンダリングすると、Combine()
メソッドに渡された2番目のbyte[]
のPDFのみが生成されます。 例:私は上記のコードを記述する場合 1)2番目のバイト[]は最初のバイト[]を上書きしてPDFをマージします
public ActionResult ShowPdf(string id1, string id2)
{
byte[] pdfBytes1 = CreatePdf1(id1);
byte[] pdfBytes2 = CreatePdf2(id2);
byte[] combinedPdfData = Combine(pdfBytes1, pdfBytes2);
return File(combinedPdfData, "application/pdf");
}
は、それだけpdfBytes2
配列データとpdfBytes1
配列データが上書きされるとPDFを生成します。
2)次に順序を変更して書く場合:
public ActionResult ShowPdf(string id1, string id2)
{
byte[] pdfBytes1 = CreatePdf1(id1);
byte[] pdfBytes2 = CreatePdf2(id2);
byte[] combinedPdfData = Combine(pdfBytes2, pdfBytes1);
return File(combinedPdfData, "application/pdf");
}
この方法のみpdfBytes1
アレイデータとPDFを生成します。
コンバインマイ()メソッドのコードは次のとおりです。
public static byte[] Combine(byte[] first, byte[] second)
{
byte[] ret = new byte[first.Length + second.Length];
Buffer.BlockCopy(first, 0, ret, 0, first.Length);
Buffer.BlockCopy(second, 0, ret, first.Length, second.Length);
return ret;
}
私はcombinedPdfData
配列、すなわちバイトの合計が含まれていることを見ることができますデバッグ中。 pdfBytes1[] + pdfBytes2[]
ですが、印刷中には1つの配列のデータのみが出力されます。私が間違っていることを教えてください。
あなたの質問にタグを付けたように[tag:itext]:iText(シャープ)を使用して* pdfファイルをマージすることができます。 – mkl