PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Tue Apr 23, 2024 10:49 am

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: Sun Nov 29, 2015 11:24 am 
Offline

Joined: Sun Nov 29, 2015 10:45 am
Posts: 4
Hi
i will generate print document and Print To XPS File Using XPS Printer.
i will also generate pdf using same logic but out will diifrence. can u tell me where is defferance.
i will u send XPS File and PDF File
please see in XPS there is some gap between Text and Line
But In PDF there is No Gape
i send Bith XPS And PDF File
Please Reply fast as if possible


Attachments:
Problem.rar [179.24 KiB]
Downloaded 346 times
Top
 Profile  
Reply with quote  
PostPosted: Sun Nov 29, 2015 5:28 pm 
Offline
PDFsharp Expert
User avatar

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

In the PDF file there is a larger gap on the left side of the text and a smaller gap on the right.

You don't show any code and I have no idea where this difference comes from and whether the PDF or the XPS is correct.

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


Top
 Profile  
Reply with quote  
PostPosted: Mon Nov 30, 2015 5:08 pm 
Offline

Joined: Sun Nov 29, 2015 10:45 am
Posts: 4
hi i will send code below and Send Output in File Please Check
I find Two Bug Which is marked in Attachment
Code:
Imports System.Drawing
Imports System.Drawing.Printing
Imports System.Drawing.Drawing2D
Imports System.Drawing.Text

Imports PdfSharp.Pdf
Imports PdfSharp
Imports PdfSharp.Drawing
Imports PdfSharp.Fonts
Imports PdfSharp.Forms


