PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Mon Jun 17, 2024 1:47 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
 Post subject: MigraDoc shading colour
PostPosted: Mon Feb 29, 2016 10:02 am 
Offline

Joined: Thu Jun 11, 2015 10:19 am
Posts: 4
I have a large program that produces customer paperwork. The forms are laid out as cells with heading strips that are shaded in. The headings are meant to be green but I often find they come out a blue-green colour, or even blue, depending on which printer you use - this is a problem for us.

Here is a minimum working example. My program creates a green square as a bitmap image and saves it to a file. It then creates a MigraDoc PDF, shades a cell in the same colour, and adds the image.

Code:
using MigraDoc.DocumentObjectModel;
using MigraDoc.Rendering;
using MigraDoc.DocumentObjectModel.Tables;
using System.Drawing;

namespace PDFPlay
{
    static class Program
    {
        static void Main()
        {
            //create image file
            Bitmap bitmap = new Bitmap(114, 114);
            Graphics g = Graphics.FromImage(bitmap);
            Brush brush = new SolidBrush(System.Drawing.Color.FromArgb(0, 176, 80));
            g.FillRectangle(brush, new Rectangle(0, 0, 114, 114));
            bitmap.Save(@"C:\Temp\greensquare.png");

            Document document = new Document();
            Section section = document.AddSection();

            //add shaded square
            Table mainTable = section.AddTable();
            mainTable.AddColumn("3cm");
            mainTable.AddRow().Height = "3cm";
            mainTable.Rows[0].Cells[0].Shading.Color = new MigraDoc.DocumentObjectModel.Color(0, 176, 80);
            mainTable.AddRow();

            //add image
            section.AddImage(@"C:\Temp\greensquare.png");

            //render and save PDF
            document.UseCmykColor = true;
            PdfDocumentRenderer pdfRenderer = new PdfDocumentRenderer(false);
            pdfRenderer.Document = document;
            pdfRenderer.RenderDocument();
            pdfRenderer.PdfDocument.Save("C:\\Temp\\pdftest.pdf");
        }
    }
}


The result is below. You can see that the MigraDoc shading is a much darker green than the image. How can I control the colour of the shading so that it is the same as the image?

Attachment:
pdfcolourproblem.PNG
pdfcolourproblem.PNG [ 1.29 KiB | Viewed 5141 times ]


Top
 Profile  
Reply with quote  
PostPosted: Mon Feb 29, 2016 10:12 am 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3100
Location: Cologne, Germany
Hi!

Either try "document.UseCmykColor = false;".
Or specify the shading color in CMYK format to prevent automatic conversion.

You force PDFsharp to write CMYK color values to the PDF file, but you specify an RGB color - thus you rely on the color conversion built into PDFsharp.
The green in the image will be converted by the viewing tool (usually Adobe Reader) and may look different.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Mon Feb 29, 2016 11:14 am 
Offline

Joined: Thu Jun 11, 2015 10:19 am
Posts: 4
Thomas Hoevel wrote:
try "document.UseCmykColor = false;".


That did it! Thanks very much Thomas :D.


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: No registered users and 158 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:  
Privacy Policy, Data Protection Declaration, Impressum
Powered by phpBB® Forum Software © phpBB Group