我正在尝试下面的代码,但未得到结果,这会干扰现有功能,因此请与我分享相同的指导原则。
// Generate PDF file name with full path
string lsPDFFileFullPath = fsFileDestination + fsDestinationFileName;
ConverterProperties loproperties = new ConverterProperties();
loproperties.SetFontProvider(new DefaultFontProvider(true, true, true));
MediaDeviceDescription mediaDeviceDescription = new MediaDeviceDescription(MediaType.SCREEN);
loproperties.SetMediaDeviceDescription(mediaDeviceDescription);
// Set BaseUri for access css and images for PDF.
loproperties.SetBaseUri(fsWebRootPath);
if (!System.IO.Directory.Exists(fsFileDestination))
{
System.IO.Directory.CreateDirectory(fsFileDestination);
}
var loElements = HtmlConverter.ConvertToElements(fsSourceHTML, loproperties);
PdfDocument loPDFDoc = new PdfDocument(new PdfWriter(lsPDFFileFullPath));
loPDFDoc.SetTagged();
Document loDocument = new Document(loPDFDoc);
loDocument.SetMargins(20, 20, 20, 20);
foreach (var loElement in loElements)
{
loDocument.Add((IBlockElement)loElement);
}
loDocument.Close();