Thanks for replying.
It’s just a simple code that was supposed to show layers to be selected if there is any or convert directly if there isn’t but it always getting no layers as I’ve commented on the case.
[HttpPost]
public ActionResult ExportPdfFile(HttpPostedFileBase fileUpload)
{
if (fileUpload != null && fileUpload.ContentLength > 0)
{
var model = new Models.ExportPdfFile();
Document document = new Document(fileUpload.InputStream);
if (document.Pages != null && document.Pages.Count > 0)
{
string newFileNamePng = $"{Path.GetFileNameWithoutExtension(fileUpload.FileName)}.png";
if (document.Pages[1].Layers != null && document.Pages[1].Layers.Count > 0)
{
Dictionary<string, string> layers = new Dictionary<string, string>();
model.Layers = document.Pages[1].Layers.ToDictionary(x => x.Id, y => y.Name);
}
else
{
model.FilesExported.Add(newFileNamePng, ExportToPNG(document.Pages[1], newFileNamePng));
}
}
return View(model);
}
else
return View("Index");
}
public string ExportToPNG(Page page, string outputName)
{
string fileName = Path.Combine(GetCurrentFolder(), outputName);
using (FileStream imageStream = new FileStream(fileName, FileMode.Create))
{
// Create PNG device with specified attributes
// Width, Height, Resolution, Quality
// Quality [0-100], 100 is Maximum
// Create Resolution object
Resolution resolution = new Resolution(300);
PngDevice pngDevice = new PngDevice(resolution);
// Convert a particular page and save the image to stream
pngDevice.Process(page, imageStream);
// Close stream
imageStream.Close();
}
return $"/{PngFolder}/{outputName}";
}