PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Sat May 15, 2021 8:41 pm

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: Fri Feb 05, 2021 1:09 pm 
Offline

Joined: Fri Feb 05, 2021 12:46 pm
Posts: 3
Hi,

Been having an issue with PDFSharp printing text in the same colour as a coloured rectangle. The concern is it doesn't happen all the time!

We're producing a set of blocks to represent items on a shelf. There seems to be an intermittent problem with the text (which should ALWAYS be black) .
(pdfGraphics.DrawString(sTextBox, xFont, XBrushes.Black, dblX, dblY))

However, if you look for product 73 on the attached image (that's specifying explicitly a black brush) you'll see the rectangle but the text is the same colour as the rectangle (end of shelf 7). Other items are printing correctly using the same method in a loop (see shelf 55)

Is this a known bug?

I've seen various fixes on the internet, mainly mentioning earlier versions of PDFSharp, and have tried some of the workarounds involving resetting the XGraphics object after outputting any graphics, but nothing seems to resolve the problem.

We're using v1.51.5185.0

Thanks for any help.


Attachments:
File comment: Item 73 (the block next to 72) is displayed in the in the same colour as the rectangle not black as specified.
OverflowingProduct2.PNG
OverflowingProduct2.PNG [ 20.55 KiB | Viewed 654 times ]
Top
 Profile  
Reply with quote  
PostPosted: Fri Feb 05, 2021 3:32 pm 
Offline
PDFsharp Expert
User avatar

Joined: Sat Mar 14, 2015 10:15 am
Posts: 636
Location: CCAA
nsanderson wrote:
Is this a known bug?
Is it a bug?
"Not repro" with just a screenshot.

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


Top
 Profile  
Reply with quote  
PostPosted: Fri Feb 05, 2021 3:49 pm 
Offline

Joined: Fri Feb 05, 2021 12:46 pm
Posts: 3
This is the code - I've removed the rectangle output as that seems to be working fine:


' Attempt to paint product rectangles onto the frontview
Private Function ExportProductsFrontView(ByVal lSectionID As Long, ByVal SectionFrontViewRight As Single, ByVal SectionFrontViewX As Single, lastIndex As Long) As Long

Dim SupportFrontViewWidth As Single = modGlobals.Value.Zero
' Valid NEW or EXISTING planogram item id
Dim lastProductNumber As Long = 0
Dim lCurrentProductIndex As Long = lastIndex
Dim lRetVal As Long

Try
If modManagement.ValidID(lSectionID) Then

Dim thisSupport As New clsSectionSupport
thisSupport = FindSupportOnSection(lSectionID)
Dim dblBoxRight As Double = 0
Dim dblTextLeft As Double = 0

' Draw products on the FrontView that do not overlap
For Each oProduct In oExportPlanogram.Products.Where(Function(product) product.SectionID = lSectionID)

'--- If we change product number, increment the index and update the current product number ---
If oProduct.ProductID <> lastProductNumber Then
lastProductNumber = oProduct.ProductID
lCurrentProductIndex += 1
End If

'--- Draw the product index number in a box And put it in the bottom left of the product ---
Call modExportPlanogramSharp.TextOut(CInt(oProduct.FrontViewX) + 1,
CInt(oProduct.FrontViewBottom) - 1,
lCurrentProductIndex.ToString, 3)

Next ' Product

End If

Catch ex As Exception
Throw New Exception(Reflection.MethodBase.GetCurrentMethod.Name & " : " & ex.Message)
End Try

Return lCurrentProductIndex

End Function ' ExportProductsFrontView


Inside a module called modExportPlanogramSharp, there's the text out method:
Friend Sub TextOut(dblX As Double,
dblY As Double,
sTextBox As String,
Optional dblFontSize As Double = EXPORT_FONT_SIZE,
Optional bBold As Boolean = False,
Optional bItalic As Boolean = False,
Optional bUnderline As Boolean = False,
Optional bStrikeOut As Boolean = False)
Try
With pdfExportDocument

Dim objStyle As Object = GetFontStyle(bBold, bItalic, bUnderline, bStrikeOut)
Dim xFont As XFont = New XFont(EXPORT_FONT_NAME, dblFontSize, DirectCast(objStyle, XFontStyle))

pdfGraphics.DrawString(sTextBox, xFont, XBrushes.Black, dblX, dblY)

End With
Catch ex As Exception
Call WriteErrorLogAndShowMessage(Reflection.MethodBase.GetCurrentMethod.Name, Err.Number, "MESSAGE_000XXX", "Did not draw textout.", ex.Message)
End Try
End Sub

A product record is included in the attachment.

Hopefully you can see that this is printing a black string into the PDF for every item in the list of products (~540) Sometimes, that XBrushes.Black is green or grey.
I tried attaching the PDF but it only seems to accept images?


Top
 Profile  
Reply with quote  
PostPosted: Fri Feb 05, 2021 3:55 pm 
Offline

Joined: Fri Feb 05, 2021 12:46 pm
Posts: 3
A slightly closer view of the problem where I've highlighted the hidden text (73)
You can CTL+C CTRL+V the text into Notepad and it's there - it's just the wrong colour in the PDF output.

Attachment:
OverflowingProduct3.PNG
OverflowingProduct3.PNG [ 1.56 KiB | Viewed 644 times ]


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

All times are UTC


Who is online

Users browsing this forum: No registered users and 2 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