Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/22.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# PDFNet pdftron库抛出;算术运算导致“溢出”;在.Net中使用create()时_C#_.net_Bitmap_Pdftron_Pdfnet - Fatal编程技术网

C# PDFNet pdftron库抛出;算术运算导致“溢出”;在.Net中使用create()时

C# 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”); 如果(

请尽快提供解决方案,为什么pdftron.PDF.Image.Create(doc,bitmap,JBIG2_hint)会出现异常“算术运算导致溢出”,但另一方面,如果我尝试Create()的另一个重载函数,它会正常工作

我用它把图像转换成PDF


专用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版本


任何图像源都会出现这种情况吗?还是只有某些人?最后,您使用的是什么版本的PDFNet?您可以在运行时调用PDFNet.GetVersion这会发生在所有图像上,我们已经以字节[]数组格式保存在SQL数据库中。图像没有损坏,通过不同的算法在其他地方可以正常工作。但我们只在这个特定场景中出现错误。如果出现错误,则PDFNET的其他重载Create()函数也将无法工作。当我们在Create()中使用“BitMap”作为参数时,会出现问题函数。由于我们对位图使用SetResolution,因此我们只能使用这一行。注释中会解释哪一行代码工作正常,哪一行代码没有。我们使用的是PDFNet的6.01版本。但早期版本的PDFNet库工作正常,但在过去的几个月里它工作不正常。我想知道您是否确认,当在Create()函数中传递位图作为参数时,PDFNet库的6.01版本中会抛出错误。但早期版本的PDFNet库工作正常,但在过去几个月内,它工作不正常。我想知道您是否确认,当位图作为参数传入Create()函数时,在6.01版本的PDFNet库中抛出错误。
    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;
 }