如何使用itextsharp在内存流而不是物理文件中创建PDF.
下面的代码是创建实际的pdf文件.
相反,我如何创建一个byte []并将其存储在byte []中,以便我可以通过函数返回它
using iTextSharp.text;
using iTextSharp.text.pdf;
Document doc = new Document(iTextSharp.text.PageSize.LETTER, 10, 10, 42, 35);
PdfWriter wri = PdfWriter.GetInstance(doc, new FileStream("c:\\Test11.pdf", FileMode.Create));
doc.Open();//Open Document to write
Paragraph paragraph = new Paragraph("This is my first line using Paragraph.");
Phrase pharse = new Phrase("This is my second line using Pharse.");
Chunk chunk = new Chunk(" This is my third line using Chunk.");
doc.Add(paragraph);
doc.Add(pharse);
doc.Add(chunk);
doc.Close(); //Close document
Run Code Online (Sandbox Code Playgroud) 如何在pdf中为每个页面添加页眉和页脚.
Headed将只包含一个文本页脚将包含pdf的文本和分页(页:1/4)
这怎么可能 ?我尝试添加以下行,但标题不会显示在pdf中.
document.AddHeader("Header", "Header Text");
Run Code Online (Sandbox Code Playgroud)
这是我用于生成PDF的代码:
protected void GeneratePDF_Click(object sender, EventArgs e)
{
DataTable dt = getData();
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "attachment;filename=Locations.pdf");
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Document document = new Document();
PdfWriter.GetInstance(document, Response.OutputStream);
document.Open();
iTextSharp.text.Font font5 = iTextSharp.text.FontFactory.GetFont(FontFactory.COURIER , 8);
PdfPTable table = new PdfPTable(dt.Columns.Count);
PdfPRow row = null;
float[] widths = new float[] { 6f, 6f, 2f, 4f, 2f };
table.SetWidths(widths);
table.WidthPercentage = 100;
int iCol = 0;
string colname = "";
PdfPCell cell = new PdfPCell(new Phrase("Locations"));
cell.Colspan = …Run Code Online (Sandbox Code Playgroud) 是否可以使用iTextSharp从PDF文档中删除不可见(或至少不显示)的对象?
更多细节:
1)我的来源是一个PDF页面,其中包含图像和文本(可能是一些矢量图)和嵌入字体.
2)有一个界面来设计多个"裁剪框".
3)我必须生成一个新的PDF,其中只包含裁剪框内的内容.必须从结果文件中删除任何其他内容(事实上,我可能会接受内部一半和一半外部的内容,但这不是理想的,无论如何都不应该出现).
到目前为止我的解
我已经成功开发了一个创建新临时文档的解决方案,每个文档都包含每个裁剪框的内容(使用writer.GetImportedPage和contentByte.AddTemplate到一个与裁剪框大小完全相同的页面).然后我创建最终文档并重复该过程,使用AddTemplate方法在最后一页中定位每个"裁剪页面".
该解决方案有两大缺点:
所以,我认为我需要遍历PDF对象,检测它是否可见,并删除它.在撰写本文时,我正在尝试使用pdfReader.GetPdfObject.
谢谢您的帮助.
我正在使用VB.Net我有一个图像的网址,让我们说http://localhost/image.gif
我需要从该文件创建一个System.Drawing.Image对象.
请注意将此保存到文件然后打开它不是我正在使用的选项之一ItextSharp
这是我的代码:
Dim rect As iTextSharp.text.Rectangle
rect = iTextSharp.text.PageSize.LETTER
Dim x As PDFDocument = New PDFDocument("chart", rect, 1, 1, 1, 1)
x.UserName = objCurrentUser.FullName
x.WritePageHeader(1)
For i = 0 To chartObj.Count - 1
Dim chartLink as string = "http://localhost/image.gif"
x.writechart( ** it only accept system.darwing.image ** )
Next
x.WritePageFooter()
x.Finish(False)
Run Code Online (Sandbox Code Playgroud) 背景:
我有PDF,我是以编程方式生成的.我需要能够从服务器直接将PDF发送到打印机(而不是通过中间应用程序).目前我可以完成上述所有操作(生成PDF,发送到打印机),但由于字体未嵌入PDF中,因此打印机正在进行字体替换.
生成时为什么不嵌入字体:
我正在使用SQL Reporting Services 2008创建PDF .SQL Reporting Services存在一个已知问题,即它不会嵌入字体(除非满足一系列要求 - http://technet.microsoft.com/en-us/library /ms159713%28SQL.100%29.aspx).不要问我为什么,PDF符合MS列出的所有要求,并且字体仍然显示为未嵌入 - 没有真正控制字体是否嵌入,所以我已经接受这不起作用并继续前进.Microsoft提供的建议解决方法(http://blogs.msdn.com/b/donovans/archive/2007/07/20/reporting-services-pdf-renderer-faq.aspx "何时将使用Reporting Services进行字体嵌入")是发布处理PDF以手动嵌入字体.
目标 获取已生成的PDF文档,以编程方式"打开"它并嵌入字体,重新保存PDF.
方法 我指向iTextSharp,但大多数示例都是针对Java版本的,我在转换到iTextSharp版本时遇到问题(我找不到任何iTextSharp文档).
我正在撰写这篇文章以了解我需要做的事情:Itext将字体嵌入PDF中.
但是对于我的生活,我似乎无法使用ByteArrayOutputStream对象.它似乎无法找到它.我已经研究过并且研究过但似乎没有人说出它在哪个类或我找到它的位置所以我可以将它包含在using语句中.我甚至破解了开放的Reflector,似乎无法在任何地方找到它.
这是我到目前为止,它编译等等.(结果是我生成的PDF的字节[]).
PdfReader pdf = new PdfReader(result);
BaseFont unicode = BaseFont.CreateFont("Georgia", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
// the next line doesn't work as I need a ByteArrayOutputStream variable to pass in
PdfStamper stamper = new PdfStamper(pdf, MISSINGBYTEARRAYOUTPUTSTREAMVARIABLE);
stamper.AcroFields.SetFieldProperty("test", "textfont", unicode, null);
stamper.Close();
pdf.Close();
Run Code Online (Sandbox Code Playgroud)
那么有人可以帮我使用iTextSharp将字体嵌入PDF或指向正确的方向吗?
我非常乐意使用除iTextSharp之外的任何其他解决方案来完成此目标,但它需要是免费的,并且能够被企业用于内部应用程序(即Affero GPL).
是iTextSharp的 DLL免费使用,并与我的Web应用程序项目,我将出售重新分配?
这是我的代码.它正确地添加了我想要的图片,除了图像使用其原始分辨率外,一切正常,因此如果图像很大,则会裁剪它以适应页面.
有没有办法让图片像缩放功能一样使用拉伸以适应,还能保持宽高比?我必须在那里找到一些东西.:P
这是一张图片来说明问题:

using System;
using System.IO;
using iTextSharp.text;
using iTextSharp.text.pdf;
using System.Drawing;
using System.Collections.Generic;
namespace WinformsPlayground
{
public class PDFWrapper
{
public void CreatePDF(List<System.Drawing.Image> images)
{
if (images.Count >= 1)
{
Document document = new Document(PageSize.LETTER);
try
{
// step 2:
// we create a writer that listens to the document
// and directs a PDF-stream to a file
PdfWriter.GetInstance(document, new FileStream("Chap0101.pdf", FileMode.Create));
// step 3: we open the document
document.Open();
foreach (var image in …Run Code Online (Sandbox Code Playgroud) 我有一个使用iTextSharp库生成PDF的旧项目.添加iTextSharp DLL作为项目的参考.iTextSharp最初是根据LGPL许可证提供的.不久前,许可证已更改为AGPL(版本5.0.0),即复制版本,因此如果您使用它,则必须使用GPL所有代码.
我的问题是我不知道什么时候下载了我的项目中链接的DLL文件.我不知道DLL是否仍在LGPL下,或者它已经在AGPL下.那就意味着我必须把GPL作为我的项目.
当你只有DLL时,有什么方法可以检查iTextSharp的版本是什么?或者它的许可证是什么?
或者有没有我可以下载仍然在LGPL下的旧版iTextSharp的地方所以我肯定我没有通过不使我的项目GPL打破许可证?
我正在尝试使用iTextSharp在PDF文档的每个页面上创建一个页脚,其格式为Page#of#,跟随iText页面和书籍上的教程.虽然我一直在cb.SetFontAndSize(helv,12)上得到一个例外; - 未将对象引用设置为对象.有谁能看到这个问题?代码如下.
谢谢,罗布
public class MyPdfPageEventHelpPageNo : iTextSharp.text.pdf.PdfPageEventHelper
{
protected PdfTemplate total;
protected BaseFont helv;
private bool settingFont = false;
public override void OnOpenDocument(PdfWriter writer, Document document)
{
total = writer.DirectContent.CreateTemplate(100, 100);
total.BoundingBox = new Rectangle(-20, -20, 100, 100);
helv = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.WINANSI, BaseFont.NOT_EMBEDDED);
}
public override void OnEndPage(PdfWriter writer, Document document)
{
PdfContentByte cb = writer.DirectContent;
cb.SaveState();
string text = "Page " + writer.PageNumber + " of ";
float textBase = document.Bottom - 20;
float textSize = 12; …Run Code Online (Sandbox Code Playgroud) 我一直使用iTextSharp生成PDF文档超过一年.不幸的是,随着Adobe Reader X的发布,我的PDF现在会导致"你想保存吗?" 关闭PDF文档时出现的对话框.对于未使用iTextSharp生成的PDF,不会发生这种情况.对于那些整天打开和关闭PDF文档的用户来说,这真的很烦人.我可以设置iTextSharp中的任何属性来防止这种情况发生吗?
如果有帮助,我使用PdfReader从现有PDF文档中读取数据(此原始文档不会导致出现"保存"对话框).然后我使用PdfWriter创建一个新文档,并使用AddTemplate将原始文档的一部分复制到新文档.
itextsharp ×10
c# ×8
pdf ×5
.net ×3
asp.net ×2
adobe-reader ×1
ghostscript ×1
gnu ×1
image ×1
itext ×1
licensing ×1
vb.net ×1