Tag: itextsharp

使用itextsharp根据大小将pdf拆分为较小的pdf

所以我们有一些非常低效的代码,根据允许的最大大小将pdf分成更小的块。 阿卡。 如果最大大小为10megs,则将跳过8兆字节文件,而将根据页数拆分16兆字节文件。 这是我inheritance的代码,并且感觉必须有一种更有效的方法来执行此操作,只需要一个方法和较少的对象实例化。 我们使用以下代码来调用方法: List splitPoints = null; List documents = null; splitPoints = this.GetPDFSplitPoints(currentDocument, maxSize); documents = this.SplitPDF(currentDocument, maxSize, splitPoints); 方法: private List GetPDFSplitPoints(IClaimDocument currentDocument, int maxSize) { List splitPoints = new List(); PdfReader reader = null; Document document = null; int pagesRemaining = currentDocument.Pages; while (pagesRemaining > 0) { reader = new […]

如何在单个pdf单元格中添加两行?

我是条码。 现在我想在条形码标签下插入学生代码。 我怎么能这样做?我的代码是 foreach (GridViewRow row in grdBarcode.Rows) { DataList dl = (DataList)row.FindControl(“datalistBarcode”); PdfContentByte cb = new PdfContentByte(writer); PdfPTable BarCodeTable = new PdfPTable(6); BarCodeTable.SetTotalWidth(new float[] { 100,10,100,10,100,10 }); BarCodeTable.DefaultCell.Border = PdfPCell.NO_BORDER; Barcode128 code128 = new Barcode128(); code128.CodeType = Barcode.CODE128_UCC; foreach (DataListItem dli in dl.Items) { String barcodename= ((Label)dli.FindControl(“lblBarCode”)).Text; string studentcode= ((Label)dli.FindControl(“lblStudCode”)).Text; code128.Code = “*” + […]

使用iTextSharp和PDFStamper在PDF中使用不同的字体

我正在使用iTextSharp加载现有PDF并使用PdfStamper添加文本。 我希望完全控制文本,这意味着我希望能够控制字体(仅限TrueType),字体大小和坐标。 现在,我正在使用ShowTextAligned将文本添加到某些协调,并使用setFontAndSize来设置字体和字体大小。 这是我添加文字的代码: private void AddText(BaseFont font, string text, int x, int y, int size) { pdf.BeginText(); pdf.SetFontAndSize(font, size); pdf.ShowTextAligned(PdfContentByte.ALIGN_LEFT, text, x, y, 0); pdf.EndText(); } 以下函数用于加载TrueType字体: public BaseFont GetFont(string font, string encoding) { if (!(font.EndsWith(“.ttf”) || font.EndsWith(“.TTF”))) font += “.ttf”; BaseFont basefont; basefont = BaseFont.CreateFont(ConfigurationManager.AppSettings[“fontdir”] + font, encoding, BaseFont.NOT_EMBEDDED); if (basefont == null) […]

无法在ASP.NET 5 Core中使用iTextSharp

我正在尝试将iTextSharp与ASP.NET 5 Core一起使用。 但是,当我尝试使用iTextSharp 5.5.5构建ASP.NET应用程序时,我收到了这些错误 码: using Microsoft.AspNet.Mvc; using System.IO; using System; using iTextSharp; using iTextSharp.text; using iTextSharp.text.pdf; // For more information on enabling MVC for empty projects, visit http://go.microsoft.com/fwlink/?LinkID=397860 namespace MyNamespace { public class GenerateFileController : Controller { // GET: // public string Index() { PdfReader reader = new PdfReader(“template.pdf”); return “SomeText”; } } […]

代码没有在我的PDF中绘制水平线

我正在尝试在顶部添加一条水平线,以将标题文本与我的pdf文件中的实际值分开: 这是我的代码: public class StudentList { public void PrintStudentList(int gradeParaleloID) { StudentRepository repo = new StudentRepository(); var students = repo.FindAllStudents() .Where(s => s.IDGradeParalelo == gradeParaleloID); try { Document document = new Document(PageSize.LETTER); PdfWriter writer = PdfWriter.GetInstance(document, new FileStream(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) + “\\Alumnos.pdf”, FileMode.Create)); document.Open(); PdfContentByte cb = writer.DirectContent; cb.SetLineWidth(2.0f); // Make a bit thicker than 1.0 default […]

如何使用iTextSharp设置PDF段落的字体?

试着按照这里的例子,我添加了以下代码来创建PDF文档的标题: using (var doc = new Document(PageSize.A4, 50, 50, 25, 25)) { using (var writer = PdfWriter.GetInstance(doc, ms)) { doc.Open(); var docTitle = new Paragraph(“UCSC Direct – Direct Payment Form”); var titleFont = FontFactory.GetFont(“Lucida Sans”, 18, Font.Bold); doc.Add(docTitle); 但是,创建titleFont的尝试不会编译(“ ‘iTextSharp.text.FontFactory.GetFont(string,float,iTextSharp.text.BaseColor)’的最佳重载方法匹配’有一些无效的参数 ”),所以我让intellisenseless通过一次添加一个arg来“帮助”我。 因为对于第一个arg它说它是字体名称,一个字符串,我添加了“Segoe UI”; 下一个arg是字体大小,一个浮点数,所以我加了18.0; 最后,它调用了字体颜色,一个BaseColor类型,所以我添加了BaseColor.Black,最后得到: var titleFont = FontFactory.GetFont(“Segoe UI”, 18.0, BaseColor.BLACK); …但是也不会编译,说“ ‘iTextSharp.text.FontFactory.GetFont(string,string,bool)’的最佳重载方法匹配’有一些无效的参数 ” […]

.NET版本或Flying Saucer端口

是否有任何类似于Flying Saucer项目的开源.NET项目(或端口),它使用iText将HTML呈现为PDF ?

如何使用iTextSharp为页面添加边框?

是否可以使用iTextSharp为PDF文档中的页面添加边框? 我从头开始生成PDF文件,因此我不需要为现有文档添加边框。 这是我的代码示例: Document pdfDocument = new Document(PageSize.LETTER); Font headerFont = new Font(baseFont, 13); Font font = new Font(baseFont, 10); PdfWriter writer = PdfWriter.GetInstance(pdfDocument, new FileStream(fileName, FileMode.Create)); pdfDocument.Open(); //I add IElements here. pdfDocument.Close();

使用iTextSharp设置页边距

我有一个嵌入了PDF表单字段的模板PDF文件。我使用PdfStamper来填写这些字段。 另外,我希望能够更改生成的PDF的边距。 有什么办法可以修改加盖PDF的页边距吗?

如何使用itextsharp将UTF-8字符写入pdf文件?

我在谷歌上尝试了很多但是却找不到.. 任何帮助表示赞赏.. Plz帮助.. 请找到以下代码: – protected void Page_Load(object sender, EventArgs e) { StreamReader read = new StreamReader(@”D:\queryUnicode.txt”, Encoding.Unicode); string str = read.ReadToEnd(); Paragraph para = new Paragraph(str); FileStream file = new FileStream(@”D:\Query.pdf”,FileMode.Create); Document pdfDoc = new Document(); PdfWriter writer = PdfWriter.GetInstance(pdfDoc, file ); pdfDoc.Open(); pdfDoc.Add(para); pdfDoc.Close(); Response.Write(“Pdf file generated”); }