PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Fri May 26, 2017 10:39 pm

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 7 posts ] 
Author Message
PostPosted: Wed May 03, 2017 11:48 pm 
Offline

Joined: Wed May 03, 2017 11:25 pm
Posts: 4
Hi!
I'm trying to apply cmyk color to a font or to a paragraph but when I render the pdf all the colors in grayscale are converted in mixed colors.
I'm using that:
style.ParagraphFormat.Shading.Color = Color.FromCmyk(0, 0, 0, 25)
style.Font.Color = Color.FromCmyk(0, 0, 0, 25)

the result of that when I open the pdf with any image editor is solmething like:
c: 64 m: 34 y: 2 k: 0 <-- mixed colors

by other side if I try to do it in pure black :
style.ParagraphFormat.Shading.Color = Color.FromCmyk(0, 0, 0, 100)
style.Font.Color = Color.FromCmyk(0, 0, 0, 100)

The result is fine: c: 0 m: 0 y: 0 k: 100. <-- pure color

Do you know if it's posible to create a gray color without mixed colors?
Thank you


Top
 Profile  
Reply with quote  
PostPosted: Thu May 04, 2017 7:47 am 
Offline
empira Employee
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 2644
Location: Cologne, Germany
Hi!
Did you set the Color Mode to CMYK? If not, try this first.

For MigraDoc: Set the UseCmykMode property of the Document object to true.
For PDFsharp: Invoke "document.Options.ColorMode = PdfColorMode.Cmyk;" where document is your PdfDocument object.

See also:
http://www.pdfsharp.net/wiki/ColorsCMYK-sample.ashx

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Thu May 04, 2017 3:18 pm 
Offline

Joined: Wed May 03, 2017 11:25 pm
Posts: 4
Hi!
Yes, I did:
Const unicode = False
Const embedding As PdfFontEmbedding = PdfFontEmbedding.Always
Dim pdfRenderer As PdfDocumentRenderer = New PdfDocumentRenderer(unicode, embedding)
pdfRenderer.Document = document
pdfRenderer.RenderDocument()

Dim filename As String = sResultFolder & "Result (" & Now.ToString("yyyy-MM-dd HH.mm.ss") & ").pdf"
pdfRenderer.PdfDocument.Options.ColorMode = PdfColorMode.Cmyk
pdfRenderer.PdfDocument.Save(filename)

But I think that only allows to keep the cmyk profile. The point is the ink result in each color don't keep like I have define.
I need the result in cmyk (0, 0, 0, 25) not a cmyk (241, 241, 241, 0).
Thank you for your answers,


Top
 Profile  
Reply with quote  
PostPosted: Thu May 04, 2017 9:26 pm 
Offline
User avatar

Joined: Sat Mar 14, 2015 10:15 am
Posts: 235
Location: CCAA
Hi!

You are using MigraDoc, but it seems you still do not set "UseCmykMode".
You only show code fragments and you do not provide a generated PDF.

In the past turning code fragments into something I can debug often proved to be a waste of time.
I assume PDFsharp works correctly when used as intended.

_________________
Best regards
Thomas
(Freelance Software Developer with several years of MigraDoc/PDFsharp experience)


Top
 Profile  
Reply with quote  
PostPosted: Fri May 05, 2017 9:17 am 
Offline

Joined: Wed May 03, 2017 11:25 pm
Posts: 4
Hi!
I'm using that code:

Code:
'Imports System

Imports System.IO
Imports System.Text

'Imports to PDF

Imports PdfSharp.Pdf
Imports PdfSharp.Drawing
Imports PdfSharp.Pdf.PdfDocument
Imports PdfSharp.Pdf.IO
Imports MigraDoc.DocumentObjectModel
Imports MigraDoc.DocumentObjectModel.Tables
Imports MigraDoc.Rendering
Imports System.Drawing.Point
'-----------------------------------------------------------------------
#Region " Ini "

    Public Sub New()
        gRenderImage = New clsRenderImage
    End Sub

