Skip to content

Split PDF #423

Answered by zlangner
topcat30 asked this question in Q&A
Feb 22, 2022 · 2 comments · 1 reply
Discussion options

You must be logged in to vote

Yes. I'm not sure what exactly you mean so I'm going to assume you have a known page range that you want to extract from a provided pdf stream.

using System.Collections.Generic;
using System.IO;
using UglyToad.PdfPig;
using UglyToad.PdfPig.Writer;

namespace MySplitter
{
    public static class PdfPigExtensions
    {
        public static MemoryStream ExtractPages(Stream inputStream, int firstPage, int lastPage)
        {
            var ms = new MemoryStream();
            using (var destDoc = new PdfDocumentBuilder(ms, disposeStream: false))
            using (var srcDoc = PdfDocument.Open(inputStream))
            {
                int numPages = srcDoc.NumberOfPages;


               …

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
1 reply
@topcat30
Comment options

Answer selected by topcat30
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants