是否有可能使用PdfSharp从PDF文件中提取纯文本?由于其许可证,我不想使用iTextSharp.
我想通过Save方法将PdfSharp.Pdf.PdfDocument保存到Stream,但它不会将PDF标头设置附加到它.因此,当我回读Stream并将其返回给用户时,他看到PDF文件无效.当PDFsharp保存到内存时,是否有附加PDF标头设置的解决方案?
这似乎很简单,但我在API中找不到类似getPageCount()的东西.我可以让它返回当前页面,但不是总页数.也许我想念它?
我想以某种方式能够在每页的顶部打印"第1页,共9页",其中"1"当然是当前的页码.
我试图获得新的行,但如果我使用\n它没有任何方式通过添加字符串像\r\n(不起作用)有新的行
gfx.DrawString("Project No \n" + textBoxProjNumber.Text, fontUnder, XBrushes.Black, 230, 95);
Run Code Online (Sandbox Code Playgroud)
不起作用.
我是C#.net的新手,我下载了PDFsharp lib.但是如何将这个lib添加到我们的项目中呢?
我的项目是创建一个PDF文件.请给我一步一步的说明.解压后它有32个文件夹.
我尝试在我的项目文件夹中处理它,但同样的错误来了.
" 无法找到类型或命名空间名称'PdfSharp'(您是否缺少using指令或程序集引用?)"
如何使用PDFsharp .NET库将PDF页面导出为图像,用于像素级操作?
例如,System.Drawing.BitMap.GetPixel()之类的东西
我试图在PDF文档中找出空白区域(全白或任何颜色),以编写一些图形/图像.
2010年6月9日:
我试过这个,但它没有用.
为什么以下代码没有按预期工作?
Bitmap.GetPixel始终返回0.
//
// PdfSharp.Pdf.PdfDocument
// PdfSharp.Pdf.PdfPage
// PdfSharp.Drawing.XGraphics
// System.Drawing.Bitmap
//
string srcPDF = @"C:\hcr\test\tmp\file1.pdf";
PdfDocument pdfd = PdfReader.Open(srcPDF);
XGraphics xgfx = XGraphics.FromPdfPage(pdfd.Pages[0]);
Bitmap b = new Bitmap((int) pdfp.Width.Point, (int) pdfp.Height.Point, xgfx.Graphics);
int rgb = b.GetPixel(0, 0).ToArgb();
Run Code Online (Sandbox Code Playgroud) 我想在预制的PDF文档中填写表单字段,但是在运行时我收到了AcroForm的Null Refrence错误.
string fileN4 = TextBox1.Text + " LOG.pdf";
File.Copy(Path.Combine(textBox4.Text + "\\", fileN4),
Path.Combine(Directory.GetCurrentDirectory(), fileN4), true);
// Open the file
PdfDocument document = PdfReader.Open(fileN4, PdfDocumentOpenMode.Modify);
PdfTextField currentField = (PdfTextField)(document.AcroForm.Fields["<CASENUM>"]);
//const
string caseName = TextBox1.Text;
PdfString caseNamePdfStr = new PdfString(caseName);
//set the value of this field
currentField.Value = caseNamePdfStr;
// Save the document...
document.Save(fileN4);
Run Code Online (Sandbox Code Playgroud)
PdfTextField currentField = (PdfTextField)(document.AcroForm.Fields["<CASENUM>"]);错误发生的地方也是如此 .它接缝表明AcroForm甚至没有认识到这些领域.
另一种选择是在PDF中查找和替换文本(不使用由于许可而无法使用的itextsharp).
任何帮助都是极好的!
在MigraDoc中,如果我有一个段落,我怎么才能在段落中加粗一些文字,而不是整个段落.
编辑:下面是我用来添加粗体段落的典型代码.
var paragraph = section.AddParagraph("This text");
paragraph.Format.Font.Bold = true;
Run Code Online (Sandbox Code Playgroud)
我不能只添加拆分文本的单独段落,因为MigraDoc在段落之间放置了空格.
环境 - PDFsharp Library,Visual Studio 2012和C#作为语言.
我在尝试着:
我可以做以下所有事情.但是当我打开文件Test2.pdf时,页面的大小会减小到宽度= 11英寸,高度--11英寸.我使用的这些PDF文件是我从互联网上下载的产品规格表.我相信这只发生在某些类型的文件上,我不知道如何区分这些文件.
代码如下:
//File dimentions - Width = 17 inches, Height - 11 inches (Tabloid Format)
PdfDocument pdfDocument = PdfReader.Open(@"D:\Test1.pdf", PdfDocumentOpenMode.Modify);
PdfPage page = pdfDocument.Pages[0];
XGraphics gfx = XGraphics.FromPdfPage(page);
XFont font = new XFont("Verdana", 20, XFontStyle.BoldItalic);
gfx.DrawString("Hello, World!", font, XBrushes.Black, new XRect(0, 0, page.Width, page.Height), XStringFormats.Center);
//When the file is saved dimentions change to - Width = 11 inches, Height - 11 inches
pdfDocument.Save(@"D:\Test2.pdf");
Run Code Online (Sandbox Code Playgroud)
我在这里上传了文件Test1.pdf
================================================== …
PDFSharp库是否可以像iTextSharp一样生成PDF文件*考虑HTML格式*?(粗体(强),间距(br)等)
以前我使用iTextSharp并以这种方式粗略处理(下面的代码):
string encodingMetaTag = "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />";
string htmlCode = "text <div> <b> bold </ b> or <u> underlined </ u> <div/>";
var sr = new StringReader (encodingMetaTag + htmlCode);
var pdfDoc = new Document (PageSize.A4, 10f, 10f, 10f, 0f);
var = new HTMLWorker htmlparser (pdfDoc);
PdfWriter.GetInstance (pdfDoc, HttpContext.Current.Response.OutputStream);
pdfDoc.Open ();
htmlparser.Parse (sr);
pdfDoc.Close ();
Run Code Online (Sandbox Code Playgroud)
将适当的HTML表单合并到处理类对象HTMLWorker的PDF文档中..那么用PDFSharp做什么?有PDFSharp类似的解决方案吗?