PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Sun Jun 30, 2024 6:20 pm

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: Thu Jul 12, 2012 9:14 am 
Offline

Joined: Thu Jul 12, 2012 9:09 am
Posts: 2
Hello,

I'm using some very basic code to split up a PDF document into multiple documents. For some reason, the resulting documents are saved in grayscale instead of color. Why could that be and how can I make sure it doesn't happen? The color should match the color of the original document, so if that contains color; the results should contain color as well.

Code:
    public Stream[] SplitDocument(Stream fileStream, int[] splitOnPageNumbers)
    {
      PdfDocument inputDocument = PdfReader.Open(fileStream, PdfDocumentOpenMode.Import);

      List<Stream> result = new List<Stream>();
      PdfDocument outputDocument = null;

      for (int page = 0; page < inputDocument.PageCount; page++)
      {
        // when there is no active document; create one
        if (outputDocument == null)
        {
          outputDocument = new PdfDocument();
          outputDocument.Version = inputDocument.Version;
          outputDocument.Info.Title = inputDocument.Info.Title;
          outputDocument.Info.Creator = inputDocument.Info.Creator;
        }

        // add the page and save to stream
        outputDocument.AddPage(inputDocument.Pages[page]);

        // when this page was indicated as a split number; save the document
        // also save by default when it's the last page
        // add 1 to the page number because that's zero based, and the splitOnPageNumbers var is one based
        if (splitOnPageNumbers.Contains(page + 1) || page + 1 == inputDocument.PageCount)
        {
          Stream outputStream = new MemoryStream();
          outputDocument.Save(outputStream, false);       // don't close stream, it will be unusable
          result.Add(outputStream);

          outputDocument = null;                          // reset to null to spawn a new document
        }
      }

      return result.ToArray();
    }


Top
 Profile  
Reply with quote  
PostPosted: Thu Jul 12, 2012 2:43 pm 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3100
Location: Cologne, Germany
Hi!
datamex wrote:
Why could that be and how can I make sure it doesn't happen?
I don't know.
The problem could be related to your PDF file.
It would be good to have the PDF file and a working Visual Studio project to replicate the problem.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Fri Jul 13, 2012 7:41 am 
Offline

Joined: Thu Jul 12, 2012 9:09 am
Posts: 2
Never mind, it's my own mistake. The document is processed by a couple of components actually and it's not PDFSharp causing this problem. Sorry to have bothered you!


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC


Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 99 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Privacy Policy, Data Protection Declaration, Impressum
Powered by phpBB® Forum Software © phpBB Group