是否可以使用.net编辑pdf文档的javascript?
我看过Acrobat SDK,但没有太多运气.看起来您可以从表单等中检索值,但不能编辑文档.
我离开赛道了吗?这甚至可能吗?
我已经尝试过iTextSharp,但由于pdf包含表单字段,因此在保存pdf时字段会丢失.
有什么建议?
我有一个iTextSharp.text.Table并尝试更改前景文本颜色.但是Cell对象上没有方法来定义颜色.有谁知道,我可以在哪里调整颜色?
我正在尝试创建一种方法,将PDF文件直接发送到我的打印机(导致打印对话框出现).
下面是我一直在研究的代码 - 大部分代码都在这里的论坛中找到.如果我使用iTextSharp创建一个新的PDF文档,它可以正常工作,但是一旦我尝试将一些JavaScript注入到现有文件中,我在调用print()方法时会遇到异常
对象不支持属性或方法'print'
<script type="text/javascript">
function load() {
try {
var x = document.getElementById("frame1");
x.print();
}
catch (err) {
}
}
</script>
<body onload="load();">
<form id="form1" runat="server">
<div>
<iframe id="frame1" src="C:/1686850_1.pdf" runat="server" frameborder="0" style="height: 0px; width: 0px;" />
</div>
</form>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
.CS文件
using System.IO;
using iTextSharp.text;
using iTextSharp.text.pdf;
public partial class Print : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
SetPDF(File.ReadAllBytes("C:\\1686850.pdf"), "C:\\1686850_1.pdf"); //test files
}
private void SetPDF(byte[] file, …Run Code Online (Sandbox Code Playgroud) 我想用ITextSharp创建以下PDF布局:

我使用以下代码生成我的表:
Document document = new Document(PageSize.A4);
MemoryStream memoryStream = new MemoryStream();
PdfWriter writer = PdfWriter.GetInstance(document, memoryStream);
document.Open();
PdfPCell cell;
PdfPTable table = new PdfPTable(2);
table.SetWidths(new float[] { 450, 100 });
table.WidthPercentage = 100;
cell = new PdfPCell(new Phrase("Item cod werwerwer"));
table.AddCell(cell);
cell = new PdfPCell(new Phrase("100"));
table.AddCell(cell);
cell = new PdfPCell(new Phrase(string.Empty));
table.AddCell(cell);
cell = new PdfPCell(new Phrase("100"));
table.AddCell(cell);
document.Add(table);
writer.CloseStream = false;
document.Close();
memoryStream.Position = 0;
return memoryStream.ToArray();
Run Code Online (Sandbox Code Playgroud)
如何在不使用固定高度值的情况下强制表格覆盖整页高度?
是否可以使用iTextSharp在句子中加粗单个单词?我正在处理来自xml的大段文本,我试图加粗几个单词,而不必将字符串分成单个短语.
例如:
document.Add(new Paragraph("this is <b>bold</b> text"));
Run Code Online (Sandbox Code Playgroud)
应该输出......
这是粗体文字
在以下代码中,中文字体(包含的html文本)不会以pdf格式显示.我也尝试这种方法中的样式和字体.请帮忙解决这个问题.在此先感谢所有人.
public static bool GeneratedPDF(string strHTMLText, string filename, string action, string rpttype)
{
bool blnReturn = false;
string fontpath = HttpContext.Current.Server.MapPath("~/files/fonts/");
string filepath = HttpContext.Current.Server.MapPath("~/files/pdf/");
BaseFont customfont = BaseFont.CreateFont(fontpath + "simhei.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
Font font = new Font(customfont, 12);
//List<iTextSharp.text.IElement> htmlarraylist = iTextSharp.text.html.simpleparser.HTMLWorker.ParseToList(new System.IO.StringReader(strHTMLText), null);
iTextSharp.text.Document document = new iTextSharp.text.Document();
if (rpttype.Trim().ToUpper() == "REPORT")
document = new iTextSharp.text.Document(iTextSharp.text.PageSize.A2.Rotate());
else if (rpttype.Trim().ToUpper() == "GRID")
document = new iTextSharp.text.Document(iTextSharp.text.PageSize.A4.Rotate());
else
document = new iTextSharp.text.Document(iTextSharp.text.PageSize.LETTER);
iTextSharp.text.pdf.PdfWriter writer = iTextSharp.text.pdf.PdfWriter.GetInstance(document, new FileStream(filepath + "\\" …Run Code Online (Sandbox Code Playgroud) 有没有办法将现有pdf页面内的文本移动/移动到其他位置?
就像在区域x = 100处有一些文本,y = 100,w = 100,h = 100并且我想将其移动到x = 50,y = 200,w = 100,h = 100.
我做了很多研究,似乎iTextSharp做不到.PDFSharp声称它可以完成,但我找不到任何例子.
一种方法是制作我想要移动的文本的特定区域的位图,在该区域上绘制白色矩形并在新位置插入位图.我不想使用这个解决方案,因为我使用超过1K页面的大型pdf文件,其中每个页面都必须被更改.
我发现的是,我需要找到一种方法来改变文本定位操作符(文本矩阵和文本状态参数),这并不是那么简单.
有人有什么想法吗?
有没有办法使用iTextSharp更改PDF中第二页的页边距?
我现在有:
Document document = new Document(PageSize.A4, 144f, 72f, 144f, 90f);
PdfWriter.GetInstance(document, ms);
/* first page content */
document.NewPage();
document.SetMargins(72f, 72f, 72f, 100f);
/* second page content */
Run Code Online (Sandbox Code Playgroud)
但是,第二页上的边距是为第一页设置的边距.
是否可以在C#中为PageSize设置默认参数的值?例如:
public virtual void Render(string reportTitle, Rectangle pageSize = PageSize.A4)
{
foreach (Page p in pages)
{
p.Render(document);
document.NewPage();
document.AddCreationDate();
document.AddTitle(reportTitle);
document.SetPageSize(pageSize);
}
}
Run Code Online (Sandbox Code Playgroud)
我在Visual Studio 2010中有以下错误:
'pageSize'的默认参数值必须是编译时常量.
c# asp.net-mvc visual-studio-2010 itextsharp default-parameters
我有一个Web服务,它调用以下方法.我想返回一个内存流,这是一个PDF文件.
现在,问题是PDF文件已损坏,代码如下.我认为这是因为文件没有被关闭.但是,如果我关闭它们,我会收到经典错误"无法访问已关闭的流".
当我之前通过文件流保存它时,PDF文件没有损坏.
所以我的谦虚问题是:如何解决它并找回一个未损坏的PDF文件?:-)
我的代码:
public Stream Generate(GiftModel model)
{
var template = HttpContext.Current.Server.MapPath(TemplatePath);
// Magic code which creates a new PDF file from the stream of the other
PdfReader reader = new PdfReader(template);
Rectangle size = reader.GetPageSizeWithRotation(1);
Document document = new Document(size);
MemoryStream fs = new MemoryStream();
PdfWriter writer = PdfWriter.GetInstance(document, fs);
document.Open();
// Two products on every page
int bookNumber = 0;
int pagesWeNeed = (int)Math.Ceiling(((double)model.Books.Count / (double)2));
for (var i = 0; i < pagesWeNeed; i++)
{ …Run Code Online (Sandbox Code Playgroud)