在使用itextsharp库生成pdf时,我遇到了这种方法: -
iTextSharp.text.Image img = iTextSharp.text.Image.GetInstance(itextsharp.text.pdf.PdfTemplate);
Run Code Online (Sandbox Code Playgroud)
在哪里,我们可以从PdfTemplate获取Image实例.但是,我不知道如何创建PdfTemplate,并且没有构造函数采用pdf文件名或流.
我想要的原因是:我想从PDF文件创建一个图像,然后将该图像转换为另一个pdf文件.
有谁知道如何创建PdfTemplate对象?
我正在使用itextsharp创建一个pdf文件.我想在pdf文档中为每个页面添加页眉和页脚.谁能告诉我怎么能这样做?
我正在使用itext 5.2.0在此,我无法找到使用HeadeFooter类的选项,该类在早期版本中可用.
提前致谢..
我正在使用iTextSharp在我的.net应用程序中生成pdf.
我被困在一个小而简单的地方,我似乎无法弄明白.
我正在使用PdfPTable生成表并向其添加单元格.
在其中一个单元格中,我想添加说明其中的3个标签.
我试过跟随2个代码,但没有给我想要的输出.
table.AddCell(new Phrase("\t\tDate:", sampleFont)); //Date:
table.AddCell(Chunk.TAB + Chunk.TAB + new Phrase("Date:", sampleFont)); //TABTABDate:
Run Code Online (Sandbox Code Playgroud) 我一直在使用iTextSharp来创建报告.我的报告中有许多不同大小的图像.尽管我缩放它们,但每个图像都会呈现不同的大小.我找到了许多解决方案但没有帮助.
我的代码:
PdfPCell InnerCell;
iTextSharp.text.Image logo = iTextSharp.text.Image.GetInstance(Server.MapPath(@"images\Logo.png"));
logo.ScaleToFit(80f, 80f);
InnerCell.FixedHeight = 80f;
InnerCell = new PdfPCell(logo);
Run Code Online (Sandbox Code Playgroud)
我尝试将图像添加到块中,但图像将其自身置于顶部.由于是动态报告,我无法在块中指定x和y值
InnerCell = new PdfPCell(new Phrase(new Chunk(logo, 0, 0)));
Run Code Online (Sandbox Code Playgroud)
我甚至试过这个,但我不能得到一个固定的大小.
我使用以下代码使用.iTextSharp版本5.4.3生成PDF.
// Create a Document object
var document = new Document(PageSize.A4, 50, 50, 25, 25);
// Create a new PdfWriter object, specifying the output stream
var output = new MemoryStream();
var writer = PdfWriter.GetInstance(document, output);
// Open the Document for writing
document.Open();
string data = @"<table cellspacing="0" border="0" style="border-collapse:collapse;margin-top:30px;;">
<tr>
<td></td><td>Visit</td><td></td><td></td><td></td>
</tr><tr>
<th>Datw</th><td>07/01/2013</td><td>07/18/2013</td><td>07/17/2013</td><td>07/09/2013</td>
</tr><tr>
<th>Score</th><td>3.00</td><td>6.33</td><td>1.00</td><td>8.00</td>
</tr><tr>
<th>Heading</th><td>7.0</td><td>8.0</td><td>2.0</td><td>3.0</td>
</tr><tr>
<th>Minutes</th><td>88</td><td>n/a</td><td>22</td><td>n/a</td>
</tr><tr>
<th>Test Data</th><td>5.0</td><td>8.0</td><td>4.0</td><td>3.0</td>
</tr><tr>
<th>Status</th><td>8.0</td><td>8.0</td><td>3.0</td><td>3.0</td>
</tr><tr>
<th>Data </th><td>3.96</td><td>6.88</td><td>5.83</td><td>6.67</td>
</tr><tr>
<th>Assessment (0-10)</th><td>5.0</td><td>3.0</td><td>2.0</td><td>2.0</td>
</tr><tr>
<th class="seperator">With heading</th><td>n/a</td><td>n/a</td><td>n/a</td><td>n/a</td>
</tr>
</table>";
IElement ele;
PdfPTable t; …Run Code Online (Sandbox Code Playgroud) 我正在使用iTextSharp以编程方式创建PDF并生成PdfPTable.
在一些细胞中,我需要有一个超链接.
没有超链接我可以水平和垂直对齐单元格中的文本,但是当我添加包含我的超链接的块时,单元格将失去其对齐属性.
这是我的代码......
var webAddress = new Chunk(row["product_code"].ToString(), linkFont);
webAddress.SetAnchor(row["url"].ToString());
PdfPCell ProductCodeCell = new PdfPCell();
ProductCodeCell.AddElement(webAddress);
ProductCodeCell.VerticalAlignment = Element.ALIGN_MIDDLE;
ProductCodeCell.HorizontalAlignment = Element.ALIGN_CENTER;
ProductCodeCell.Padding = 3f;
table.AddCell(ProductCodeCell);
Run Code Online (Sandbox Code Playgroud)
任何人都可以帮我重新调整链接吗?
非常感谢.
我正在尝试使用iTextSharp压缩PDF.有很多页面将彩色图像存储为JPEG(DCTDECODE)...所以我将它们转换为黑白PNG并在文档中替换它们(PNG比JPG的黑白格式小得多)
我有以下方法:
private static bool TryCompressPdfImages(PdfReader reader)
{
try
{
int n = reader.XrefSize;
for (int i = 0; i < n; i++)
{
PdfObject obj = reader.GetPdfObject(i);
if (obj == null || !obj.IsStream())
{
continue;
}
var dict = (PdfDictionary)PdfReader.GetPdfObject(obj);
var subType = (PdfName)PdfReader.GetPdfObject(dict.Get(PdfName.SUBTYPE));
if (!PdfName.IMAGE.Equals(subType))
{
continue;
}
var stream = (PRStream)obj;
try
{
var image = new PdfImageObject(stream);
Image img = image.GetDrawingImage();
if (img == null) continue;
using (img)
{
int width = img.Width;
int height = …Run Code Online (Sandbox Code Playgroud) 我使用itextsharp生成PDF文件,
我正在打印2个字符串leading1和leading2.
问题是,当领先1长度增加时,它影响领先2并且它被修剪.
但是如果在leading1中没有字符增加,我想在下一行打印leading1和leading2.
基本上,leading2被硬编码为=你的DIDIT.但是leading1是动态价值.
所以,我只想知道如何定位和包装长文本.
这是我的代码......
有人可以帮我这样做吗?
PdfContentByte cb = writer.getDirectContent();
cb.saveState();
cb.beginText();
cb.setFontAndSize(baseFontMedium, 10f);
// float x = 6.4392f * commonView.INCH;
float x = 6.47f * commonView.INCH;
float y = pageSize.getHeight() - (1.13f * commonView.INCH);
cb.setCMYKColorFillF(0f, 0f, 0f, 0.77f);
cb.setTextMatrix(1, 0, 0, 1, x, y);
cb.showText(leading1);
x += new Chunk(leading1, fontMedium10Pt).getWidthPoint();
cb.setCMYKColorFillF(1f, 0f, 0f, 0f);
cb.setTextMatrix(1, 0, 0, 1, x, y);
cb.showText(leading2);
cb.endText();
cb.restoreState()
Run Code Online (Sandbox Code Playgroud) 我在C#项目中使用iTextSharp库来读取和编辑pdf文档.现在我想更改某个pdf文档的标题.我搜索了很多关于这个问题,但没有什么对我有用.我发现的最好的是:
PdfReader pdfReader = new PdfReader(filePath);
using (FileStream fileStream = new FileStream(newFilePath,
FileMode.Create,
FileAccess.Write))
{
string title = pdfReader.Info["Title"] as string;
Trace.WriteLine("Existing title: " + title);
PdfStamper pdfStamper = new PdfStamper(pdfReader, fileStream);
// The info property returns a copy of the internal HashTable
Hashtable newInfo = pdfReader.Info;
newInfo["Title"] = "New title";
pdfStamper.MoreInfo = newInfo;
pdfReader.Close();
pdfStamper.Close();
}
Run Code Online (Sandbox Code Playgroud)
但Visual Studio表示System.Collection.Hashtable无法将其隐式转换为System.Collections.Generic.IDictionary<string,string>.已有转换.
希望有人能帮助我.或者使用iTextSharp的另一个解决方案来编辑标题.