我使用itextSharp有抛光字符的问题.我想从html创建pdf.一切都很好,但缺少波兰人的性格.我使用较低的功能:
private void createPDF(string html)
{
//MemoryStream msOutput = new MemoryStream();
TextReader reader = new StringReader(html);// step 1: creation of a document-object
Document document = new Document(PageSize.A4, 30, 30, 30, 30);
// step 2:
// we create a writer that listens to the document
// and directs a XML-stream to a file
PdfWriter writer = PdfWriter.GetInstance(document, new FileStream("Test.pdf", FileMode.Create));
// step 3: we create a worker parse the document
HTMLWorker worker = new HTMLWorker(document);
// step 4: we open document …Run Code Online (Sandbox Code Playgroud) 所以,我需要一个PDF生成器用于我的ASP.NET应用程序.我下载了iTextSharp,因为它似乎是最受欢迎的免费版本.但在搜索互联网后,我并没有真正找到让我开始的信息.到目前为止,我发现的一些教程太混乱了.我知道那里有一本书,但我是学生,不想花钱.我只需要真正基本的逐步信息,最好是VB中的代码.到目前为止,我发现的最基本的教程是http://www.mikesdotnetting.com/Article/80/Create-PDFs-in-ASP.NET-getting-started-with-iTextSharp,但它对我不起作用.我试着遵循它并想出了这段代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using iTextSharp.text;
using iTextSharp.text.pdf;
using System.IO;
public partial class Default3 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
var doc1 = new Document();
string path = Server.MapPath("PDFs");
PdfWriter.GetInstance(doc1, new FileStream(path + "/Doc1.pdf", FileMode.Create));
doc1.Open();
doc1.Add(new Paragraph("My first PDF"));
doc1.Close();
}
}
Run Code Online (Sandbox Code Playgroud)
但它给了我一个错误:"CS1502:'iTextSharp.text.pdf.PdfWriter.GetInstance(iTextSharp.text.Document,System.IO.Stream)'的最佳重载方法匹配'有一些无效的参数"并且突出显示的行是PdfWriter.GetInstance ...
所以无论如何,我想知道是否有人知道我在本教程中做错了什么,或者我可以使用的其他教程.或者如果你想给我一个如何以你自己的话开始的基本解释,这将是伟大的.请记住,我很遗憾对此一无所知.:) 谢谢.
我试图将2个水晶报告合并为单个pdf文件,我正在使用Itextsharp v5.1.1.但它说文件无法打开.它可能已损坏.没有构建错误.但pdf格式不正确,无法打开.这是我选择完成此任务的顺序.
以下是订单中每个步骤的代码.
/// Get the Dataset from Stored Procedure for the CSSource Report
dsCS = CSData.GetUSSourceXML(ds_input);
/// Create the Report of type CSsource
rptCS = ReportFactory.GetReport(typeof(CSsource));
rptCS .SetDataSource(dsCS);
/// Set the Parameters to the CS report
rptCS .ParameterFields["Parameterid"].CurrentValues.Clear();
rptCS .SetParameterValue("Parameterid", PID);
//// Serialize the Object as PDF
msCS=(MemoryStream)rptCS .ExportToStream(ExportFormatType.PortableDocFormat);
Run Code Online (Sandbox Code Playgroud)
对于第2步
/// Get the Dataset from Stored Procedure for the Aden Report
dsAd = CSData.GetAdden(ds_input);
/// Create the Report of type Aden
rptAd = ReportFactory.GetReport(typeof(Aden));
rptAd.SetDataSource(dsAd …Run Code Online (Sandbox Code Playgroud) 我有一张桌子
PdfPTable tblSummary = new PdfPTable(1);
Run Code Online (Sandbox Code Playgroud)
它确实有2个嵌套在其中的表.如何使tblSummary整个表格显示(行不得中断到另一个页面),或者如果整个表格不适合当前页面,则将其移动到另一个页面.
我曾尝试SplitLate和SplitRows
我的代码是这样的
PdfPTable tblSummary = new PdfPTable(1);
PdfPCell csummarycell = new PdfPCell();
PdfPTable tblSummaryFirst = new PdfPTable(3);
.
.
csummarycell.AddElement(tblSummaryFirst);
.
.
tblSummary.AddCell(csummarycell);
tblSummary.SplitLate = true;
tblSummary.SplitRows = false;
Run Code Online (Sandbox Code Playgroud)
像这样我向tblSummary添加了一个表,而得到的表高度总是小于pagesize的表,所以可以确定表的内容不会超过页面高度.
任何建议都会有所帮助.
我使用iTextPdf从html页面生成pdf文件,如:
iTextSharp.text.html.simpleparser.HTMLWorker hw = new iTextSharp.text.html.simpleparser.HTMLWorker(document);
TextReader reader = new StringReader(HTML);
hw.Parse(reader);
document.Close();
Run Code Online (Sandbox Code Playgroud)
但我的html页面很大,我需要在特定的地方添加页面制动器.
如何在pdf中添加这些分页符?
谢谢
我有一个PDF,因为有一个表是动态的表,我想在我现有的PDF中动态地在下面添加另一个表.
有没有办法在现有PDF中添加现有表格(不在文档末尾)的特定位置,然后我想添加我的表格.
我该如何添加?请建议我一些好方法.
如下图所示.

谢谢,
我正在使用iTextSharp来更新A PDF的文件属性:
FileStream fs = File.Open(@"C:\Developer\C#Projects\BylawSearch\0001.pdf", FileMode.Open);
Document document = new Document();
PdfWriter writer = PdfWriter.GetInstance(document, fs);
document.Open();
document.AddSubject("Blah");
document.AddTitle("Blah blah");
document.AddKeywords("Blah blah blah");
document.Close();
Run Code Online (Sandbox Code Playgroud)
我收到了"文件没有页面".来自iTextSharp的错误.任何帮助赞赏.
我正在使用iTextSharp在PDF文档中创建表.我需要在表格单元格中的几行显示一个在另一个下面,如下所示:
First line text
Second Line Text
Third Line Text
Fourth line text
Run Code Online (Sandbox Code Playgroud)
有时像这样额外的线:
First line text
Second Line Text
Third Line Text
Fourth line text
Run Code Online (Sandbox Code Playgroud)
我尝试了几种方法,使用Paragraphs,Chunks,Phrases,在线进行研究,但仍然无法得到这个结果.请帮忙.另外,如何使列动态调整宽度到内容?(不包装)谢谢
试着按照这里的例子,我添加了以下代码来创建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);
Run Code Online (Sandbox Code Playgroud)
但是,创建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);
Run Code Online (Sandbox Code Playgroud)
...但是也不会编译,说" 'iTextSharp.text.FontFactory.GetFont(string,string,bool)'的最佳重载方法匹配'有一些无效的参数 "
因此,当我复制示例并使用string,int和Font样式时,它说不,它需要string,float和BaseColor.当我添加这些参数时,它改变了它的"思想",并说它真正想要的是字符串,字符串和布尔?
此外,该示例显示然后将段落添加到文档中,如下所示:
doc.Add(docTitle, titleFont);
Run Code Online (Sandbox Code Playgroud)
...但是,这也不会飞,因为" 没有重载方法'添加'需要2个参数 "
我该怎么做才能安抚iTextSharp?无论我是跳舞还是吟唱挽歌,它都不想玩耍.
好的,这编译:
var docTitle = new Paragraph("UCSC Direct - Direct Payment Form");
var titleFont = FontFactory.GetFont("Courier", …Run Code Online (Sandbox Code Playgroud)