بسم الله نبدأ
أولا عليك تحميل ملفات المكتبة من المرفقات و هما عبارة عن ملفى dll
ثانيا قم باضافة مراجع للملفات فى Referances بالمشروع
ثالثا فى النموذج الخاص بك أضف هذه الادوات:-
1- مربع نص باسم txtname يحتوى على اسم المريض
2- مربع نص باسم txtage يحتوى على عمر المريض
3- مربع نص باسم txtdrug1 يحتوى على الدواء الاول
4- مربع نص باسم txtdrug2 يحتوى على الدواء الثانى
5- مربع نص باسم txtdrug3 يحتوى على الدواء الثالث
6- مربع نص باسم txtdrug4 يحتوى على الدواء الرابع
7- مربع نص باسم txtdrug5 يحتوى على الدواء الخامس
8- زر
رابعا ضع صورة الروشتة التى أرسلتها أنت من قبل فى نفس مجلد البرنامج debug فى المشروع
و نأتى الى الأكواد
==========
مبدأيا و حتى تكون الفكرة واضحة سأقوم بعمل جدول بحجم الجزء الخالى من الروشتة ثم نقوم بإضافة البيانات اليه على شكل صفوف (خلايا)
و ذلك حتى نتمكن من التحكم فى اتجاه النص لكى لا يسبب مشاكل مع النصوص العربية
أولا هذه دالة تعطى خلية بالموصفات التى أحددها (و تظهر فى النهاية كسطر )
كود :
Private Function CellData(TheText As String, TheFont As Font, Optional TheColor As BaseColor = Nothing, Optional TheTopDistance As Integer = 0, Optional TheStartDistance As Integer = 0, Optional theAlignment As Integer = 0) As PdfPCell
Dim CellFont As Font = New Font(TheFont)
CellFont.Color = If(TheColor Is Nothing, BaseColor.BLACK, TheColor)
Dim C As PdfPCell = New PdfPCell(New Phrase(0, TheText, CellFont))
C.Border = BorderStyle.None
C.PaddingTop = TheTopDistance
C.HorizontalAlignment = theAlignment '1 center 2 left 0 right >>>> default
If theAlignment = 2 Then
C.PaddingLeft = TheStartDistance
Else
C.PaddingRight = TheStartDistance
End If
Return C
End Function
وثانيا هذا الاجراء يقوم بتكوين الملف بالاسم المحدد ثم يضيف الخلايا اليه و بعد ذلك يفتح الملف بعد حفظه
كود :
Private Sub WritPrescription(ByVal pdfdocument_path As String)
Dim Prescription As New Document(PageSize.A5.Rotate, 0, 0, 0, 0)
Dim writer As PdfWriter = PdfWriter.GetInstance(Prescription, New FileStream(pdfdocument_path, FileMode.Create))
Prescription.Open()
'Create a PDF image object from our physical image
Dim ThisImage = itextsharp.text.Image.GetInstance("n.jpg")
'Scale the image
Dim NewW, NewH As Single
NewW = Prescription.PageSize.Width
NewH = Prescription.PageSize.Height
ThisImage.ScaleToFit(NewW, NewH)
'Add the image to the document under text
ThisImage.SetAbsolutePosition(0, 2)
Dim under As PdfContentByte = writer.DirectContentUnder
under.AddImage(ThisImage)
'add font to Write arabic letters
Dim fontpath As String = Environment.GetEnvironmentVariable("SystemRoot") + "\\fonts\\times.ttf"
Dim BaseFont As BaseFont = BaseFont.CreateFont(fontpath, BaseFont.IDENTITY_H, BaseFont.EMBEDDED)
Dim arabicfont As Font = New Font(BaseFont, 12, itextsharp.text.Font.BOLD, BaseColor.BLACK)
Dim tbl As PdfPTable = New PdfPTable(1)
'resize table to Writing part
tbl.TotalWidth = 360.0F
'set writing direction
tbl.RunDirection = PdfWriter.RUN_DIRECTION_RTL
'write name
tbl.AddCell(CellData(txtname.Text, arabicfont, BaseColor.BLACK, 41, 70, 0))
'write age and date
tbl.AddCell(CellData(Today.Date & Space(40) & txtage.Text, arabicfont, BaseColor.BLACK, 10, 80, 0))
'write drugs
tbl.AddCell(CellData(txtdrug1.Text & " - ", arabicfont, BaseColor.BLUE, 30, 20, 2))
tbl.AddCell(CellData(txtdrug2.Text & " - ", arabicfont, BaseColor.BLUE, 20, 20, 2))
tbl.AddCell(CellData(txtdrug3.Text & " - ", arabicfont, BaseColor.BLUE, 20, 20, 2))
tbl.AddCell(CellData(txtdrug4.Text & " - ", arabicfont, BaseColor.BLUE, 20, 20, 2))
tbl.AddCell(CellData(txtdrug5.Text & " - ", arabicfont, BaseColor.BLUE, 20, 20, 2))
' ádd data table to Prescription
tbl.WriteSelectedRows(0, -1, Prescription.Left + 182, Prescription.Top, writer.DirectContent)
Prescription.Close()
'open Prescription
Process.Start(pdfdocument_path)
End Sub
ؤ فى النهاية ضع هذا الكود فى حدث ضغط الزر
كود :
WritPrescription("Prescription.pdf")
الكود سهل و واضح و أعتقد لا يحتاج شرح و لقد وضعت وصف لكل جزئية بالكود
و بالتوفيق للجميع
بالمرفقات ملفات المكتبة و الملف الناتج و صورة الروشتة التى أرسلتها من قبل