简体   繁体   中英

TallComponents PDF Rasterizer.NET convertToWPF memory error

I am trying to rasterize pdf's using TallComponents PDF Rasterizer

It works fine going to tiff.. Although I wanted to ConvertToWpf..

I asked this question to them directly although no response..

so, I followed their example code..

        TallComponents.PDF.Rasterizer.Document _document;
        using (FileStream file = new FileStream(pSource, FileMode.Open, FileAccess.Read))
        {
            _document = new TallComponents.PDF.Rasterizer.Document(file);
        }

        TallComponents.PDF.Rasterizer.Configuration.RenderSettings rSettings = new TallComponents.PDF.Rasterizer.Configuration.RenderSettings();
        rSettings.TextSettings.ResolveFont += new TallComponents.PDF.Rasterizer.Fonts.ResolveFontEventHandler(TextSettings_ResolveFont);

        TallComponents.PDF.Rasterizer.ConvertToWpfOptions rOptions = new TallComponents.PDF.Rasterizer.ConvertToWpfOptions();
        TallComponents.PDF.Rasterizer.Diagnostics.Summary summary = new TallComponents.PDF.Rasterizer.Diagnostics.Summary();

        int count = _document.Pages.Count;
        for (int i = 0; i < count; i++)
        {

        using (FileStream outStream = new FileStream(path, FileMode.Create)) 
        { 
             System.Windows.Documents.FixedPage fpage = _document.Pages[i].ConvertToWpf(rSettings, rOptions, summary); 

             double width = fpage.Width * rasterize.rast_dpiX / system.scr_dpiX; 
             double height = fpage.Height * rasterize.rast_dpiY / system.scr_dpiY; 

             RenderTargetBitmap renderTarget = new RenderTargetBitmap( 
             (int)width, 
             (int)height, 
             rasterize.rast_dpiX, 
             rasterize.rast_dpiY, 
             System.Windows.Media.PixelFormats.Default); 

             renderTarget.Render(fpage); 

             PngBitmapEncoder enc = new PngBitmapEncoder(); 
             enc.Frames.Add(BitmapFrame.Create(renderTarget)); 
             enc.Save(outStream); 

        } 

It works when I use a pdf that has only 1 page..

When I use a pdf with more then 1 page, I get insufficient memory errors..

When I use a pdf with more then 1 page and start at page 2, and skip the first page it works.. Although all the pages come up blank, saying I can only rasterize the first page because its a trial..

Am I getting the memory error because its a trial product?

Most probably you have an image (or another huge PDF object) on a first page, after processing of which you have got an exception. This exception breaks the further rendering and you have a blank 2,3,4... pages.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM