我正在从iTextSharp创建一个PDF进行打印.我有可变长度的文本,我希望始终使用最大字体大小来填充固定高度的表格单元格而不会看不到视线.如何才能做到这一点?
我想使用ITextSharp将ASP.NET网页转换为pdf.我写了一些代码,但我不能让它显示土耳其字符.谁能帮我?
这是代码:
using System;
using System.IO;
using iTextSharp.text;
using iTextSharp.text.pdf;
using System.Web.UI;
using System.Web;
using iTextSharp.text.html.simpleparser;
using System.Text;
using System.Text.RegularExpressions;
namespace Presentation
{
public partial class TemporaryStudentFormPrinter : System.Web.UI.Page
{
protected override void Render(HtmlTextWriter writer)
{
MemoryStream mem = new MemoryStream();
StreamWriter twr = new StreamWriter(mem);
HtmlTextWriter myWriter = new HtmlTextWriter(twr);
base.Render(myWriter);
myWriter.Flush();
myWriter.Dispose();
StreamReader strmRdr = new StreamReader(mem);
strmRdr.BaseStream.Position = 0;
string pageContent = strmRdr.ReadToEnd();
strmRdr.Dispose();
mem.Dispose();
writer.Write(pageContent);
CreatePDFDocument(pageContent);
}
public void CreatePDFDocument(string strHtml)
{
string strFileName = HttpContext.Current.Server.MapPath("test.pdf"); …Run Code Online (Sandbox Code Playgroud) 我希望PDF阅读器(Adobe Reader)打开PDF文件,缩放自动设置为100%.
谢谢!
我正在使用PdfStamper在运行时创建PDF.我的问题是我无法增加PDF字段的字体大小.我试过这个,但没有运气,
stamper.AcroFields.SetFieldProperty("names", "textsize", 4f, null);
Font font = FontFactory.GetFont(FontFactory.COURIER, 2f, iTextSharp.text.Font.BOLD);
stamper.AcroFields.AddSubstitutionFont(font.BaseFont);
Run Code Online (Sandbox Code Playgroud) 我正在使用LibreOffice 4.1.3.2生成可填写的PDF:
使用Acrobar Reader打开pdf文件显示正确的可填写pdf.
接下来我使用iTextSharp 5.4.5填充字段并保存展平文档:
var pdf = new PdfReader(srcFilename);
using (var fw = new FileStream(dstFilename, FileMode.Create))
{
var stamper = new PdfStamper(pdf, fw);
var f = stamper.AcroFields;
f.SetField("field1", "John Doe");
f.SetField("field2", "12/04/2013");
stamper.FormFlattening = true;
stamper.Close();
}
pdf.Close();
Run Code Online (Sandbox Code Playgroud)
问题是填充的字段值在新文档中完全消失!
我认为没有找到或填充字段,但发现stamper.FormFlattening = true在保存的pdf中有评论字段值!
当然,我需要一个扁平化的PDF格式...
这有解决方案吗?
我正在使用iTextSharp(5.4.5)几个星期了.本周,我遇到了一些奇怪的事情,它涉及到文档中元素的顺序.
我正在制作一份包含主题和图片(图表)的pdf报告.
文档的格式如下:
NR.主题标题1
主题1的CHART IMAGE(来自bytearray)
NR.主题2的主题标题
主题2的CHART IMAGE ...
下面是一个代码示例.我知道代码不完全正确,但它只是指出问题.让我们假设循环运行10次,所以我希望10个主题标题都直接跟随图像.
我注意到的是,如果到达页面结束并且应该添加新的IMAGE,则图像将移动到下一页,并且下一个主题标题将打印在上一页上.
所以在纸上我们有:
第1页:
主题1图像主题1
主题2图像主题2
主题3主题4
第2页:
图像主题3图像主题4
主题5图像主题5
...
因此,纸上元素的顺序与我通过Document.add方法将元素放在文档中的顺序不同.
这真的很奇怪.任何人有任何想法?
int currentQuestionNr = 0;
foreach (Topic currentTOPIC in Topics)
{
currentQuestionNr++;
//compose question (via table so all questions (with nr prefix) are aligned the same)
PdfPTable questionTable = new PdfPTable(2);
questionTable.WidthPercentage = 100;
questionTable.SetWidths(new int[] { 4, 96 });
PdfPCell QuestionNrCell = new PdfPCell();
QuestionNrCell.BorderWidth = 0;
QuestionNrCell.HorizontalAlignment = PdfPCell.ALIGN_LEFT;
QuestionNrCell.VerticalAlignment = PdfPCell.ALIGN_TOP;
QuestionNrCell.AddElement(new Paragraph(String.Format("{0}. ", currentQuestionNr), …Run Code Online (Sandbox Code Playgroud) 如果我说:
var georgia = FontFactory.GetFont("Georgia Regular", 10f);
Run Code Online (Sandbox Code Playgroud)
它不起作用.当我检查变量georgia的状态时,它的Family属性设置为值UNDEFINED,其FamilyName属性设置为Unknown.
它只有在我实际加载并注册字体文件然后得到它时才有效:
FontFactory.Register("C:\\Windows\\Fonts\\georgia.ttf", "Georgia");
var georgia = FontFactory.GetFont("Georgia", 20f);
Run Code Online (Sandbox Code Playgroud)
这是为什么?
使用itextsharp,我试图将表单的文本字段的字体大小设置为auto.
我现在正在做这样的事情:
Object d = 0.0;
PdfReader reader = new PdfReader(path);
byte [] pdf;
using (var ms = new MemoryStream())
{
PdfStamper stamper = new PdfStamper(reader, ms);
AcroFields fields = stamper.AcroFields;
foreach (var f in fields.Fields.Keys)
{
fields.SetFieldProperty(f, "textsize", d, null);
}
}
Run Code Online (Sandbox Code Playgroud)
但是我收到以下错误:
System.InvalidCastException: Specified cast is not valid.
at iTextSharp.text.pdf.AcroFields.SetFieldProperty(String field, String name, Object value, Int32[] inst)
Run Code Online (Sandbox Code Playgroud)
我怎样才能解决这个问题?
我目前正在研究PDF,但我正面临着试图增加a的行高的问题Paragraph,这是我现在的代码:
var tempTable = new PdfPTable(1);
cell = new PdfPCell(new Paragraph("My Account", GetInformationalTitle()));
cell.Border = Rectangle.NO_BORDER;
tempTable.AddCell(cell);
cell = new PdfPCell(new Paragraph("http://www.google.com/", GetInformationalOblique()));
cell.Border = Rectangle.NO_BORDER;
cell.PaddingBottom = 10f;
tempTable.AddCell(cell);
var para = new Paragraph("Login to 'My Account' to access detailed information about this order. " +
"You can also change your email address, payment settings, print invoices & much more.", GetInformationalContent());
para.SetLeading(0f, 2f);
cell = new PdfPCell(para);
cell.Border = Rectangle.NO_BORDER;
tempTable.AddCell(cell);
Run Code Online (Sandbox Code Playgroud)
正如你从上面所看到的,我正在尝试增加行高para,我已经尝试了para.SetLeading(0f, 2f)但它仍然没有增加行高或行距,因为它被称为. …
itextsharp ×10
c# ×5
pdf ×4
acrofields ×2
itext ×2
acrobat ×1
c#-4.0 ×1
page-zoom ×1
turkish ×1
typography ×1