I am using PDF focus library and I have a issue.
some PDF file can not convert to image.
I convert all pages of PDF file but that miss some page.
Please help to solve this issue.
I use code as below to convert 1st page of pdf file :
Code: Select all
OpenFileDialog Chonfile = new OpenFileDialog();
Chonfile.Filter = "All Files (*.pdf)|*.pdf";
Chonfile.FilterIndex = 1;
Chonfile.Multiselect = false;
progressBar_upload.Value = 0;
// Chonfile.Multiselect = false;
if (Chonfile.ShowDialog() == DialogResult.OK)
{
int i = 0;
string newpath = @"C:\Users\Dong.Pham\Desktop\";
foreach (string filename in Chonfile.FileNames)
{
//string Npath = newpath + Txt_DocNo.Text + "_" + Txt_extension.Text + "_" + i + ".png";
string Npath = newpath + Txt_DocNo.Text + "_" + Txt_extension.Text + ".png";
SautinSoft.PdfFocus f = new SautinSoft.PdfFocus();
f.Serial = "XXXXXXX"; // I have liscience
f.OpenPdf(filename);
if (f.PageCount > 0)
{
//Set 200 dpi and png format
f.ImageOptions.Dpi = 200;
// f.ImageOptions.Resize();
f.ImageOptions.ImageFormat = System.Drawing.Imaging.ImageFormat.Png;
// int width = 1585; // Width in Px
// int height = 850; // Height in Px
// f.ImageOptions.Resize(new Size { Width = width, Height = height }, false);
f.ImageOptions.Resize(0.5f, 0.5f);
progressBar_upload.Value = 50;
f.ToImage(Npath, 1);
f.ClosePdf();
/*
for (int page = 1; page <= f.PageCount; page++)
{
f.ToImage(Npath, page);
}
*/
progressBar_upload.Value = 100;
}
}
}
Code: Select all
foreach (string filename in Chonfile.FileNames)
{
//
// string newpath = pathdes+ "\\" + Txt_DocNo.Text + "_" + i + ".png";
// i++;
// File.Copy(filename, newpath, true);
///////////////////////////////////////////////
///use sautisoft pdf
string newpath = "";
SautinSoft.PdfFocus f = new SautinSoft.PdfFocus();
f.Serial = "XXXXXXXX";
f.OpenPdf(filename);
if (f.PageCount > 0)
{
//Set 200 dpi and png format
int count_page = f.PageCount;
f.ImageOptions.Dpi = 200;
f.ImageOptions.ImageFormat = System.Drawing.Imaging.ImageFormat.Png;
progressBar_upload.Step = 100 / f.PageCount;
for (int page = 1; page <= f.PageCount; page++)
{
if(page == f.PageCount)
{
progressBar_upload.Value = 100;
}
else
{
progressBar_upload.Value = progressBar_upload.Step * page;
}
newpath = pathdes + "\\" + Txt_DocNo.Text + "_" + i + ".png";
f.ToImage(newpath, page);
i++;
}
}
}