#End Region


 Public Sub Generate_Test()
        'BEGINING PDF
        Dim frm As New frmTest

        Try
            LineaLog(INFORMATION, "Generating: TEST...")

            ' loading the form
            frm = New frmTest
            frm.Left = -4000
            frm.Show()

            ' Saving folder...
            Dim sFolderResult As String = ReadOption("Test_FolderResul", gOptions)

            'Generate PDF Test
            Dim document As New Document()

            'Creating the size
            document.DefaultPageSetup.PageWidth = "195mm"
            document.DefaultPageSetup.PageHeight = "285mm"

            'Position
            Dim section As Section = document.AddSection()
            section.PageSetup.DifferentFirstPageHeaderFooter = True
            section.PageSetup.OddAndEvenPagesHeaderFooter = False

            'Folder definition
            Dim FolderResources As String = ReadOption("Test_FolderResources", gOptions)
            Dim sFolderResources As String = ReadOption("Test_FolderResources", gOptions)

            'background
            Dim image As Shapes.Image = section.AddImage(sFolderResources + "\WHITE_BACKGROUND.png")
            image.Width = frm.background.Width * 0.24
            image.Height = frm.background.Height * 0.24
            image.RelativeVertical = Shapes.RelativeVertical.Page
            image.RelativeHorizontal = Shapes.RelativeHorizontal.Page
            image.Left = Shapes.ShapePosition.Center
            image.Top = Shapes.ShapePosition.Center
            image.WrapFormat.Style = Shapes.WrapStyle.Through

            '---------------------------------
            ' FONT STYLES
            '----------------------------------

            ' TEXT 1
            Dim style As Style = document.Styles.AddStyle("TestFontBlack", "Normal")
            style.Font.Name = "Arial"
            style.Font.Size = 10
            style.Font.Bold = False
            style.Font.Color = Color.FromCmyk(0, 0, 0, 100)
            style.ParagraphFormat.LineSpacingRule = LineSpacingRule.AtLeast
            style.ParagraphFormat.LineSpacing = 10.85

            'TEXT 2
            style = document.Styles.AddStyle("TestFontGray", "Normal")
            style.Font.Name = "Arial"
            style.Font.Size = 10
            style.Font.Bold = False
            style.Font.Color = Color.FromCmyk(0, 0, 0, 50)
            style.ParagraphFormat.LineSpacingRule = LineSpacingRule.AtLeast
            style.ParagraphFormat.LineSpacing = 10.85

            'Text 1
            Dim text1 As Shapes.TextFrame
            text1 = section.AddTextFrame()
            Dim paragraphtext1 As Paragraph = text1.AddParagraph()
            'Text
            paragraphtext1.AddText("TEXT IN BLACK CMYK (0, 0, 0, 100)")
            paragraphtext1.AddText(" AND THE RESULT IS CMYK(0, 0, 0, 100)")
            paragraphtext1.Style = "TestFontBlack"
            paragraphtext1.Format.Alignment = ParagraphAlignment.Left
            text1.RelativeVertical = Shapes.RelativeVertical.Page
            text1.RelativeHorizontal = Shapes.RelativeHorizontal.Page
            text1.Width = 1000
            text1.Height = 100
            text1.Top = Unit.FromPoint(100)
            text1.WrapFormat.DistanceLeft = Unit.FromPoint(20)


            'Text 2
            Dim text2 As Shapes.TextFrame
            text2 = section.AddTextFrame()
            Dim paragraphtext2 As Paragraph = text2.AddParagraph()
            'Text
            paragraphtext2.AddText("TEXT IN GRAY CMYK(0, 0, 0, 50)")
            paragraphtext2.AddText(" AND THE RESULT IS CMYK(55, 45, 42, 7)")
            paragraphtext2.Style = "TestFontGray"
            paragraphtext2.Format.Alignment = ParagraphAlignment.Left
            text2.RelativeVertical = Shapes.RelativeVertical.Page
            text2.RelativeHorizontal = Shapes.RelativeHorizontal.Page
            text2.Width = 1000
            text2.Height = 100
            text2.Top = Unit.FromPoint(200)
            text2.WrapFormat.DistanceLeft = Unit.FromPoint(20)

            Const unicode = False
            Const embedding As PdfFontEmbedding = PdfFontEmbedding.Always
            Dim pdfRenderer As PdfDocumentRenderer = New PdfDocumentRenderer(unicode, embedding)
            pdfRenderer.Document = document
            pdfRenderer.RenderDocument()

            Dim filename As String = sFolderResult & "TEST (" & Now.ToString("yyyy-MM-dd HH.mm.ss") & ").pdf"
            pdfRenderer.PdfDocument.Options.ColorMode = PdfColorMode.Cmyk
            '---------------------------
            'RENDER TEST
            '---------------------------

            pdfRenderer.PdfDocument.Save(filename)
            frm.Close()

            LineaLog(INFORMATION, "Generating: PDF TEST ... OK")

        Catch ex As Exception
            LineaLog(PROCESS_ERROR, ex.Message & ex.StackTrace)
            gResult = FIN_PROCESS_ERROR
        Finally
            If (frm IsNot Nothing) Then
                frm.Close()
                frm.Dispose()
                GC.Collect()
            End If
        End Try

    End Sub

#Region " End "

    Public Sub Dispose() Implements IDisposable.Dispose
        gRenderImage = Nothing
        GC.Collect()
    End Sub

#End Region


Attachments:
TEST (2017-05-05 11.10.00).zip [23.34 KiB]
Downloaded 12 times
Top
 Profile  
Reply with quote  
PostPosted: Mon May 08, 2017 11:45 am 
Offline
empira Employee
User avatar

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

Above "'Creating the size" would be a good place for
Code:
document.UseCmykMode = true
(not sure this is valid VB code)
This is the code you need to tell MigraDoc you want to use CMYK colors.
Without this assignment, all colors will be converted to RGB.

The call "pdfRenderer.PdfDocument.Options.ColorMode = PdfColorMode.Cmyk" comes after all pages have been created in RGB mode. AFAIK you can skip calling this since you are using MigraDoc.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Sun May 14, 2017 10:55 pm 
Offline

Joined: Wed May 03, 2017 11:25 pm
Posts: 4
Hi! It works fine with that code!!! Thank you!!
But, one more thing please:
I'm using a cmyk gray background, and over it I'm putting a transparent .PNG picture (in RGB).
It's possible that at last, when the background + PNG are rendered, both are converted in RGB.
In addition, seems the PNG + the background it's a only one structure.
Thank you again!


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

All times are UTC


Who is online

Users browsing this forum: Bing [Bot] and 5 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:  
Powered by phpBB® Forum Software © phpBB Group