チェック印刷の目的でiTextSharpを使用してPDFを作成しています。私の問題は、小切手の封筒に小さな窓がある小切手に印刷する名前/住所を取得できないことです。アドレス行の間隔が大きすぎます。HTMLドキュメントのフォントタグに行の高さを設定していますが、引き継がれていません。
具体的には、アドレス部分は次のとおりです。
conn.Open();
using (SqlDataReader itemReader = strSQL.ExecuteReader())
{
checksHolder.InnerHtml += "<table cellSpacing=\"0\" cellPadding=\"0\" border=\"0\" width=\"100%\">\n";
while (itemReader.Read())
{
if (i % 3 == 0 && i != 0)
{
checksHolder.InnerHtml += "</table>\n";
checksHolder.InnerHtml += "<!-- pagebreak -->\n";
checksHolder.InnerHtml += "<table cellSpacing=\"0\" cellPadding=\"0\" border=\"0\" width=\"100%\">\n";
f = 0;
}
if (i > 0 && i % 3 != 0)
{
checksHolder.InnerHtml += "<tr><td colspan=\"3\"><br/><br/><br/><br/><br/><br/>";
checksHolder.InnerHtml += "</td></tr>\n";
}
String[] tmpArray = getConsignorInfo(itemReader["check_cs_id"].ToString());
int CheckNum = Int32.Parse(itemReader["check_number"].ToString());
String CheckAmount = itemReader["check_amount"].ToString();
String PayableTo = tmpArray[0];
String Memo = itemReader["check_memo"].ToString();
String name = tmpArray[0];
String address = tmpArray[1];
String city = tmpArray[2];
String state = tmpArray[3];
String zip = tmpArray[4];
Char NBSP = '\u00A0';
checksHolder.InnerHtml += "<tr><td colspan=\"3\"><br/><br/></td></tr>\n";
checksHolder.InnerHtml += "<tr>\n";
//checksHolder.InnerHtml += "<td width=\"5\"></td>\n";
checksHolder.InnerHtml += "<td colspan=\"2\">\n";
checksHolder.InnerHtml += "<font size=\"2\">\n";
checksHolder.InnerHtml += " \n";
checksHolder.InnerHtml += PayableTo + "</font>\n";
checksHolder.InnerHtml += "</td>\n";
checksHolder.InnerHtml += "<td align=\"right\">\n";
checksHolder.InnerHtml += "<font align=\"right\" size=\"2\">" + string.Format("{0:c}", Double.Parse(CheckAmount.ToString())).Replace("$", "") + "</font>\n";
checksHolder.InnerHtml += "</td>\n";
checksHolder.InnerHtml += "</tr>\n";
checksHolder.InnerHtml += "<tr>\n";
checksHolder.InnerHtml += "<td colspan=\"3\">\n";
checksHolder.InnerHtml += " \n";
checksHolder.InnerHtml += "</td>\n";
checksHolder.InnerHtml += "</tr>\n";
checksHolder.InnerHtml += "<tr>\n";
checksHolder.InnerHtml += "<td colspan=\"3\">\n";
checksHolder.InnerHtml += "<font size=\"2\">";
if (wordify(decimal.Parse(CheckAmount.ToString())).Length >= 90)
{
checksHolder.InnerHtml += wordify(decimal.Parse(CheckAmount.ToString()));
}
else
{
string exes = " ";
for (int x = wordify(decimal.Parse(CheckAmount.ToString())).Length; x <= 90; x++)
{
exes += "x";
}
checksHolder.InnerHtml += wordify(decimal.Parse(CheckAmount.ToString())) + exes;
}
checksHolder.InnerHtml += "</font>\n";
checksHolder.InnerHtml += "</td>\n";
checksHolder.InnerHtml += "</tr>\n";
checksHolder.InnerHtml += "<tr>\n";
checksHolder.InnerHtml += "<td colspan=\"2\">\n";
checksHolder.InnerHtml += "<table cellSpacing=\"0\" cellPadding=\"0\" border=\"0\" width=\"100%\">\n";
checksHolder.InnerHtml += "<tr>\n";
checksHolder.InnerHtml += "<td colspan=\"2\"><br/>\n";
checksHolder.InnerHtml += "<font size=\"2\" line-height=\"8p\">" + name + "<br/>\n";
checksHolder.InnerHtml += address + "<br/>\n";
checksHolder.InnerHtml += city + ",\n";
checksHolder.InnerHtml += state + " \n";
checksHolder.InnerHtml += zip + "</font>\n";
checksHolder.InnerHtml += "</td>\n";
checksHolder.InnerHtml += "</tr>\n";
checksHolder.InnerHtml += "<tr>\n";
checksHolder.InnerHtml += "<td colspan=\"3\">\n";
checksHolder.InnerHtml += "<br/></td>\n";
checksHolder.InnerHtml += "</tr>\n";
checksHolder.InnerHtml += "<tr>\n";
checksHolder.InnerHtml += "<td width=\"10\"></td>\n";
checksHolder.InnerHtml += "<td>\n";
checksHolder.InnerHtml += "<font size=\"2\">" + Memo.Substring(0, 50) + "...</font>\n";
checksHolder.InnerHtml += "</td>\n";
checksHolder.InnerHtml += "</tr>\n";
checksHolder.InnerHtml += "</table>\n";
checksHolder.InnerHtml += "</td>\n";
checksHolder.InnerHtml += "<td valign=\"bottom\" width=\"40\">\n";
checksHolder.InnerHtml += "<img valign=\"bottom\" align=\"left\" src=\"images/wesSig.png\" Alt=\"\" /><br/>\n";
checksHolder.InnerHtml += "</td>\n";
checksHolder.InnerHtml += "</tr>\n";
i++;
f++;
}
checksHolder.InnerHtml += "</table>\n";
itemReader.Close();
}
public void CreatePDFDocument(string strHtml)
{
string strFileName = HttpContext.Current.Server.MapPath("printCheck.pdf");
// step 1: creation of a document-object
iTextSharp.text.Rectangle rec = new iTextSharp.text.Rectangle(612, 792);
Document document = new Document(rec);
document.SetMargins(45f, 30f, 55f, 30f);
// step 2:
// we create a writer that listens to the document
var pdfWriter = PdfWriter.GetInstance(document, new FileStream(strFileName, FileMode.Create));
pdfWriter.InitialLeading = 12.5f;
string[] stringSeparators = new string[] { "<!-- pagebreak -->" };
//Response.Write(strHtml);
string[] newString = strHtml.Split(stringSeparators, StringSplitOptions.None);
//HTMLWorker obj = new HTMLWorker(document);
document.Open();
var xmlWorkerHelper = XMLWorkerHelper.GetInstance();
var cssResolver = new StyleAttrCSSResolver();
var xmlWorkerFontProvider = new XMLWorkerFontProvider();
var cssAppliers = new CssAppliersImpl(xmlWorkerFontProvider);
var htmlContext = new HtmlPipelineContext(cssAppliers);
htmlContext.SetTagFactory(Tags.GetHtmlTagProcessorFactory());
PdfWriterPipeline pdfWriterPipeline = new PdfWriterPipeline(document, pdfWriter);
HtmlPipeline htmlPipeline = new HtmlPipeline(htmlContext, pdfWriterPipeline);
CssResolverPipeline cssResolverPipeline = new CssResolverPipeline(cssResolver, htmlPipeline);
XMLWorker xmlWorker = new XMLWorker(cssResolverPipeline, true);
XMLParser xmlParser = new XMLParser(xmlWorker);
int i = 0;
foreach (String currentString in newString) {
if (i > 0)
{
document.NewPage();
}
StringReader sr = new StringReader(currentString);
xmlParser.Parse(sr);
i++;
}
document.Close();
ShowPdf(strFileName);
}
名前/住所を入れるのに0.5インチしかありません。念のため、両方で行の高さを指定してみまし8px
た8
。何も機能しませんでした。行の高さを引き継ぐためにHTMLをフォーマットする必要がある方法を誰かが知っていますか?前もって感謝します。