我无法在常见问题解答中找到API中是否存在此功能,尽管它在书中提到的可能是可用的.有没有人有任何实现此功能的经验?
嗨,我正在使用itextsharp创建PDF.现在我的要求是在现有的pdf中添加更多文本.是否有可能,那么我该怎么做呢?
谢谢Dipa
我想为发票创建PDF,我使用了iTextSharp的DLL,我能够成功创建PDF.我在ASP.NET中使用Visual C#.NET.
问题是,我想把信息标题放在左侧,然后将有关该信息标题的有关信息放在右侧.例如:
<blink>
First Name: John Marshal
Address: Missouri
Street: Honolulu 23rd
</blink>
Run Code Online (Sandbox Code Playgroud)
在这里,我将"名字,地址,街道"称为信息标题,将"John Marshal,Missouri,Honolulu 23rd"称为信息.
是否有任何解决方案可以将所有这些内容对齐,以便发票变得可见且有意义.虽然我已经使用空格来创建这种格式,如下所示: -
document.Add(new Paragraph(" CROWN SERVICE LIMITED", new Font(Font.BOLD, 25)));
document.Add(new Paragraph (" John Marshal ", new Font(Font.BOLD, 20)));
document.Add(new Paragraph (" Missouri Honolulu 23rd", new Font(Font.BOLD, 20)));
Run Code Online (Sandbox Code Playgroud)
虽然我试图在PDF的背景中使用图像,但它似乎仍然不合适.
我认为通过将数据转换为XML可以有一些解决方案,如果有可能,请告诉我.
单击按钮时出现以下错误
,
点击按钮我调用以下方法:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.IO;
using iTextSharp.text.html.simpleparser;
using iTextSharp.text;
using iTextSharp.text.pdf;
using iTextSharp.text.html;
/// <summary>
/// Summary description for pdfgeneration
/// </summary>
public class pdfgeneration
{
public pdfgeneration()
{
//
// TODO: Add constructor logic here
//
}
public void pdfgenerator(String name1, AjaxControlToolkit.HTMLEditor.Editor Editor1)
{
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.ContentType = "application/pdf";
// Create PDF document
Document pdfDocument = new Document(PageSize.A4, 70, 55, 40, 25);
PdfWriter wri = PdfWriter.GetInstance(pdfDocument, new FileStream("e://" +name1 + ".pdf", FileMode.Create)); …Run Code Online (Sandbox Code Playgroud) 有没有人知道如何在一个标题(一个粗体文本的短行)下画一条线,它可能位于页面上的随机位置.
例如
My Heading 1
----------------------------------------------
Some random paragraph
My Heading 2
----------------------------------------------
Run Code Online (Sandbox Code Playgroud)
我可以这样做,就像我上面使用一行下划线_但为了得到标题附近的任何地方我必须将字体大小设置为2,这会导致一条斑驳的丑陋线.
我还可以在彼此的顶部添加两个块(一个带有标题,一个带有_),类似于本文中的第一个示例http://www.mikesdotnetting.com/Article/82/iTextSharp-Adding-Text- with-Chunks-Phrases-and-Paragraphs使用相同的字体大小,但似乎这只适用于页面顶部,一旦我添加其他段落并尝试在页面中间向下执行,两个块分开一个在第一个块的末尾清除换行符.
看来你可以在iTextSharp中绘制线条,但我不知道如何计算坐标,因为我看到的所有例子都使用这种方法在固定位置的页面顶部或底部放置一条线.
任何帮助非常感谢.
干杯罗布
我正在使用iTextSharp创建Shipping Label.
我正在做的是用PDF创建标签,这样我就可以用我想要的任何方式对其进行格式化,然后将其发送到我的热敏打印机.
我的问题是,我的标签大小为4x6(标准运输标签).这些是我们在UPS和Fedex包上看到的标签.如何使我的PDF完全适合4x6英寸?目前正在普通A4文件中打印.
我使用以下:
Dim document As New Document()
document.SetPageSize(PageSize.A4_LANDSCAPE)
Run Code Online (Sandbox Code Playgroud) 我想在iTextPDf中显示Special Character India Rupee Symbol,
我的代码:
Font fontRupee = FontFactory.GetFont("Arial", "?", true, 12);
Chunk chunkRupee = new Chunk(" ? 5410", font3);
Run Code Online (Sandbox Code Playgroud) 在我的Windows 8应用程序中,我想逐行读取PDF,然后我想分配一个String数组.我该怎么做?
public StringBuilder addd= new StringBuilder();
string[] array;
private async void btndosyasec_Click(object sender, RoutedEventArgs e)
{
FileOpenPicker openPicker = new FileOpenPicker();
openPicker.ViewMode = PickerViewMode.List;
openPicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
openPicker.FileTypeFilter.Add(".pdf");
StorageFile file = await openPicker.PickSingleFileAsync();
if (file != null)
{
PdfReader reader = new PdfReader((await file.OpenReadAsync()).AsStream());
for (int page = 1; page <= reader.NumberOfPages; page++)
{
addd.Append(PdfTextExtractor.GetTextFromPage(reader, page));
string tmp= PdfTextExtractor.GetTextFromPage(reader, page);
array[page] = tmp.ToString();
reader.Close();
}
}
}
Run Code Online (Sandbox Code Playgroud) 我有一个名为"DocumentContent"的富文本框,我将使用以下代码将其内容添加到pdf:
iTextSharp.text.Font font = FontFactory.GetFont(@"C:\Windows\Fonts\arial.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED, 12f, Font.NORMAL, BaseColor.BLACK);
DocumentContent = System.Web.HttpUtility.HtmlDecode(DocumentContent);
Chunk chunkContent = new Chunk(DocumentContent);
chunkContent.Font = font;
Phrase PhraseContent = new Phrase(chunkContent);
PhraseContent.Font = font;
PdfPTable table = new PdfPTable(2);
table.WidthPercentage = 100;
PdfPCell cell;
cell = new PdfPCell(new Phrase(PhraseContent));
cell.Border = Rectangle.NO_BORDER;
table.AddCell(cell);
Run Code Online (Sandbox Code Playgroud)
问题是当我打开PDF文件时,内容显示为HTML而不是文本,如下所示:
<p>Overview  line1 </p><p>Overview  line2
</p><p>Overview  line3 </p><p>Overview 
line4</p><p>Overview  line4</p><p>Overview 
line5 </p>
Run Code Online (Sandbox Code Playgroud)
但它应该如下所示
Overview line1
Overview line2
Overview line3
Overview line4
Overview line4
Overview line5
Run Code Online (Sandbox Code Playgroud)
我要做的是保留用户应用于富文本的所有样式,只需将字体系列更改为Arial.
我可以更改字体系列,但我需要将此内容从HTML解码为文本.
您能否提一些建议?谢谢
有没有办法让iTextSharp与Windows 10 Universal应用程序一起使用?当我尝试通过NuGet包管理器添加iTextSharp版本5.5.8时,我收到以下错误:
iTextSharp 5.5.8 is not compatible with UAP, Version=v10.0(win10-XXX)
Some packages are not compatible ith UAP,Version=v10.0(win10-XXX)
Run Code Online (Sandbox Code Playgroud)
其中XXX是x64或x86等平台.我们在Windows 8商店应用程序中使用iTextSharp来获取PDF模板,然后使用用户提供的数据填充字段.用户还提供模板,以便按照他们想要的方式格式化文档.为此,我们使用iTextSharp库中的PDFStamper类来执行此操作,如以下代码所示:
public async Task<byte[]> fillPDF(string templatePath, FormData mergeDataItems)
{
StorageFile file = await StorageFile.GetFileFromPathAsync(templatePath);
var buf = await FileIO.ReadBufferAsync(file);
var reader = new PdfReader(buf.ToArray());
var outStream = new MemoryStream();
var stamper = new PdfStamper(reader, outStream);
var form = stamper.AcroFields;
form.GenerateAppearances = true; //Added this line, fixed my problem
var fieldKeys = form.Fields.Keys;
foreach (KeyValuePair<String, String> pair in mergeDataItems.MergeFieldValues)
{
if (fieldKeys.Any(f …Run Code Online (Sandbox Code Playgroud)