C# PDFNet pdftron库抛出;算术运算导致“溢出”;在.Net中使用create()时
请尽快提供解决方案,为什么pdftron.PDF.Image.Create(doc,bitmap,JBIG2_hint)会出现异常“算术运算导致溢出”,但另一方面,如果我尝试Create()的另一个重载函数,它会正常工作 我用它把图像转换成PDFC# PDFNet pdftron库抛出;算术运算导致“溢出”;在.Net中使用create()时,c#,.net,bitmap,pdftron,pdfnet,C#,.net,Bitmap,Pdftron,Pdfnet,请尽快提供解决方案,为什么pdftron.PDF.Image.Create(doc,bitmap,JBIG2_hint)会出现异常“算术运算导致溢出”,但另一方面,如果我尝试Create()的另一个重载函数,它会正常工作 我用它把图像转换成PDF 专用PDFDoc ConvertToPDF(System.Drawing.Image SourceImage) { 字符串currentCulture=GetApplicationParameter(“DataCenterCulture”); 如果(
专用PDFDoc ConvertToPDF(System.Drawing.Image SourceImage)
{
字符串currentCulture=GetApplicationParameter(“DataCenterCulture”);
如果(当前文化==“en-US”)
{
初始化(“某些值已正确传递”);
}
其他的
{
初始化(“某些值已正确传递”);
}
string path=GetApplicationParameter(“some_PDF_path”);
bool found=PDFNet.SetResourcesPath(路径);
PDFDoc doc=新的PDFDoc();
ElementBuilder f=new ElementBuilder();//用于构建新元素对象
ElementWriter writer=new ElementWriter();//用于将元素写入页面
元素=null;
//使用JBIG2编码
ObjSet hint_set=new ObjSet();
pdftron.SDF.Obj JBIG2_hint=hint_set.CreateArray();
JBIG2_hint.PushBack(hint_set.CreateName(“g4”));
尝试
{
对于(int i=0;i
此问题已在PDFNet的最新版本中修复
您可以从以下位置获取最新的官方.Net版本
private PDFDoc ConvertToPDF(System.Drawing.Image SourceImage)
{
string currentCulture = GetApplicationParameter("DataCenterCulture");
if (currentCulture == "en-US")
{
PDFNet.Initialize("some value already passed correctly");
}
else
{
PDFNet.Initialize("some value already passed correctly");
}
string path = GetApplicationParameter("some_PDF_Path");
bool found = PDFNet.SetResourcesPath(path);
PDFDoc doc = new PDFDoc();
ElementBuilder f = new ElementBuilder(); // Used to build new Element objects
ElementWriter writer = new ElementWriter(); // Used to write Elements to the page
Element element = null;
// Use JBIG2 Encoding
ObjSet hint_set = new ObjSet();
pdftron.SDF.Obj JBIG2_hint = hint_set.CreateArray();
JBIG2_hint.PushBack(hint_set.CreateName("g4"));
try
{
for (int i = 0; i < GetPageCount(SourceImage); i++)
{
SourceImage.SelectActiveFrame(FrameDimension.Page, i);
MemoryStream ms = new MemoryStream();
SourceImage.Save(ms, ImageFormat.Tiff);
ms.Seek(0, 0);
System.Drawing.Bitmap bitmap = new Bitmap(ms);
bitmap.SetResolution(200f, 200f);
Page page = doc.PageCreate(); // Start a new page
writer.Begin(page); // Begin writing to this page
// ColorSpace cs = ColorSpace.CreateDeviceRGB(); //Alternatively using this line, but not required.
//System.Drawing.Image img = (System.Drawing.Image)bitmap; //Working Fine, but No need of this line just verifying whether it gives error or not.
//byte[] bt = ms.ToArray();// Working Fine, but No need of //this line just verifying whether it gives error or not.
//pdftron.PDF.Image image = pdftron.PDF.Image.Create(doc, ms.ToArray(), 200, 200, 100, cs); // This line works fine, but we don’t need to use this.
// pdftron.PDF.Image image = pdftron.PDF.Image.Create(doc, "E:\\SomeTestImage.jpg", JBIG2_hint); // This line also works fine, but we don’t need to use this.
pdftron.PDF.Image image = pdftron.PDF.Image.Create(doc, bitmap, JBIG2_hint); // I need this line as its our requirement, but this line gives error “Arithmetic operation resulted in an overflow” and need solution for this why it gives error.
element = f.CreateImage(image, new Matrix2D(page.GetPageWidth(), 0, 0, page.GetPageHeight(), 0, 0));
writer.WriteElement(element);
writer.End();
doc.PagePushBack(page);
}
}
catch (ArithmeticException aex)
{
}
catch (PDFNetException pex)
{
//Why Arithmetic operation resulted in an overflow occurs and catch in this PDFNetException , and not in Arithmetic Exception, this is also my query.
}
catch (Exception ex)
{
}
return doc;
}