我使用此代码将pdf文件转换为jpg图像,但jpg图像的质量非常差;有人知道如何改变质量或保持PDF格式的质量? 我正在制作具有优质品质的多页pdf。 抱歉我的英语不好。
public void ConvertPDFtoJpg(string filename, string dirOut)
{
string[] archivo = filename.Split('\\');
string final = archivo[3].Replace(".pdf", "");
string archOri = final;
PDFLibNet.PDFWrapper _pdfDoc = new PDFLibNet.PDFWrapper();
_pdfDoc.LoadPDF(filename);
int p = 1;
SqlConnection con1 = new SqlConnection("Data Source=192.168.10.25;User ID=sa;Initial Catalog=BECO");
con1.Open();
for (int s = 0; s < _pdfDoc.PageCount; s++)
{
Image img = RenderPage(_pdfDoc, s);
string rutaFin = final + ".page" + p + ".jpg";
img.Save(Path.Combine(dirOut, string.Format(rutaFin)));
string textoCmd = "INSERT into imagenes (ruta1,valor,estado) VALUES ('" + rutaFin +"', '"+ archOri +"', 0)";
SqlCommand com4 = new SqlCommand(textoCmd, con1);
com4.ExecuteNonQuery();
p++;
}
_pdfDoc.Dispose();
con1.Close();
}
public Image RenderPage(PDFLibNet.PDFWrapper doc, int page)
{
doc.CurrentPage = page + 1;
doc.CurrentX = 0;
doc.CurrentY = 0;
doc.RenderPage(IntPtr.Zero);
// create an image to draw the page into
var buffer = new Bitmap(doc.PageWidth, doc.PageHeight);
doc.ClientBounds = new Rectangle(0, 0, doc.PageWidth, doc.PageHeight);
using (var g = Graphics.FromImage(buffer))
{
var hdc = g.GetHdc();
try
{
doc.DrawPageHDC(hdc);
}
finally
{
g.ReleaseHdc();
}
}
return buffer;
}
答案 0 :(得分:0)
Matias的,
您需要做的是在RenderPage方法中添加一行来指定输出DPI。
例如:
...
doc.CurrentX = 0;
doc.CurrentY = 0;
doc.RenderDPI = 300;
...
在这种情况下,我将其设置为300 DPI,为您提供更多细节。