Product:
WebViewer
Product Version:
WebViewer Api
Please give a brief summary of your issue:
Cant delete or merge the converted files after converting using PDFDoc in C#.
Please describe your issue and provide steps to reproduce it:
Calling the PDFDocApi to convert
Please provide a link to a minimal sample where the issue is reproducible:
public ConversionResult ConvertAnyToPDF(OutputFileNameAndPathExtractor OFOP, string? stamp)
{
ConversionResult cr = new ConversionResult();
try
{
//this method throws exceptions which are to be caught by whichever code uses it.
using (PDFDoc pdfdoc = new PDFDoc())
{
pdfdoc.InitSecurityHandler();
string extensionOfDocument = OFOP.input_fileExtension.ToLower();
if (convertibles.Contains(extensionOfDocument))
{
DocumentConversion documentConversion = pdftron.PDF.Convert.StreamingPDFConversion(pdfdoc,
OFOP.input_path + OFOP.input_filenameWithExtension,
null
);
documentConversion.Convert();
//if the incoming document has a stamp request
if (!String.IsNullOrEmpty(stamp))
{
addStamp(pdfdoc, stamp, null);
}
// save the result
pdfdoc.Save(OFOP.output_path + OFOP.output_filename, SDFDoc.SaveOptions.e_linearized);
cr.conversionSuccessStatus = true;
cr.convertedFilePath = OFOP.output_path + OFOP.output_filename;
}
else if (html_convertibles.Contains(OFOP.input_fileExtension))
{
// Running on IIS express the current working directory was inside C:/ProgramFiles/IISExpress, had to jump out to directory to get to tfs
HTML2PDF.SetModulePath("../../tfs12/ImageRetrievalService/Application/CR73830bwm1-pdftron/DocConverterPdfTron/Lib/");
HTML2PDF converter = new HTML2PDF();
string htmlContent = File.ReadAllText(OFOP.input_path + OFOP.input_filenameWithExtension);
converter.InsertFromHtmlString(htmlContent);
if (converter.Convert(pdfdoc))
{
pdfdoc.Save(OFOP.output_path + OFOP.output_filename, SDFDoc.SaveOptions.e_linearized);
cr.conversionSuccessStatus = true;
cr.convertedFilePath = OFOP.output_path + OFOP.output_filename;
//return cr;
}
else
{
throw new ConvertingException();
}
}
else
{
//throw exception for document type not supported instead
throw new ConvertingException();
}
pdfdoc.Close();
pdfdoc.Dispose();
return cr;
}
}
catch (Exception ex)
{
throw new ConvertingException(ex.Message);
}
}
public void addStamp(PDFDoc pdfdoc, string stamp, int? pageNumber)
{
int defaultPageSetValue = 1;
if(pageNumber is not null)
{
defaultPageSetValue = (int)pageNumber;
}
try
{
using (Stamper s = new Stamper(Stamper.SizeType.e_absolute_size, 0.10, 0.10))
{
//get alignment from appsettings later
pdfdoc.InitSecurityHandler();
s.SetAlignment(Stamper.HorizontalAlignment.e_horizontal_center, Stamper.VerticalAlignment.e_vertical_bottom);
//get color from appsettings later
s.SetFontColor(new ColorPt(0, 0, 0)); // set text color to black
s.StampText(pdfdoc, stamp, new PageSet(defaultPageSetValue));
}
pdfdoc.Unlock();
}
catch(Exception ex)
{
throw new StampingException("Error occured during stamping. ", ex);
}
}
public PdftronServiceImplementation(IConfiguration configuration)
{
_configuration = configuration;
PDFNet.Initialize(_configuration.GetValue(“Secrets:PDFTRON_KEY”) ?? throw new NullReferenceException(“Appsettings Secrets:PDFTRON_KEY could not be found”));
}