Giter VIP home page Giter VIP logo

Comments (1)

ceztko avatar ceztko commented on June 12, 2024

Hello, I'm not sure I can fully answer all your questions but I will try. First I don't know what "built-in support for OCG" could be in PoDoFo: with PoDoFo you can parse the content stream for a page (or an XObject) and knowing enough PDF specification you can identify and separate the content you are looking for. An example of such parsing can be found here.

Secondly, you can definitely edit the [content stream of a] PDF [page] in situ, I am not sure why you had the feeling this is not possible. Manipulate the contents stream of a page is an explicitly supported use case, and with most recent code in master you can do it abstractly for a PdfCanvas (that is either a page or an XObject) like this:

PdfMemDocument doc;
doc.Load(R"(D:\Test\test.pdf)");
auto& page = doc.GetPages().GetPageAt(0);
auto& canvas = static_cast<PdfCanvas&>(page);

PdfObject tempObj;
auto& newContents = tempObj.GetOrCreateStream();
{
    auto outputStream = stream.GetOutputStream();

    // Parse the contents of the page and rewrite it to "outputStream"
    // ...
}
// Finally set the new stream on the canvas. Output stream must
// be closed before this operation
canvas.ResetContentsStream() = std::move(newContents);

// Save the document
doc.Save(R"(D:\Test\test.pdf)");

You can do both parsing of the original contents stream and serializing operators in a streamline operation, with a method like this:

void SerializeTo(OutputStream& stream, const PdfVariantStack& stack, PdfOperator op, string& buffer)
{
    for (auto it = stack.rbegin(); it != stack.rend(); it++)
    {
        it->ToString(buffer);
        stream.Write(buffer);
        stream.Write(" ");
    }

    stream.Write(PoDoFo::GetPdfOperatorName(op));
    stream.Write("\n");
}

It's also possible to do with 0.10.x API but the method to replace the contents stream is not abstract and you'll have to code it specifically for page and XObject.

from podofo.

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.