2015-09-26 104 views
0

您好我正在使用PDFsharp示例將PDF轉換爲圖像格式。但是我的PDF獲得了一個日期戳(水印),這在圖像文件中會丟失。有沒有辦法在圖像上貼上郵票?PDFsharp示例「ExportImages」移除水印

代碼(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; 
     } 
    } 

回答

0

此示例說明如何提取嵌入在PDF文件的JPEG文件。它確實而不是將PDF頁面呈現爲圖像文件。

如果有一個文字水印覆蓋圖像,那麼你只會得到圖像。

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