Hello!
I'm using PdfSharp 1.32.3057.0 (GDI build I believe) to generate referencefiles for my company's scan process.
The PDFs we generate contain the object id and file type of the file we're scanning.
We use the following VB.Net code to apply both parameters on the PDF:
Code:
Private Sub DrawObjectIdAndFileType(ByVal document As PdfDocument, ByVal graphics As XGraphics, ByVal page As PdfPage, ByVal objectId As String, ByVal fileType As String)
Dim objSize As XSize = graphics.MeasureString(objectId, New XFont("Calibri", 12, XFontStyle.Regular))
Dim fileTypeSize = graphics.MeasureString("(" & fileType & ")", New XFont("Calibri", 12, XFontStyle.Regular))
Dim totalHeight = objSize.Height + fileTypeSize.Width + 4
Dim largestWidth = fileTypeSize.Width + 20
If (objSize.Width > fileTypeSize.Width) Then
largestWidth = objSize.Width + 20
End If
Dim objForm As XForm = New XForm(document, totalHeight, largestWidth)
Dim objGraphs As XGraphics = XGraphics.FromForm(objForm)
Dim objObjectRect = New XRect((largestWidth - objSize.Width) / 2, 0, objSize.Width, objSize.Height)
Dim objFileTypeRect = New XRect((largestWidth - fileTypeSize.Width) / 2, objSize.Height + 4, fileTypeSize.Width, fileTypeSize.Height)
Dim objFormatter As XTextFormatter = New XTextFormatter(objGraphs)
objGraphs.RotateAtTransform(270, New XPoint(totalHeight / 2, largestWidth / 2))
objFormatter.DrawString(objectId, New XFont("Calibri", 12, XFontStyle.Regular), XBrushes.Black, objObjectRect)
objFormatter.DrawString("(" & fileType & ")", New XFont("Calibri", 12, XFontStyle.Regular), XBrushes.Black, objFileTypeRect)
graphics.DrawImage(objForm, New System.Drawing.Point(100, CType(page.Height, Integer) * 0.8 - largestWidth / 2))
End Sub
However, when the file type gets too small, the horizontal offset is no longer correct:
Quote:
13 0 obj
<<
/Type/XObject
/Subtype/Form
/BBox[0 0 37.328 56.492]
/Resources
<<
/ProcSet [/PDF/Text/ImageB/ImageC/ImageI]
/ExtGState
<<
/GS0 8 0 R
>>
/Font
<<
/F0 15 0 R
>>
>>
/Length 150
>>
stream
q
1 0 0 -1 0 56.492 cm -100 Tz
q
0 -1 1 0 -9.582031 46.910156 cm
BT
/GS0 gs
/F0 -12 Tf
10 11.4258 Td (120148) Tj
8.9063 18.6484 Td (\(ye\)) Tj
ET
Q
Q
endstream
endobj
As shown below, when the file type is a longer string, it does show correctly:
Quote:
13 0 obj
<<
/Type/XObject
/Subtype/Form
/BBox[0 0 75.074 76.426]
/Resources
<<
/ProcSet [/PDF/Text/ImageB/ImageC/ImageI]
/ExtGState
<<
/GS0 8 0 R
>>
/Font
<<
/F0 15 0 R
>>
>>
/Length 158
>>
stream
q
1 0 0 -1 0 76.426 cm -100 Tz
q
0 -1 1 0 -0.675781 75.75 cm
BT
/GS0 gs
/F0 -12 Tf
19.9668 11.4258 Td (120148) Tj
-9.9668 18.6484 Td (\(Algemeen\)) Tj
ET
Q
Q
endstream
endobj
All PDF files that are generated with a larger file type have the same (offset?) value, marked in green.
When I change the value marked with red (first PDF) to the value marked in green (second PDF), the parameters from the first PDF are positioned correctly.
Any idea what is causing this issue?
Kind regards,
Anton