私はしばらくの間、この問題を解決しようとしてきましたが、役に立ちませんでした。改行を入れようとしている iTextSharp にテキストがあります。\n
エスケープ文字 ,を使用してみましたが、成功Environment.NewLine
しdocument.Add(new Phrase(Environment.NewLine))
ませんでした。これを行う方法はありますか?これが私がそれをやろうとしている私のコードの一部です( でコメントされた行に注意してください//Doesn't work
):
//Open the reader
PdfReader reader = new PdfReader(oldFile);
Rectangle size = reader.GetPageSizeWithRotation(1);
Document document = new Document(size);
// open the writer
FileStream fs = new FileStream(newFile, FileMode.Create, FileAccess.Write);
PdfWriter writer = PdfWriter.GetInstance(document, fs);
document.Open();
//Configure the content
PdfContentByte cb = writer.DirectContent;
// select the font properties
BaseFont bf = BaseFont.CreateFont("c:\\windows\\fonts\\calibri.ttf", BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
cb.SetColorFill(BaseColor.BLACK);
cb.SetFontAndSize(bf, 10);
//Write the text here
cb.BeginText();
text = "F\n";//Doesn’t work
document.Add(new Phrase(Environment.NewLine));//Doesn’t work
text += "o\n";
text += Environment.NewLine;//Doesn’t work
text += "o\n";
cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, text, 85, 311, 0);
cb.EndText();
//Create the new page
PdfImportedPage page = writer.GetImportedPage(reader, 1);
cb.AddTemplate(page, 0, 0);
//Close all streams
document.Close();
fs.Close();
writer.Close();
reader.Close();
助言がありますか?
編集 1:
まだ動作していませんdocument.Add(new Paragraph("\n"));
。私はそれを間違っていましたか?
cb.BeginText();
text = "F";
document.Add(new Paragraph("\n"));
text += "o";
document.Add(new Paragraph("\n"));
text += "o";
cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, text, 85, 311, 0);
cb.EndText();