[英]C# turn transparency into white for a .pdf document
I have a .pdf document that has transparency in its pages. 我有一个.pdf文件,其页面具有透明性。 I need to remove that transparency and make it white, how can I do that with C#? 我需要删除该透明度并将其设置为白色,如何使用C#做到这一点? I can use pdftron, itextsharp or any other free library. 我可以使用pdftron,itextsharp或任何其他免费库。
Using PDFTrons PDFNet SDK, you can insert a white rectangle as the background to remove the default page transparency as suggested by @mkl. 使用PDFTrons PDFNet SDK,您可以插入白色矩形作为背景,以删除@mkl建议的默认页面透明度。 Below is an example using the ElementBuilder class. 下面是使用ElementBuilder类的示例。 You can look at the ElementBuilder sample code for more information. 您可以查看ElementBuilder示例代码以获取更多信息。
using (PDFDoc doc = new PDFDoc(@"D:\in.pdf"))
using (ElementBuilder eb = new ElementBuilder())
using (ElementWriter writer = new ElementWriter())
{
int pagenum = 1;
writer.Begin(doc.GetPage(pagenum), ElementWriter.WriteMode.e_underlay);
Element e = eb.CreateRect(0, 0, doc.GetPage(pagenum).GetPageWidth(), doc.GetPage(pagenum).GetPageHeight());
e.SetPathFill(true);
e.SetPathStroke(true);
e.SetPathClip(false);
e.GetGState().SetFillColorSpace(ColorSpace.CreateDeviceRGB());
e.GetGState().SetStrokeColorSpace(ColorSpace.CreateDeviceRGB());
e.GetGState().SetStrokeColor(new ColorPt(255, 255, 255)); // white background fill color
e.GetGState().SetFillColor(new ColorPt(255, 255, 255)); // stroke color white as well
writer.WritePlacedElement(e);
writer.End();
doc.Save(@"D:\output.pdf", 0);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.