簡體   English   中英

PDFsharp示例“ ExportImages”刪除水印

[英]PDFsharp example “ExportImages” removes watermark

您好,我正在使用PDFsharp示例將PDF轉換為圖像格式。 但是我的PDF帶有日期戳(水印),並且在圖像文件中丟失了。 有沒有辦法在圖像上蓋章?

代碼( http://www.pdfsharp.net/wiki/ExportImages-sample.ashx

private void GetImageFromPdf(string fileNamePath)
    {
        PdfDocument document = PdfReader.Open(fileNamePath);

        int imageCount = 0;
        // Iterate pages
        foreach (PdfPage page in document.Pages)
        {
            // Get resources dictionary
            PdfDictionary resources = page.Elements.GetDictionary("/Resources");
            if (resources != null)
            {
                // Get external objects dictionary
                PdfDictionary xObjects = resources.Elements.GetDictionary("/XObject");
                if (xObjects != null)
                {
                    ICollection<PdfItem> items = xObjects.Elements.Values;
                    // Iterate references to external objects
                    foreach (PdfItem item in items)
                    {
                        PdfReference reference = item as PdfReference;
                        if (reference != null)
                        {
                            PdfDictionary xObject = reference.Value as PdfDictionary;
                            // Is external object an image?
                            if (xObject != null && xObject.Elements.GetString("/Subtype") == "/Image")
                            {
                                ExportImage(xObject, ref imageCount);
                            }
                        }
                    }
                }
            }
        }
        System.Windows.Forms.
        MessageBox.Show(imageCount + " images exported.", "Export Images");

    }

    static void ExportImage(PdfDictionary image, ref int count)
    {
        string filter = image.Elements.GetName("/Filter");
        switch (filter)
        {
            case "/DCTDecode":
                ExportJpegImage(image, ref count);
                break;

            //case "/FlateDecode":
            //    ExportAsPngImage(image, ref count);
            //    break;
        }
    }

該示例演示如何提取嵌入在PDF文件中的JPEG文件。 渲染PDF頁面的圖像文件。

如果圖像上有文字水印,則您只會得到圖像。

PDFsharp無法呈現PDF文件,因此無法獲取包含水印作為圖形文件的PDF頁面。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM