2011-12-08 62 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,這個庫的供應商合作。