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