Public Class Form1

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

        Dim PrnDoc As New System.Drawing.Printing.PrintDocument

        Dim PrnPreview As New PrintPreviewDialog
        AddHandler PrnDoc.PrintPage, AddressOf PrnDoc_PrintPage
        'PrnPreview.wi
        PrnPreview.Document = PrnDoc
        PrnPreview.PrintPreviewControl.Zoom = 1.5

        PrnPreview.ShowDialog()

    End Sub

    Private Sub PrnDoc_PrintPage(sender As Object, e As System.Drawing.Printing.PrintPageEventArgs)

        Dim rec As RectangleF
        Dim Printx As Single
        Dim PrintY As Single
        Dim gfx As Graphics
        Dim Ind_Col As Long
        Dim Ind_Row As Long
        Dim Width1 As Single
        Dim Height1 As Single
        Dim TopMargine As Single
        Dim LeftMargine As Single
        Dim TmpStr1 As String

        gfx = e.Graphics
        gfx.SmoothingMode = SmoothingMode.HighQuality
        gfx.PageUnit = GraphicsUnit.Point
        gfx.TextRenderingHint = TextRenderingHint.AntiAlias
        'gfx.TextContrast = 0
        gfx.CompositingQuality = CompositingQuality.HighQuality
        gfx.InterpolationMode = InterpolationMode.HighQualityBilinear
        gfx.PixelOffsetMode = PixelOffsetMode.HighQuality

        Width1 = 144
        Height1 = 14.17323

        LeftMargine = 18
        TopMargine = 18

        PrintY = TopMargine

        For Ind_Row = 1 To 3

            Printx = LeftMargine
            For Ind_Col = 1 To 3

                rec = New RectangleF(Printx, PrintY, Width1, Height1)

                If Ind_Col <> 2 Then

                    '--- Left Line
                    Dim pen As New Pen(Color.Black)
                    pen.Alignment = PenAlignment.Left
                    pen.Width = 1
                    gfx.DrawLine(pen, Printx + (pen.Width / 2), PrintY, Printx + (pen.Width / 2), PrintY + Height1)
                    rec.X = rec.X + pen.Width
                    pen.Dispose()

                    '--- Right Line
                    pen = New Pen(Color.Black)
                    pen.Alignment = PenAlignment.Center
                    pen.Width = 1
                    gfx.DrawLine(pen, Printx + Width1 - (pen.Width / 2), PrintY, Printx + Width1 - (pen.Width / 2), PrintY + Height1)
                    rec.Width = rec.Width - pen.Width
                    pen.Dispose()

                    If Ind_Row = 1 Then

                        '--- Top Line
                        pen = New Pen(Color.Black)
                        pen.Alignment = PenAlignment.Center
                        pen.Width = 1
                        gfx.DrawLine(pen, Printx, PrintY + (pen.Width / 2), Printx + Width1, PrintY + (pen.Width / 2))
                        rec.Y = rec.Y + pen.Width
                        pen.Dispose()

                    End If

                    '--- Bottom Line
                    pen = New Pen(Color.Black)
                    pen.Alignment = PenAlignment.Center
                    pen.Width = 1
                    gfx.DrawLine(pen, Printx, PrintY + Height1 - (pen.Width / 2), Printx + Width1, PrintY + Height1 - (pen.Width / 2))
                    rec.Height = rec.Height - pen.Width
                    pen.Dispose()


                    '--- For Gap From Line
                    rec.X = rec.X + 1
                    rec.Y = rec.Y + 1
                    rec.Height = rec.Height - 1
                    rec.Width = rec.Width - 1
                End If

                Dim Format As New StringFormat
                Format.FormatFlags = StringFormatFlags.NoWrap
                Format.Trimming = StringTrimming.None

                If Ind_Col = 1 Then
                    Format.Alignment = StringAlignment.Far
                    Format.LineAlignment = StringAlignment.Center
                ElseIf Ind_Col = 2 Then
                    Format.Alignment = StringAlignment.Center
                    Format.LineAlignment = StringAlignment.Center
                Else
                    Format.Alignment = StringAlignment.Far
                    Format.LineAlignment = StringAlignment.Center
                End If

                TmpStr1 = "Row " + Ind_Row.ToString() + "Cell " + Ind_Col.ToString()
                If Ind_Col = 1 Then
                    TmpStr1 = "3W4W5W6W7W8W9W1W2W3W4W5W6W7W8W9"
                End If

                gfx.DrawString(TmpStr1, New Font("Arial", 8, FontStyle.Regular), System.Drawing.Brushes.Black, rec, Format)
                Printx = Printx + Width1

            Next

            PrintY = PrintY + Height1

        Next

        e.HasMorePages = False
    End Sub

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click

        Dim PdfDoc As PdfDocument
        Dim PdfPage As PdfPage
        Dim PgInfo As PaperSize

        PdfDoc = New PdfDocument()
        PdfDoc.Info.Author = My.Application.Info.CompanyName
        PdfDoc.Info.Creator = "Ankit Patel"
        PdfDoc.Info.Subject = "Export From Report Lib"
        PdfDoc.Info.Title = My.Application.Info.Title


        PdfPage = PdfDoc.AddPage()
        'PdfPage.Size = PageSize.Undefined
        PdfPage.Width = 841.68
        PdfPage.Height = 595.44
        PdfPage.Orientation = PageOrientation.Portrait

        Dim rec As RectangleF
        Dim Printx As Single
        Dim PrintY As Single
        Dim gfx As XGraphics
        Dim Ind_Col As Long
        Dim Ind_Row As Long
        Dim Width1 As Single
        Dim Height1 As Single
        Dim TopMargine As Single
        Dim LeftMargine As Single
        Dim TmpStr1 As String

        gfx = XGraphics.FromPdfPage(PdfPage, XGraphicsPdfPageOptions.Append, XGraphicsUnit.Point)
        gfx.SmoothingMode = SmoothingMode.HighQuality
       
        Width1 = 144
        Height1 = 14.17323

        LeftMargine = 18
        TopMargine = 18

        PrintY = TopMargine

        For Ind_Row = 1 To 3

            Printx = LeftMargine
            For Ind_Col = 1 To 3

                rec = New RectangleF(Printx, PrintY, Width1, Height1)

                If Ind_Col <> 2 Then

                    '--- Left Line
                    Dim pen As New XPen(Color.Black)
                    'pen.Alignment = PenAlignment.Left
                    pen.Width = 1
                    gfx.DrawLine(pen, Printx + (pen.Width / 2), PrintY, Printx + (pen.Width / 2), PrintY + Height1)
                    rec.X = rec.X + pen.Width
                    pen = Nothing

                    '--- Right Line
                    pen = New XPen(Color.Black)
                    'pen.Alignment = PenAlignment.Center
                    pen.Width = 1
                    gfx.DrawLine(pen, Printx + Width1 - (pen.Width / 2), PrintY, Printx + Width1 - (pen.Width / 2), PrintY + Height1)
                    rec.Width = rec.Width - pen.Width
                    pen = Nothing

                    If Ind_Row = 1 Then

                        '--- Top Line
                        pen = New XPen(Color.Black)
                        'pen.Alignment = PenAlignment.Center
                        pen.Width = 1
                        gfx.DrawLine(pen, Printx, PrintY + (pen.Width / 2), Printx + Width1, PrintY + (pen.Width / 2))
                        rec.Y = rec.Y + pen.Width
                        pen = Nothing

                    End If

                    '--- Bottom Line
                    pen = New XPen(Color.Black)
                    'pen.Alignment = PenAlignment.Center
                    pen.Width = 1
                    gfx.DrawLine(pen, Printx, PrintY + Height1 - (pen.Width / 2), Printx + Width1, PrintY + Height1 - (pen.Width / 2))
                    rec.Height = rec.Height - pen.Width
                    pen = Nothing


                    '--- For Gap From Line
                    rec.X = rec.X + 1
                    rec.Y = rec.Y + 1
                    rec.Height = rec.Height - 1
                    rec.Width = rec.Width - 1
                End If

                Dim Format As New XStringFormat
                'Format.FormatFlags = XStringFormat.NoWrap
                'Format.Trimming = XStringFormat.None

                If Ind_Col = 1 Then
                    Format.Alignment = XStringAlignment.Far
                    Format.LineAlignment = XStringAlignment.Center
                ElseIf Ind_Col = 2 Then
                    Format.Alignment = XStringAlignment.Center
                    Format.LineAlignment = XStringAlignment.Center
                Else
                    Format.Alignment = XStringAlignment.Far
                    Format.LineAlignment = XStringAlignment.Center
                End If

                TmpStr1 = "Row " + Ind_Row.ToString() + "Cell " + Ind_Col.ToString()
                If Ind_Col = 1 Then
                    TmpStr1 = "3W4W5W6W7W8W9W1W2W3W4W5W6W7W8W9"
                End If

                gfx.DrawString(TmpStr1, New XFont("Arial", 8, FontStyle.Regular), XBrushes.Black, rec, Format)
                Printx = Printx + Width1

            Next

            PrintY = PrintY + Height1

        Next

        PdfDoc.Save("E:\AdpError.pdf")

    End Sub
