Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/qt/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 带有itextsharp的Jpeg到pdf在顶部和底部剪切_C#_.net_Pdf_Itextsharp_Twain - Fatal编程技术网

C# 带有itextsharp的Jpeg到pdf在顶部和底部剪切

C# 带有itextsharp的Jpeg到pdf在顶部和底部剪切,c#,.net,pdf,itextsharp,twain,C#,.net,Pdf,Itextsharp,Twain,我使用iTextSharp程序集将jpg转换为pdf 我的jpg由twain A4扫描。 jpg很好 我将png转换为pdf格式,如下所示: Document doc = new Document(); PdfWriter.GetInstance(doc, new System.IO.FileStream(this._fileName, System.IO.FileMode.Create)); doc.Open(); iTextSharp.text.Image img = iTextSharp.

我使用iTextSharp程序集将jpg转换为pdf

我的jpg由twain A4扫描。 jpg很好

我将png转换为pdf格式,如下所示:

Document doc = new Document();
PdfWriter.GetInstance(doc, new System.IO.FileStream(this._fileName, System.IO.FileMode.Create));
doc.Open();
iTextSharp.text.Image img = iTextSharp.text.Image.GetInstance(Scanners.Twain.GetImage(i), System.Drawing.Imaging.ImageFormat.Jpeg);  
doc.SetPageSize(new iTextSharp.text.Rectangle(0, 0, img.Width, img.Height));
doc.NewPage();
doc.Add(img);
doc.Close(); 
我的问题是pdf文件的顶部和底部都被切掉了。 为什么?

我怎样才能避免这种情况

非常感谢


Seuxin

除非您另有规定,否则文档的所有边都有36的边距。您可以通过以下方式删除它们:

doc.SetMargins(0, 0, 0, 0);

你可以按照克里斯·哈斯的建议去做,但你可以使用这是一个替代方案:

img.SetAbsolutePosition(0, 0);
这样,img就不考虑文档的边距,而是将其添加到页面的左下角