Giter Site home page Giter Site logo

Comments (3)

Modest-as avatar Modest-as commented on August 26, 2024 2

This is now supported in DocNet 2.0.0

from docnet.

Modest-as avatar Modest-as commented on August 26, 2024

Hey, you can also try reading and generating images one page at a time if you need more fine control how to scale the pages

from docnet.

LokiMidgard avatar LokiMidgard commented on August 26, 2024

That's what I'm currently doing. The problem is I can only specify the absolute result size for every page. Without knowing the original page size I don't know what the result size should be.

My workaround, using reflection to get the scaling and calculate the original size, then create a seccond page:

public static IPageReader GetPageReader(this DocLib library, string tmp, int pageIndex, double resolution)
{
    int widht, height;

    using (var docReader = library.GetDocReader(tmp, 1024, 1024))
    using (var page = docReader.GetPageReader(pageIndex))
    {
        var type = page.GetType();
        var member = type.GetField("_scaling", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
        var scaling = (double)member.GetValue(page);

        var originalHeight = page.GetPageHeight() / scaling;
        var originalWidth = page.GetPageWidth() / scaling;

        widht = (int)(originalWidth * resolution);
        height = (int)(originalHeight * resolution);
    }
    var doc2 = library.GetDocReader(tmp, widht, height);
    var pageReader = doc2.GetPageReader(pageIndex);
    return new PageReader(pageReader, doc2);
}

private class PageReader : IPageReader
{
    private readonly IPageReader pageReader;
    private readonly IDocReader doc2;

    public PageReader(IPageReader pageReader, IDocReader doc2)
    {
        this.pageReader = pageReader;
        this.doc2 = doc2;
    }

    public int PageIndex => this.pageReader.PageIndex;

    public void Dispose()
    {
        this.pageReader.Dispose();
        this.doc2.Dispose();
    }

    public IEnumerable<Character> GetCharacters() => this.pageReader.GetCharacters();

    public byte[] GetImage() => this.pageReader.GetImage();

    public int GetPageHeight() => this.pageReader.GetPageHeight();

    public int GetPageWidth() => this.pageReader.GetPageWidth();

    public string GetText() => this.pageReader.GetText();
}

from docnet.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.