End Class


Attachments:
Problem.rar [33.6 KiB]
Downloaded 331 times
Top
 Profile  
Reply with quote  
PostPosted: Sat Dec 12, 2015 4:49 am 
Offline

Joined: Sun Nov 29, 2015 10:45 am
Posts: 4
if it is not possible than tell me. so i can not waste my time. But please Reply. Thank u


Top
 Profile  
Reply with quote  
PostPosted: Sat Dec 12, 2015 7:13 am 
Offline
PDFsharp Expert
User avatar

Joined: Sat Mar 14, 2015 10:15 am
Posts: 915
Location: CCAA
ankit_patel314 wrote:
if it is not possible than tell me. so i can not waste my time.
I will not waste my time trying to turn your code snippet into something I can run in a debugger.

If there is a bug in PDFsharp then we need a complete project that we can run in a debugger.
In the best case there will be just one DrawString along with one DrawRectangle or two DrawLine calls.

Make the problem replicable with as few lines of code as possible. If it takes 200 lines - OK. Better if 20 lines are enough.

See also:
viewtopic.php?f=2&t=832

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


Top
 Profile  
Reply with quote  
PostPosted: Fri Dec 18, 2015 5:56 am 
Offline

Joined: Sun Nov 29, 2015 10:45 am
Posts: 4
how can i send whole project
because my project become more than 256Kb


Top
 Profile  
Reply with quote  
PostPosted: Fri Dec 18, 2015 7:44 am 
Offline
PDFsharp Expert
User avatar

Joined: Sat Mar 14, 2015 10:15 am
Posts: 915
Location: CCAA
ankit_patel314 wrote:
how can i send whole project
Remove OBJ and BIN directories and the NuGet packages. Or upload to an external file hoster and post a link.

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


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: No registered users and 209 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