我想更改HTML上的某些内容并在C#上动态更改它。我看过该文档并阅读了https://itextpdf.com/en/resources/books/itext-7-converting-html-pdf-pdfhtml/chapter-5-custom-tag-workers-and-css-appliers,但是由于我不熟悉编程并且对JAVA知识为0,所以无法解决。知道如何在C#中执行此操作吗?
这是iText文档中的代码:
String[] names = {"Bruno Lowagie", "Ingeborg Willaert", "John Doe"};
int counter = 1;
for (String name : names) {
app.createPdf(name, SRC, String.format(DEST, counter++));
}
public void createPdf(String name, String src, String dest) throws IOException {
SimpleDateFormat sdf = new SimpleDateFormat("MMMM d, yyyy", Locale.ENGLISH);
ConverterProperties converterProperties = new ConverterProperties();
converterProperties.setTagWorkerFactory(
new DefaultTagWorkerFactory() {
@Override
public ITagWorker getCustomTagWorker(
IElementNode tag, ProcessorContext context) {
if ("name".equalsIgnoreCase(tag.name()) ) {
return new SpanTagWorker(tag, context) {
@Override
public boolean processContent(
String content, ProcessorContext context) {
return super.processContent(name, context);
}
};
}
else if ("date".equalsIgnoreCase(tag.name()) ) {
return new SpanTagWorker(tag, context) {
@Override
public boolean processContent(
String content, ProcessorContext context) {
return super.processContent(
sdf.format(new Date()), context);
}
};
}
return null;
}
} );
HtmlConverter.convertToPdf(new File(src), new File(dest), converterProperties);
}