|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
这是在网上找的一个.net的代码,哪位大师能把他转换为VBA的代码吗?谢谢!
// Run the sample:
// cd ExtractTextTableInfoWithFiguresTablesRenditionsFromPDF/
// dotnet run ExtractTextTableInfoWithFiguresTablesRenditionsFromPDF.csproj
namespace ExtractTextTableInfoWithFiguresTablesRenditionsFromPDF
{
class Program
{
private static readonly ILog log = LogManager.GetLogger(typeof(Program));
static void Main()
{
// Configure the logging.
ConfigureLogging();
try
{
// Initial setup, create credentials instance.
Credentials credentials = Credentials.ServiceAccountCredentialsBuilder()
.FromFile(Directory.GetCurrentDirectory() + "/pdfservices-api-credentials.json")
.Build();
// Create an ExecutionContext using credentials and create a new operation instance.
ExecutionContext executionContext = ExecutionContext.Create(credentials);
ExtractPDFOperation extractPdfOperation = ExtractPDFOperation.CreateNew();
// Set operation input from a source file.
FileRef sourceFileRef = FileRef.CreateFromLocalFile(@"extractPDFInput.pdf");
extractPdfOperation.SetInputFile(sourceFileRef);
// Build ExtractPDF options and set them into the operation.
ExtractPDFOptions extractPdfOptions = ExtractPDFOptions.ExtractPDFOptionsBuilder()
.AddElementsToExtract(new List<ExtractElementType>(new []{ ExtractElementType.TEXT, ExtractElementType.TABLES}))
.AddElementsToExtractRenditions(new List<ExtractRenditionsElementType> (new []{ExtractRenditionsElementType.FIGURES, ExtractRenditionsElementType.TABLES}))
.Build();
extractPdfOperation.SetOptions(extractPdfOptions);
// Execute the operation.
FileRef result = extractPdfOperation.Execute(executionContext);
// Save the result to the specified location.
result.SaveAs(Directory.GetCurrentDirectory() + "/output/ExtractTextTableInfoWithFiguresTablesRenditionsFromPDF.zip");
}
catch (ServiceUsageException ex)
{
log.Error("Exception encountered while executing operation", ex);
}
catch (ServiceApiException ex)
{
log.Error("Exception encountered while executing operation", ex);
}
catch (SDKException ex)
{
log.Error("Exception encountered while executing operation", ex);
}
catch (IOException ex)
{
log.Error("Exception encountered while executing operation", ex);
}
catch (Exception ex)
{
log.Error("Exception encountered while executing operation", ex);
}
}
static void ConfigureLogging()
{
ILoggerRepository logRepository = LogManager.GetRepository(Assembly.GetEntryAssembly());
XmlConfigurator.Configure(logRepository, new FileInfo("log4net.config"));
}
}
}
|
|