我正在使用iTextSharp生成一些PDF文件.我有两个有内容的表,我想在两个表之间放一些空格,比如相当于1行文本(使用与空格周围的表相同的字体).
下面是我用来添加两个表的代码.我无法弄清楚的是如何在两个表之间放置一个垂直空间.
Table upperTable = new Table(1);
upperTable.Border = Rectangle.NO_BORDER;
upperTable.DefaultCell.Border = Rectangle.NO_BORDER;
upperTable.DefaultCell.HorizontalAlignment = Element.ALIGN_CENTER;
upperTable.AddCell(new Phrase("some text", font3));
d.Add(upperTable);
Table lowerTable= new Table(1);
lowerTable.Border = Rectangle.NO_BORDER;
lowerTable.DefaultCell.Border = Rectangle.NO_BORDER;
lowerTable.DefaultCell.HorizontalAlignment = Element.ALIGN_CENTER;
lowerTable.AddCell(new Phrase("some other text", font3));
d.Add(lowerTable);
Run Code Online (Sandbox Code Playgroud)
有人能告诉我如何在两个表之间添加垂直空间吗?
谢谢!
可以使用iTextSharp在内存中创建PDF文档,使用户可以选择"打开"或"保存"?如果打开则会在浏览器窗口中打开.
目前我唯一将它保存到磁盘.
编辑:
好吧,我已经怀疑了.我最终不得不将文件写入文件夹,但它只是暂时的,因为每次都被覆盖.以下是它的价值所在的解决方案:
private void GeneratePDF() {
var doc1 = new Document();
string path = Server.MapPath("~/pdfs/");
string filepath = path + "Doc1.pdf";
PdfWriter.GetInstance(doc1, new FileStream(filepath, FileMode.Create));
doc1.Open();
doc1.Add(new Paragraph("A new Document"));
doc1.Add(new Paragraph(DateTime.Now.ToString()));
doc1.Close();
Response.Buffer = false; //transmitfile self buffers
Response.Clear();
Response.ClearContent();
Response.ClearHeaders();
Response.ContentType = "application/pdf";
Response.AddHeader("Content-Disposition", "attachment; filename=myPDF.pdf");
Response.TransmitFile(filepath);
Response.End();
Run Code Online (Sandbox Code Playgroud)
}
在我的工作中,有时我必须合并几个到几百个pdf文件.我一直在使用Writer和ImportedPages上课.但是当我将所有文件合并为一个文件时,文件大小变得庞大,所有合并文件大小的总和,因为字体附加到每个页面,而不是重复使用(字体嵌入到每个页面,而不是整个文档).
不久前我发现了PdfSmartCopy类,它重用了嵌入的字体和图像.在这里,问题就出现了.很多时候,在将文件合并到一起之前,我必须为它们添加额外的内容(图像,文本).为此我通常使用PdfContentByte的Writer对象.
Document doc = new Document();
PdfWriter writer = PdfWriter.GetInstance(doc, new FileStream("C:\test.pdf", FileMode.Create));
PdfContentByte cb = writer.DirectContent;
cb.Rectangle(100, 100, 100, 100);
cb.SetColorStroke(BaseColor.RED);
cb.SetColorFill(BaseColor.RED);
cb.FillStroke();
Run Code Online (Sandbox Code Playgroud)
当我对PdfSmartCopy对象执行类似的操作时,会合并页面,但不会添加其他内容.我的测试的完整代码PdfSmartCopy:
using (Document doc = new Document())
{
using (PdfSmartCopy copy = new PdfSmartCopy(doc, new FileStream(Path.GetDirectoryName(pdfPath[0]) + "\\testas.pdf", FileMode.Create)))
{
doc.Open();
PdfContentByte cb = copy.DirectContent;
for (int i = 0; i < pdfPath.Length; i++)
{
PdfReader reader = new PdfReader(pdfPath[i]);
for …Run Code Online (Sandbox Code Playgroud) 我有一个像这样的iTextSharp页脚模板方法:
public PdfTemplate footerTemplate(){
PdfTemplate footer = cb.CreateTemplate(500, 50);
footer.BeginText();
BaseFont bf2 = BaseFont.CreateFont(BaseFont.TIMES_ITALIC, "windows-1254", BaseFont.NOT_EMBEDDED);
footer.SetFontAndSize(bf2, 11);
footer.SetColorStroke(BaseColor.DARK_GRAY);
footer.SetColorFill(BaseColor.GRAY);
int al = -200;
int v = 45 - 15;
float widthoftext = 500.0f - bf2.GetWidthPoint(footerOneLine[0], 11);
footer.ShowTextAligned(al, footerOneLine[0], widthoftext, v, 0);
footer.EndText();
return footer;
}
Run Code Online (Sandbox Code Playgroud)
footerTemplate()正在获取这样的字符串:
footerOneLine.Add("<b>All this line is bold, and <u>this is bold and underlined</u></b>");
Run Code Online (Sandbox Code Playgroud)
我有一个其他方法使字符串HTML.方法是:
private Paragraph CreateSimpleHtmlParagraph(String text) {
//Our return object
Paragraph p = new Paragraph();
//ParseToList requires a StreamReader instead of just text …Run Code Online (Sandbox Code Playgroud) 我想使用iTextSharp为现有的PDF文件添加文本,我发现了不同的方法,但在所有这些文件中,编写器和阅读器都是单独的pdf文件.我想要一种方式,这样我就可以打开一个pdf,然后在不同的位置写出不同的东西.现在我有这个代码,但它创建了一个新文件.
using (FileStream stream1 = File.Open(path, FileMode.OpenOrCreate))
{
BaseFont bf = BaseFont.CreateFont(fontPath, BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
PdfReader reader = new PdfReader("C:\\26178DATA\\pdf\\holding.pdf");
var pageSize = reader.GetPageSize(1);
PdfStamper stamper = new PdfStamper(reader, stream1);
iTextSharp.text.Font tmpFont = new iTextSharp.text.Font(bf, fontSize);
PdfContentByte canvas = stamper.GetOverContent(1);
Phrase ph = new Phrase(words[1], tmpFont);
ph.Font = tmpFont;
canvas.SetFontAndSize(bf, fontSize);
ColumnText.ShowTextAligned(canvas, Element.ALIGN_LEFT, ph, iTextSharp.text.Utilities.MillimetersToPoints(x * 10), pageSize.GetTop(iTextSharp.text.Utilities.MillimetersToPoints(y * 10)), 0);
stamper.Close();
}
Run Code Online (Sandbox Code Playgroud) 如果它们包含相同数量的列,我可以创建多个行:
table = new PdfPTable(3);
var firstRowCell1 = new PdfPCell( new Phrase ("Row 1 - Column 1"));
var firstRowCell2 = new PdfPCell( new Phrase ("Row 2 - Column 2"));
var firstRowCell3 = new PdfPCell( new Phrase ("Row 3 - Column 3"));
PdfPCell[] row1Cells = { firstRowCell1, firstLineRow2, firstRowCell3 };
var row1 = new PdfPRow(row1Cells);
table.Rows.Add(row1);
var nextRowCell1 = new PdfPCell( new Phrase ("Row 2 - Column 1"));
var nextRowCell2 = new PdfPCell( new Phrase ("Row 2 - Column 2"));
var …Run Code Online (Sandbox Code Playgroud) 我对iText中的LTV感到困惑.我已经阅读了论文,讨论但有一点仍然不清楚.LTV和文档时间戳之间有什么联系?或者更准确地说,如何在不使用时间戳的情况下启用pdf LTV?有一点我肯定知道,要创建一个支持LTV的文档,我不需要时间戳.我尝试在acrobat中使用数字证书签署文档,打开时说文档已启用LTV,我没有使用任何时间戳.
我正在使用ASP MVC,我使用iTextSharp在我的应用程序中生成PDF.但现在我有一个问题:我打印列表,当存在多个页面时,我想显示页码(例如:)Page 1 to 4.我找到了一些例子,但我认为它比我需要做的更复杂(如exameple).
编辑: 我发现这个例子2.我可以计算页数,但我不能打印页数.
我做了什么:
public ActionResult downloadListaISCC(DateTime? DataFimFiltro)
{
//Code to generate list to PDF
//My document
Document doc1 = new Document();
doc1.SetPageSize(iTextSharp.text.PageSize.A4);
doc1.SetMargins(0f, 0f, 0f, 0f);
doc1.NewPage();
MemoryStream pdfStream = new MemoryStream();
PdfWriter pdfWriter = PdfWriter.GetInstance(doc1, pdfStream);
//Code to create table
doc1.Add(table); //table list in document
//Follow the example 2 (link)
pdfWriter.CloseStream = true;
doc1.Close();
//E fui seguindo o exemplo do segundo link
string file = "D:/gerarPDFOleotorres/"+ nomeDoc +""; …Run Code Online (Sandbox Code Playgroud) 根据ISO标准,A4为210x297 mm,或约595.2756x841.8898点.有没有理由在iTextSharp中,点值是四舍五入的,即.595x842,即使它们是花车?

itextsharp ×10
c# ×7
itext ×2
asp.net ×1
asp.net-mvc ×1
html-parsing ×1
java ×1
merge ×1
pdfptable ×1
razorpdf ×1
rounding ×1
rows ×1
xml ×1