2011-12-08 63 views
3

我正在寻找一种将额外图层添加到PDF文档的方法。该图层应位于现有图层的顶部,并应显示我想要放在其上的文字,有点像水印。目前我们有这样做的方法,但这只是将文本添加到PDF中嵌入的图片上,这不是我想要的。任何人有任何想法,如果有图书馆(免费的会很好),这是什么?以图形方式将图章添加到PDF文档

+0

[使用iTextSharp创建图像时将图像水印添加到PDF中](http://stackoverflow.com/questions/6041718/adding-image-watermark-to-pdf-while-creating-it-using-itextsharp ) –

+0

[在PdfSharp中创建水印](http://pdfsharp.net/wiki/Watermark-sample.ashx)。 –

+0

将尝试,我需要检查PDF上的文本保持文本,并不会被转换为图像。这似乎发生在我尝试过的其他例子上。但是,谢谢!我会告诉你。 – Jasper

回答

2

我们用户MigraDoc,

http://www.pdfsharp.net/MigraDocOverview.ashx?AspxAutoDetectCookieSupport=1

更具体地说,PdfSharp库PdfSharp.dll,

PdfDocument doc = PdfReader.Open(pdf1Point4FileDataStream, PdfDocumentOpenMode.Modify) 

foreach (PdfPage page in doc.Pages) 
{ 
    page.Orientation = PdfSharp.PageOrientation.Portrait; 
    var gfx = XGraphics.FromPdfPage(page, XGraphicsPdfPageOptions.Append, XPageDirection.Downwards); 

    gfx.DrawString(approvalWatermark, approvalFont, watermarkBrush, new XPoint((page.Width - maxWidth + approvalDiff)/2 - space - moveLeft, page.Height/2 - height1 - space), format); 
} 

只是有点从我们的项目采取的代码,因此它是一个有点不完整。看看图书馆和课程,会有一些文档。

-2

PDFKit.NET不是免费的,但你想要做什么是这样的:

using (FileStream fileIn = new FileStream(...)) 
{ 
    Document pdf = new Document(fileIn); 
    Page page = pdf.Pages[0]; 

    TextShape text = new TextShape("some text", Font.Helvetica, 12); 
    text.Transform = new TranslateTransform(x, y); 
    // you can use any kind of transform, scale, rotate, combinations, etc. 
    page.Overlay.Add(text); 

    using (FileStream fileOut = new FileStream(...)) 
    { 
     document.Write(fileOut); 
    } 
} 

声明:我在TallComponents,这个库的供应商合作。