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;
}
}