/// <summary> /// Creates the normal appearance form X object for the annotation that represents /// this acro form text field. /// </summary> void RenderAppearance() { PdfRectangle rect = Elements.GetRectangle(PdfAnnotation.Keys.Rect); XForm form = new XForm(this.document, rect.Size); XGraphics gfx = XGraphics.FromForm(form); if (backColor != XColor.Empty) { gfx.DrawRectangle(new XSolidBrush(BackColor), rect.ToXRect() - rect.Location); } string text = Text; if (text.Length > 0) { gfx.DrawString(Text, Font, new XSolidBrush(ForeColor), rect.ToXRect() - rect.Location + new XPoint(2, 0), XStringFormats.TopLeft); } form.DrawingFinished(); // Get existing or create new appearance dictionary PdfDictionary ap = Elements[PdfAnnotation.Keys.AP] as PdfDictionary; if (ap == null) { ap = new PdfDictionary(this.document); Elements[PdfAnnotation.Keys.AP] = ap; } // Set XRef to normal state ap.Elements["/N"] = form.PdfForm.Reference; }
internal override void PrepareForSave() { if (Rectangle.X1 + Rectangle.X2 + Rectangle.Y1 + Rectangle.Y2 == 0) { return; } if (this.AppearanceHandler == null) { return; } PdfRectangle rect = Elements.GetRectangle(PdfAnnotation.Keys.Rect); XForm form = new XForm(this._document, rect.Size); XGraphics gfx = XGraphics.FromForm(form); this.AppearanceHandler.DrawAppearance(gfx, rect.ToXRect()); form.DrawingFinished(); // Get existing or create new appearance dictionary PdfDictionary ap = Elements[PdfAnnotation.Keys.AP] as PdfDictionary; if (ap == null) { ap = new PdfDictionary(this._document); Elements[PdfAnnotation.Keys.AP] = ap; } // Set XRef to normal state ap.Elements["/N"] = form.PdfForm.Reference; }
void RenderAppearance() { for (var i = 0; i < Annotations.Elements.Count; i++) { var widget = Annotations.Elements[i]; if (widget == null) { continue; } var rect = widget.Rectangle; var xRect = new XRect(0, 0, rect.Width, rect.Height); var form = new XForm(_document, xRect); EnsureFonts(form); using (var gfx = XGraphics.FromForm(form)) { if (widget.BackColor != XColor.Empty) { gfx.DrawRectangle(new XSolidBrush(widget.BackColor), xRect); } // Draw Border if (!widget.BorderColor.IsEmpty) { gfx.DrawRectangle(new XPen(widget.BorderColor), xRect); } var index = SelectedIndex; if (index > 0) { var text = ValueInOptArray(index, false); if (!String.IsNullOrEmpty(text)) { var format = TextAlign == TextAlignment.Left ? XStringFormats.CenterLeft : TextAlign == TextAlignment.Center ? XStringFormats.Center : XStringFormats.CenterRight; gfx.DrawString(text, Font, new XSolidBrush(ForeColor), xRect, format); } } form.DrawingFinished(); var ap = new PdfDictionary(this._document); widget.Elements[PdfAnnotation.Keys.AP] = ap; widget.Elements.SetName(PdfAnnotation.Keys.AS, "/N"); // set appearance state // Set XRef to normal state ap.Elements["/N"] = form.PdfForm.Reference; var xobj = form.PdfForm; var s = xobj.Stream.ToString(); s = "/Tx BMC\n" + s + "\nEMC"; xobj.Stream.Value = new RawEncoding().GetBytes(s); } } }
public static void PDFExport(string Paydate) { string InvoiceNumber = "" + SelectedInvoiceNumber + ""; PdfDocument document = new PdfDocument(); document.Info.Title = "Invoice"; document.Info.Author = "Jack Huckins"; document.Info.Subject = "Service Invoice"; PdfPage page = new PdfPage(); page = document.AddPage(); page.Width = XUnit.FromInch(8.5); page.Height = XUnit.FromInch(11); XGraphics gfx = default(XGraphics); gfx = XGraphics.FromPdfPage(page); XForm form = new XForm(document, XUnit.FromMillimeter(300), XUnit.FromMillimeter(300)); XGraphics formGfx = default(XGraphics); formGfx = XGraphics.FromForm(form); XGraphicsState state = default(XGraphicsState); state = formGfx.Save(); //..... Invoice Results GetInvResults(Paydate); PrepareInvoiceTop(formGfx, state, InvoiceNumber); PrepareInvoiceData(6, 217, formGfx); PrepareFooter(formGfx); state = formGfx.Save(); formGfx.Dispose(); gfx.DrawImage(form, 0, 0); //document.Save("c:\\Invoices\\Inv " + InvoiceNumber + ".pdf") SetReportPath(); document.Save(ReportPath); TimeConnector.Data.ActionLog.Insert("PDF Export", "" + InvoiceNumber + ""); //UpdatePDFLabel("30 second Check", Form1.lblPDFStatus); //var _with1 = ViewPDF; //_with1.PdfName = Export.ReportPath; //_with1.Show(); }
public static void DrawBeziers() { string fn = @"input.pdf"; using (PdfSharp.Pdf.PdfDocument document = PdfSharp.Pdf.IO.PdfReader.Open(fn)) { // Create an empty XForm object with the specified width and height // A form is bound to its target document when it is created. The reason is that the form can // share fonts and other objects with its target document. using (XForm form = new XForm(document, XUnit.FromMillimeter(70), XUnit.FromMillimeter(55))) { // Create an XGraphics object for drawing the contents of the form. using (XGraphics formGfx = XGraphics.FromForm(form)) { // Draw a large transparent rectangle to visualize the area the form occupies XColor back = XColors.Orange; back.A = 0.2; XSolidBrush brush = new XSolidBrush(back); formGfx.DrawRectangle(brush, -10000, -10000, 20000, 20000); // On a form you can draw... // ... text formGfx.DrawString("Text, Graphics, Images, and Forms", new XFont("Verdana", 10, XFontStyle.Regular), XBrushes.Navy, 3, 0, XStringFormats.TopLeft); XPen pen = XPens.LightBlue.Clone(); pen.Width = 2.5; // ... graphics like Bézier curves formGfx.DrawBeziers(pen, XPoint.ParsePoints("30,120 80,20 100,140 175,33.3")); // ... raster images like GIF files XGraphicsState state = formGfx.Save(); formGfx.RotateAtTransform(17, new XPoint(30, 30)); formGfx.DrawImage(XImage.FromFile("../../../../../../dev/XGraphicsLab/images/Test.gif"), 20, 20); formGfx.Restore(state); // ... and forms like XPdfForm objects state = formGfx.Save(); formGfx.RotateAtTransform(-8, new XPoint(165, 115)); formGfx.DrawImage(XPdfForm.FromFile("../../../../../PDFs/SomeLayout.pdf"), new XRect(140, 80, 50, 50 * System.Math.Sqrt(2))); formGfx.Restore(state); // When you finished drawing on the form, dispose the XGraphic object. } // End Using formGfx } // End Using form } // End Using document }
/// <summary> /// May I have a new polling cards generator for this election? /// </summary> /// <param name="electionName">The name of the election</param> /// <param name="electionDate">The date of the election</param> /// <param name="electionTime">The timespan of the election</param> public PollingCards(string electionName, string electionDate, string electionTime) { Contract.Requires(electionName != null); Contract.Requires(electionDate != null); Contract.Requires(electionTime != null); //Create the a new document document = new PdfDocument(); //Create a template containing the non specific voter details template = new XForm(document, XUnit.FromMillimeter(Width), XUnit.FromMillimeter(Height)); XGraphics gfx = XGraphics.FromForm(template); AddWatermark(gfx); DrawGraphics(gfx); ElectionDetails(gfx, electionName, electionDate, electionTime); Descriptions(gfx); //Release the XGraphics object gfx.Dispose(); }
/// <summary> /// This method will Generate the invoice as a pdf file. /// </summary> /// <param name="dtBody">this datatable will contain all article information in the invoice</param> /// <param name="dtHead">this datatable will contain all information related to this invoice</param> /// <param name="dtVat">this datatable will contain all types of VAT summary exist in the invoice</param> /// <param name="invoiceId">Supplied invoiceid</param> private void ReportGenerator(DataTable dtBody, DataTable dtHead, DataTable dtVat, string invoiceId, DataTable dtPrice) { Double totalShippingCost = 0.00; Double totalVat = 0.00; Double subTotal = 0.00; Double invoiceTotal = 0.00; for (int i = 0; i < dtBody.Rows.Count; i++) { subTotal += Double.Parse(dtBody.Rows[i][5].ToString());// +Double.Parse(dtBody.Rows[i][8].ToString()); totalVat += Double.Parse(dtBody.Rows[i][8].ToString()); } string sql = "select sum(o.shippingcost) as total from orders o" + " where o.orderid in(select orderid from invoiceline where invoiceid='" + invoiceId + "')"; DataTable dtShipCost = dbHandler.GetDataTable(sql); totalShippingCost = Double.Parse(dtShipCost.Rows[0]["total"].ToString()); if (!dtHead.Rows[0]["customerbtwnr"].ToString().Equals("")) { invoiceTotal = subTotal;// +totalShippingCost; //invoiceTotal = subTotal + totalShippingCost; } else { invoiceTotal = subTotal + totalVat; } //Print Invoice XForm form = new XForm(report.document, XUnit.FromMillimeter(1000), XUnit.FromMillimeter(400)); XGraphics graphics = XGraphics.FromForm(form); double xInit = 0, yInit = 0; graphics.DrawString(CulturalValues[0], report._largeFontBold, XBrushes.Black, xInit, yInit, XStringFormat.TopLeft); report.gfx.DrawImage(form, 390, 40); // Print Customer Address dthead1 = dtHead; form = new XForm(report.document, XUnit.FromMillimeter(1000), XUnit.FromMillimeter(400)); graphics = XGraphics.FromForm(form); xInit = 95; yInit = 20; //graphics.DrawRectangle(report._borderPen, 0, 0, 300, 100); graphics.DrawString(dtHead.Rows[0]["companyname"].ToString().Trim(), report._normalFont, XBrushes.Black, xInit, yInit - report._lineGap, XStringFormat.TopLeft); graphics.DrawString(dtHead.Rows[0]["customer"].ToString().Trim(), report._normalFont, XBrushes.Black, xInit, yInit, XStringFormat.TopLeft); graphics.DrawString(dtHead.Rows[0]["address"].ToString() + " " + dtHead.Rows[0]["housenr"].ToString(), report._normalFont, XBrushes.Black, xInit, yInit + report._lineGap, XStringFormat.TopLeft); graphics.DrawString(dtHead.Rows[0]["postcode"].ToString() + " " + dtHead.Rows[0]["residence"].ToString(), report._normalFont, XBrushes.Black, xInit, yInit + report._lineGap * 2, XStringFormat.TopLeft); graphics.DrawString(dtHead.Rows[0]["country"].ToString(), report._normalFont, XBrushes.Black, xInit, yInit + report._lineGap * 3, XStringFormat.TopLeft); report.gfx.DrawImage(form, 245, 130); // Print Our VAT No + Bankaccount details form = new XForm(report.document, XUnit.FromMillimeter(1000), XUnit.FromMillimeter(400)); graphics = XGraphics.FromForm(form); xInit = 5; yInit = 5; graphics.DrawRectangle(XBrushes.Gray, 0, 0, 300, 20); graphics.DrawString(CulturalValues[1], report._smallFont, XBrushes.White, xInit, yInit, XStringFormat.TopLeft); graphics.DrawString(CulturalValues[2], report._smallFont, XBrushes.White, xInit + 120, yInit, XStringFormat.TopLeft); graphics.DrawRectangle(new XSolidBrush(XColor.FromArgb(120, 204, 204, 204)), 0, 20, xInit + 115, 60); graphics.DrawString("NL006012152B01", report._smallFontBold, XBrushes.Black, 5, yInit + 25, XStringFormat.TopLeft); graphics.DrawRectangle(new XSolidBrush(XColor.FromArgb(80, 204, 204, 204)), xInit + 115, 20, 180, 60); graphics.DrawString("ABNAMRO:", report._smallFont, XBrushes.Black, xInit + 120, yInit + 25, XStringFormat.TopLeft); graphics.DrawString("61 26 26 032", report._smallFontBold, XBrushes.Black, xInit + 200, yInit + 25, XStringFormat.TopLeft); graphics.DrawString("IBAN:", report._smallFont, XBrushes.Black, xInit + 120, yInit + 25 + report._lineGap, XStringFormat.TopLeft); graphics.DrawString("NL08ABNA0612626032", report._smallFontBold, XBrushes.Black, xInit + 200, yInit + 25 + report._lineGap, XStringFormat.TopLeft); graphics.DrawString("BIC:", report._smallFont, XBrushes.Black, xInit + 120, yInit + 25 + report._lineGap * 2, XStringFormat.TopLeft); graphics.DrawString("ABNANL2A", report._smallFontBold, XBrushes.Black, xInit + 200, yInit + 25 + report._lineGap * 2, XStringFormat.TopLeft); report.gfx.DrawImage(form, 28, 260); //print For payment please quote iid = invoiceId; form = new XForm(report.document, XUnit.FromMillimeter(1000), XUnit.FromMillimeter(400)); graphics = XGraphics.FromForm(form); xInit = 5; yInit = 5; graphics.DrawRectangle(XBrushes.Gray, 0, 0, 230, 20); graphics.DrawString(CulturalValues[3], report._smallFont, XBrushes.White, xInit, yInit, XStringFormat.TopLeft); graphics.DrawRectangle(new XSolidBrush(XColor.FromArgb(120, 204, 204, 204)), 0, 20, 230, 60); graphics.DrawString(CulturalValues[4], report._smallFont, XBrushes.Black, 5, yInit + 25, XStringFormat.TopLeft); graphics.DrawString(dtHead.Rows[0]["customerid"].ToString().Trim(), report._smallFontBold, XBrushes.Black, xInit + 100, yInit + 25, XStringFormat.TopLeft); graphics.DrawString(CulturalValues[5], report._smallFont, XBrushes.Black, 5, yInit + 25 + report._lineGap, XStringFormat.TopLeft); graphics.DrawString(invoiceId, report._smallFontBold, XBrushes.Black, xInit + 100, yInit + 25 + report._lineGap, XStringFormat.TopLeft); graphics.DrawString(CulturalValues[6], report._smallFont, XBrushes.Black, 5, yInit + 25 + report._lineGap * 2, XStringFormat.TopLeft); string s = dtHead.Rows[0]["invoicedate"].ToString(); graphics.DrawString(s, report._smallFontBold, XBrushes.Black, xInit + 100, yInit + 25 + report._lineGap * 2, XStringFormat.TopLeft); graphics.DrawRectangle(report._borderPen, 0, 0, 230, 80); report.gfx.DrawImage(form, 333, 260); //VAT basis + VAT amount form = new XForm(report.document, XUnit.FromMillimeter(1000), XUnit.FromMillimeter(400)); graphics = XGraphics.FromForm(form); xInit = 5; yInit = 5; double seg_width = 70; XTextFormatter tf = new XTextFormatter(graphics); graphics.DrawRectangle(XBrushes.Gray, 0, 0, 230, 20); graphics.DrawString(CulturalValues[7], report._smallFont, XBrushes.White, 98, yInit, XStringFormat.TopLeft); graphics.DrawString(CulturalValues[8], report._smallFont, XBrushes.White, 180, yInit, XStringFormat.TopLeft); graphics.DrawRectangle(new XSolidBrush(XColor.FromArgb(120, 204, 204, 204)), 0, 20, seg_width, 60); graphics.DrawRectangle(new XSolidBrush(XColor.FromArgb(80, 204, 204, 204)), seg_width, 20, seg_width, 60); graphics.DrawRectangle(new XSolidBrush(XColor.FromArgb(120, 204, 204, 204)), seg_width * 2, 20, 90, 60); graphics.DrawString(CulturalValues[9], report._smallFont, XBrushes.Black, 5, yInit + 25, XStringFormat.TopLeft); XRect rec = new XRect(seg_width, yInit + 25, 65, 20); tf.Alignment = XParagraphAlignment.Right; if (!dtHead.Rows[0]["customerbtwnr"].ToString().Equals("")) { Double vatBasis = double.Parse(dtPrice.Rows[0]["price0"].ToString()) + double.Parse(dtPrice.Rows[0]["price6"].ToString()) + double.Parse(dtPrice.Rows[0]["price19"].ToString()); tf.DrawString("€".PadRight(25), report._smallFont, XBrushes.Black, rec); tf.DrawString(vatBasis.ToString("N2"), report._smallFont, XBrushes.Black, rec); rec = new XRect(seg_width * 2, yInit + 25, 85, 20); tf.DrawString("€".PadRight(25), report._smallFont, XBrushes.Black, rec); tf.DrawString("0.00", report._smallFont, XBrushes.Black, rec); graphics.DrawString(CulturalValues[10], report._smallFont, XBrushes.Black, 5, yInit + 25 + report._lineGap, XStringFormat.TopLeft); rec = new XRect(seg_width, yInit + 25 + report._lineGap, 65, 20); tf.DrawString("€".PadRight(25), report._smallFont, XBrushes.Black, rec); tf.DrawString("0.00", report._smallFont, XBrushes.Black, rec); rec = new XRect(seg_width * 2, yInit + 25 + report._lineGap, 85, 20); tf.DrawString("€".PadRight(25), report._smallFont, XBrushes.Black, rec); tf.DrawString("0.00", report._smallFont, XBrushes.Black, rec); graphics.DrawString(CulturalValues[11], report._smallFont, XBrushes.Black, 5, yInit + 25 + report._lineGap * 2, XStringFormat.TopLeft); rec = new XRect(seg_width, yInit + 25 + report._lineGap * 2, 65, 20); tf.DrawString("€".PadRight(25), report._smallFont, XBrushes.Black, rec); tf.DrawString("0.00", report._smallFont, XBrushes.Black, rec); rec = new XRect(seg_width * 2, yInit + 25 + report._lineGap * 2, 85, 20); tf.DrawString("€".PadRight(25), report._smallFont, XBrushes.Black, rec); tf.DrawString("0.00", report._smallFont, XBrushes.Black, rec); graphics.DrawString(CulturalValues[12], report._smallFont, XBrushes.Black, 5, yInit + 25 + report._lineGap * 4, XStringFormat.TopLeft); graphics.DrawString(dtHead.Rows[0]["customerbtwnr"].ToString(), report._smallFont, XBrushes.Black, 100, yInit + 25 + report._lineGap * 4, XStringFormat.TopLeft); } else { tf.DrawString("€".PadRight(25), report._smallFont, XBrushes.Black, rec); tf.DrawString(double.Parse(dtPrice.Rows[0]["price0"].ToString()).ToString("N2"), report._smallFont, XBrushes.Black, rec); rec = new XRect(seg_width * 2, yInit + 25, 85, 20); tf.DrawString("€".PadRight(25), report._smallFont, XBrushes.Black, rec); tf.DrawString(double.Parse(dtVat.Rows[0]["vat0"].ToString()).ToString("N2"), report._smallFont, XBrushes.Black, rec); graphics.DrawString(CulturalValues[10], report._smallFont, XBrushes.Black, 5, yInit + 25 + report._lineGap, XStringFormat.TopLeft); rec = new XRect(seg_width, yInit + 25 + report._lineGap, 65, 20); tf.DrawString("€".PadRight(25), report._smallFont, XBrushes.Black, rec); tf.DrawString(double.Parse(dtPrice.Rows[0]["price6"].ToString()).ToString("N2"), report._smallFont, XBrushes.Black, rec); rec = new XRect(seg_width * 2, yInit + 25 + report._lineGap, 85, 20); tf.DrawString("€".PadRight(25), report._smallFont, XBrushes.Black, rec); tf.DrawString(double.Parse(dtVat.Rows[0]["vat6"].ToString()).ToString("N2"), report._smallFont, XBrushes.Black, rec); graphics.DrawString(CulturalValues[11], report._smallFont, XBrushes.Black, 5, yInit + 25 + report._lineGap * 2, XStringFormat.TopLeft); rec = new XRect(seg_width, yInit + 25 + report._lineGap * 2, 65, 20); tf.DrawString("€".PadRight(25), report._smallFont, XBrushes.Black, rec); tf.DrawString(double.Parse(dtPrice.Rows[0]["price19"].ToString()).ToString("N2"), report._smallFont, XBrushes.Black, rec); rec = new XRect(seg_width * 2, yInit + 25 + report._lineGap * 2, 85, 20); tf.DrawString("€".PadRight(25), report._smallFont, XBrushes.Black, rec); tf.DrawString(double.Parse(dtVat.Rows[0]["vat19"].ToString()).ToString("N2"), report._smallFont, XBrushes.Black, rec); //graphics.DrawString(CulturalValues[12], report._smallFont, XBrushes.Black, 5, yInit + 25 + report._lineGap * 4, XStringFormat.TopLeft); //graphics.DrawString(dtHead.Rows[0]["customerbtwnr"].ToString(), report._smallFont, XBrushes.Black, 100, yInit + 25 + report._lineGap * 4, XStringFormat.TopLeft); } //report.gfx.DrawImage(form, 28, 720); //Page Number //string Show_page = "Page "+ s +" of "+seg_width +"."; totalpage = dtPage.Rows[0]["page"].ToString(); if (Convert.ToInt32(totalpage) >= 1) { pagenumber = 1; } string Show_page = "Page " + pagenumber + " of " + totalpage + " (" + invoiceId + ")."; pagenumber += 1; //graphics.DrawString(Show_page, report._smallFont, XBrushes.Black, 5, yInit + 25 + report._lineGap * 4, XStringFormat.TopLeft); graphics.DrawString(Show_page, report._smallFont, XBrushes.Black, 5, yInit + 90, XStringFormat.TopLeft); report.gfx.DrawImage(form, 28, 710); //if (dtHead.Rows[0]["customerbtwnr"].ToString().Equals("")) //Sub Total form = new XForm(report.document, XUnit.FromMillimeter(1000), XUnit.FromMillimeter(400)); graphics = XGraphics.FromForm(form); tf = new XTextFormatter(graphics); tf.Alignment = XParagraphAlignment.Right; xInit = 5; yInit = 5; graphics.DrawRectangle(XBrushes.Gray, 0, 0, 230, 20); graphics.DrawString(CulturalValues[13], report._smallFont, XBrushes.White, xInit, yInit, XStringFormat.TopLeft); graphics.DrawRectangle(new XSolidBrush(XColor.FromArgb(80, 204, 204, 204)), 100, 20, 130, 60); graphics.DrawString(CulturalValues[14], report._smallFont, XBrushes.Black, 5, yInit + 25, XStringFormat.TopLeft); graphics.DrawString(CulturalValues[26], report._smallFont, XBrushes.Black, 5, yInit + 25 + report._lineGap, XStringFormat.TopLeft); //graphics.DrawString("VAT: ", report._smallFontBold, XBrushes.Black, 5, yInit + 25 + report._lineGap, XStringFormat.TopLeft); graphics.DrawString(CulturalValues[16], report._smallFontBold, XBrushes.Black, 5, yInit + 25 + report._lineGap * 2, XStringFormat.TopLeft); rec = new XRect(100, yInit + 25, 100, 20); tf.DrawString("€".PadRight(25), report._smallFont, XBrushes.Black, rec); tf.DrawString(subTotal.ToString("N2"), report._smallFont, XBrushes.Black, rec); rec = new XRect(100, yInit + 25 + report._lineGap, 100, 20); tf.DrawString("€".PadRight(25), report._smallFont, XBrushes.Black, rec); if (!dtHead.Rows[0]["customerbtwnr"].ToString().Equals("")) { tf.DrawString("0.00", report._smallFont, XBrushes.Black, rec); } else { tf.DrawString(totalVat.ToString("N2"), report._smallFont, XBrushes.Black, rec); } rec = new XRect(100, yInit + 25 + report._lineGap * 2, 100, 20); tf.DrawString("€".PadRight(25), report._smallFontBold, XBrushes.Black, rec); tf.DrawString(invoiceTotal.ToString("N2"), report._smallFontBold, XBrushes.Black, rec); graphics.DrawString(CulturalValues[17], report._verySmallFont, XBrushes.Black, 115, yInit + 25 + report._lineGap * 3, XStringFormat.TopLeft); graphics.DrawString(CulturalValues[18], report._smallFont, XBrushes.Black, 5, yInit + 25 + report._lineGap * 4, XStringFormat.TopLeft); System.Globalization.CultureInfo enUS = new System.Globalization.CultureInfo("en-US", true); System.Globalization.DateTimeFormatInfo dtfi = new System.Globalization.DateTimeFormatInfo(); dtfi.ShortDatePattern = "dd-MM-yyyy"; dtfi.DateSeparator = "-"; DateTime dtIn = Convert.ToDateTime(s, dtfi); dtIn = dtIn.AddDays(14); graphics.DrawString(dtIn.ToString("dd-MM-yyyy"), report._smallFont, XBrushes.Black, 115, yInit + 25 + report._lineGap * 4, XStringFormat.TopLeft); graphics.DrawRectangle(report._borderPen, 0, 0, 230, 80); report.gfx.DrawImage(form, 333, 710); //Populate Article Details double[] colWidth = { 50, 220, 40, 60, 55, 60, 50 }; //string[] colName = {"Article ID", "Description", "Quantity", "Retail Price", "Discount", "Net Price", "VAT" }; form = new XForm(report.document, XUnit.FromMillimeter(1000), XUnit.FromMillimeter(400)); graphics = XGraphics.FromForm(form); PrintArticleDetail(colWidth, ref form, dtBody); report.gfx.DrawImage(form, 28, 350); }
public override void RenderPage(XGraphics gfx) { #if true_ // Create a new PDF document //PdfDocument document = new PdfDocument(); // Create a font XFont font = new XFont("Verdana", 16); // Create a new page //PdfPage page = document.AddPage(); //XGraphics gfx = XGraphics.FromPdfPage(page); //gfx.DrawString("XPdfForm Sample", font, XBrushes.DarkGray, 15, 25, XStringFormat.Default); // Step 1: Create an XForm and draw some graphics on it // Create an empty XForm object with the specified width and height // A form is bound to its target document when it is created. The reason is that the form can // share fonts and other objects with its target document. XForm form = new XForm(gfx, XUnit.FromMillimeter(70), XUnit.FromMillimeter(55)); // Create an XGraphics object for drawing the contents of the form. XGraphics formGfx = XGraphics.FromForm(form); // Draw a large transparent rectangle to visualize the area the form occupies XColor back = XColors.Orange; back.A = 0.2; XSolidBrush brush = new XSolidBrush(back); formGfx.DrawRectangle(brush, -10000, -10000, 20000, 20000); // On a form you can draw... //// ... text //formGfx.DrawString("Text, Graphics, Images, and Forms", new XFont("Verdana", 10, XFontStyle.Regular), XBrushes.Navy, 3, 0, XStringFormat.TopLeft); //XPen pen = XPens.LightBlue.Clone(); //pen.Width = 2.5; // ... graphics like Bézier curves //formGfx.DrawBeziers(pen, XPoint.ParsePoints("30,120 80,20, 100,140 175,33.3")); //// ... raster images like GIF files //XGraphicsState state = formGfx.Save(); //formGfx.RotateAtTransform(17, new XPoint(30, 30)); //formGfx.DrawImage(XImage.FromFile("../../../../XGraphicsLab/images/Test.gif"), 20, 20); //formGfx.Restore(state); //// ... and forms like XPdfForm objects //state = formGfx.Save(); //formGfx.RotateAtTransform(-8, new XPoint(165, 115)); //formGfx.DrawImage(XPdfForm.FromFile("../../../../PDFs/SomeLayout.pdf"), new XRect(140, 80, 50, 50 * Math.Sqrt(2))); //formGfx.Restore(state); // When you finished drawing on the form, dispose the XGraphic object. formGfx.Dispose(); // Step 2: Draw the XPdfForm on your PDF page like an image // Draw the form on the page of the document in its original size gfx.DrawImage(form, 20, 50); #if true_ // Draw it stretched gfx.DrawImage(form, 300, 100, 250, 40); // Draw and rotate it int d = 25; for (int idx = 0; idx < 360; idx += d) { gfx.DrawImage(form, 300, 480, 200, 200); gfx.RotateAtTransform(d, new XPoint(300, 480)); } #endif //// Save the document... //string filename = "XForms.pdf"; //document.Save(filename); //// ...and start a viewer. //Process.Start(filename); #else //base.RenderPage(gfx); int cx = 300; int cy = 240; XForm form; //if (gfx.PdfPage == null) form = new XForm(gfx, cx, cy); //else // form = new XForm(gfx.PdfPage.Owner, cx, cy); double dx = gfx.PageSize.Width; double dy = gfx.PageSize.Height; XGraphics formgfx = XGraphics.FromForm(form); XSolidBrush brush = new XSolidBrush(XColor.FromArgb(128, 0, 255, 255)); formgfx.DrawRectangle(brush, -1000, -1000, 2000, 2000); formgfx.DrawLine(XPens.Red, 0, 0, cx, cy); formgfx.DrawLine(XPens.Red, cx, 0, 0, cy); XFont font = new XFont("Times", 16, XFontStyle.BoldItalic); formgfx.DrawString("Text", font, XBrushes.DarkOrange, 0, 0, XStringFormats.TopLeft); formgfx.DrawString("Text", font, XBrushes.DarkOrange, new XRect(0, 0, cx, cy), XStringFormats.Center); // Required to finish drawing the form. Both cases are correct. #if true formgfx.Dispose(); #else form.DrawingFinished(); #endif gfx.DrawImage(form, 50, 50); #if true_ gfx.TranslateTransform(dx / 2, dy / 2); gfx.RotateTransform(-25); gfx.TranslateTransform(-dx / 2, -dy / 2); gfx.DrawImage(form, (dx - form.Width) / 2, (dy - form.Height) / 2, form.Width, form.Height); #endif #endif }
/// <summary> /// Creates the normal appearance form X object for the annotation that represents /// this acro form text field. /// </summary> void RenderAppearance() { if (string.IsNullOrEmpty(Text)) { Elements.Remove(PdfAnnotation.Keys.AP); return; } #if true_ PdfFormXObject xobj = new PdfFormXObject(Owner); Owner.Internals.AddObject(xobj); xobj.Elements["/BBox"] = new PdfLiteral("[0 0 122.653 12.707]"); xobj.Elements["/FormType"] = new PdfLiteral("1"); xobj.Elements["/Matrix"] = new PdfLiteral("[1 0 0 1 0 0]"); PdfDictionary res = new PdfDictionary(Owner); xobj.Elements["/Resources"] = res; res.Elements["/Font"] = new PdfLiteral("<< /Helv 28 0 R >> /ProcSet [/PDF /Text]"); xobj.Elements["/Subtype"] = new PdfLiteral("/Form"); xobj.Elements["/Type"] = new PdfLiteral("/XObject"); string s = "/Tx BMC " + '\n' + "q" + '\n' + "1 1 120.653 10.707 re" + '\n' + "W" + '\n' + "n" + '\n' + "BT" + '\n' + "/Helv 7.93 Tf" + '\n' + "0 g" + '\n' + "2 3.412 Td" + '\n' + "(Hello ) Tj" + '\n' + "20.256 0 Td" + '\n' + "(XXX) Tj" + '\n' + "ET" + '\n' + "Q" + '\n' + "";//"EMC"; int length = s.Length; byte[] stream = new byte[length]; for (int idx = 0; idx < length; idx++) { stream[idx] = (byte)s[idx]; } xobj.CreateStream(stream); // Get existing or create new appearance dictionary PdfDictionary ap = Elements[PdfAnnotation.Keys.AP] as PdfDictionary; if (ap == null) { ap = new PdfDictionary(_document); Elements[PdfAnnotation.Keys.AP] = ap; } // Set XRef to normal state ap.Elements["/N"] = xobj.Reference; //// HACK //string m = //"<?xpacket begin=\"\" id=\"W5M0MpCehiHzreSzNTczkc9d\"?>" + '\n' + //"<x:xmpmeta xmlns:x=\"adobe:ns:meta/\" x:xmptk=\"Adobe XMP Core 4.0-c321 44.398116, Tue Aug 04 2009 14:24:39\"> " + '\n' + //" <rdf:RDF xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\"> " + '\n' + //" <rdf:Description rdf:about=\"\" " + '\n' + //" xmlns:pdf=\"http://ns.adobe.com/pdf/1.3/\"> " + '\n' + //" <pdf:Producer>PDFsharp 1.40.2150-g (www.PdfSharp.com) (Original: Powered By Crystal)</pdf:Producer> " + '\n' + //" </rdf:Description> " + '\n' + //" <rdf:Description rdf:about=\"\" " + '\n' + //" xmlns:xap=\"http://ns.adobe.com/xap/1.0/\"> " + '\n' + //" <xap:ModifyDate>2011-07-11T23:15:09+02:00</xap:ModifyDate> " + '\n' + //" <xap:CreateDate>2011-05-19T16:26:51+03:00</xap:CreateDate> " + '\n' + //" <xap:MetadataDate>2011-07-11T23:15:09+02:00</xap:MetadataDate> " + '\n' + //" <xap:CreatorTool>Crystal Reports</xap:CreatorTool> " + '\n' + //" </rdf:Description> " + '\n' + //" <rdf:Description rdf:about=\"\" " + '\n' + //" xmlns:dc=\"http://purl.org/dc/elements/1.1/\"> " + '\n' + //" <dc:format>application/pdf</dc:format> " + '\n' + //" </rdf:Description> " + '\n' + //" <rdf:Description rdf:about=\"\" " + '\n' + //" xmlns:xapMM=\"http://ns.adobe.com/xap/1.0/mm/\"> " + '\n' + //" <xapMM:DocumentID>uuid:68249d89-baed-4384-9a2d-fbf8ace75c45</xapMM:DocumentID> " + '\n' + //" <xapMM:InstanceID>uuid:3d5f2f46-c140-416f-baf2-7f9c970cef1d</xapMM:InstanceID> " + '\n' + //" </rdf:Description> " + '\n' + //" </rdf:RDF> " + '\n' + //"</x:xmpmeta> " + '\n' + //" " + '\n' + //" " + '\n' + //" " + '\n' + //" " + '\n' + //" " + '\n' + //" " + '\n' + //" " + '\n' + //" " + '\n' + //" " + '\n' + //" " + '\n' + //"<?xpacket end=\"w\"?>"; //PdfDictionary mdict = (PdfDictionary)_document.Internals.GetObject(new PdfObjectID(32)); //length = m.Length; //stream = new byte[length]; //for (int idx = 0; idx < length; idx++) // stream[idx] = (byte)m[idx]; //mdict.Stream.Value = stream; #else PdfRectangle rect = Elements.GetRectangle(PdfAnnotation.Keys.Rect); XForm form = new XForm(_document, rect.Size); XGraphics gfx = XGraphics.FromForm(form); XRect xrect = (rect.ToXRect() - rect.Location); if (BackColor != XColor.Empty) { gfx.DrawRectangle(new XSolidBrush(BackColor), rect.ToXRect() - rect.Location); } // Draw Border if (!BorderColor.IsEmpty) { gfx.DrawRectangle(new XPen(BorderColor), rect.ToXRect() - rect.Location); } string text = Text; if (text.Length > 0) { xrect.Y = xrect.Y + TopMargin; xrect.X = xrect.X + LeftMargin; xrect.Width = xrect.Width + RightMargin; xrect.Height = xrect.Height + BottomMargin; if ((Flags & PdfAcroFieldFlags.Comb) != 0 && MaxLength > 0) { var combWidth = xrect.Width / MaxLength; var format = XStringFormats.TopLeft; format.Comb = true; format.CombWidth = combWidth; gfx.Save(); gfx.IntersectClip(xrect); if (this.MultiLine) { XTextFormatter formatter = new XTextFormatter(gfx); formatter.Text = text; formatter.DrawString(Text, Font, new XSolidBrush(ForeColor), xrect, Alignment); } else { gfx.DrawString(text, Font, new XSolidBrush(ForeColor), xrect + new XPoint(0, 1.5), format); } gfx.Restore(); } else { XTextFormatter formatter = new XTextFormatter(gfx); formatter.Text = text; formatter.DrawString(text, Font, new XSolidBrush(ForeColor), rect.ToXRect() - rect.Location, Alignment); } } form.DrawingFinished(); form.PdfForm.Elements.Add("/FormType", new PdfLiteral("1")); // Get existing or create new appearance dictionary. PdfDictionary ap = Elements[PdfAnnotation.Keys.AP] as PdfDictionary; if (ap == null) { ap = new PdfDictionary(_document); Elements[PdfAnnotation.Keys.AP] = ap; } // Set XRef to normal state ap.Elements["/N"] = PdfObject.DeepCopyClosure(Owner, form.PdfForm); var normalStateDict = ap.Elements.GetDictionary("/N"); var resourceDict = new PdfDictionary(Owner); resourceDict.Elements[PdfResources.Keys.ProcSet] = new PdfArray(Owner, new PdfName("/PDF"), new PdfName("/Text")); var defaultFormResources = Owner.AcroForm.Elements.GetDictionary(PdfAcroForm.Keys.DR); if (defaultFormResources != null && defaultFormResources.Elements.ContainsKey(PdfResources.Keys.Font)) { var fontResourceItem = XForm.GetFontResourceItem(Font.FamilyName, defaultFormResources); PdfDictionary fontDict = new PdfDictionary(Owner); resourceDict.Elements[PdfResources.Keys.Font] = fontDict; fontDict.Elements[fontResourceItem.Key] = fontResourceItem.Value; } normalStateDict.Elements.SetObject(PdfPage.Keys.Resources, resourceDict); PdfFormXObject xobj = form.PdfForm; if (xobj.Stream == null) { xobj.CreateStream(new byte[] { }); } string s = xobj.Stream.ToString(); // Thank you Adobe: Without putting the content in 'EMC brackets' // the text is not rendered by PDF Reader 9 or higher. s = "/Tx BMC\n" + s + "\nEMC"; ap.Elements.GetDictionary("/N").Stream.Value = new RawEncoding().GetBytes(s); #endif }
private void Button(object sender, RoutedEventArgs e) { ChartLayer1.Width = 350; // Create a new PDF document var document = new PdfDocument(); // Create an empty page var page = document.AddPage(); // Get an XGraphics object for drawing var gfx = XGraphics.FromPdfPage(page); var options = new XPdfFontOptions(PdfFontEncoding.Unicode, PdfFontEmbedding.Always); // Create a font var font = new XFont("Verdana", 16, XFontStyle.BoldItalic, options); // Draw the text gfx.DrawString(@"Состояние дорожного покрытия", font, XBrushes.Black, new XRect(0, 20, page.Width, page.Height), XStringFormats.TopCenter); var fonttext = new XFont("Times New Roman", 14, XFontStyle.Regular, options); gfx.DrawString("Название дороги:", fonttext, XBrushes.Black, new XRect(30, 60, page.Width, page.Height), XStringFormats.TopLeft); gfx.DrawString(Info.RoadName, fonttext, XBrushes.Black, new XRect(230, 60, page.Width, page.Height), XStringFormats.TopLeft); gfx.DrawString("Номер измерения:", fonttext, XBrushes.Black, new XRect(30, 75, page.Width, page.Height), XStringFormats.TopLeft); gfx.DrawString(Info.NumMess.ToString(), fonttext, XBrushes.Black, new XRect(230, 75, page.Width, page.Height), XStringFormats.TopLeft); gfx.DrawString("Дата проведения измерения:", fonttext, XBrushes.Black, new XRect(30, 90, page.Width, page.Height), XStringFormats.TopLeft); gfx.DrawString(Info.TimeStart, fonttext, XBrushes.Black, new XRect(230, 90, page.Width, page.Height), XStringFormats.TopLeft); gfx.DrawString("Общая протяженность участка:", fonttext, XBrushes.Black, new XRect(30, 105, page.Width, page.Height), XStringFormats.TopLeft); //gfx.DrawLine(XPens.Black, 0, 120, page.Width, 120); gfx.DrawString(Distance + " м", fonttext, XBrushes.Black, new XRect(230, 105, page.Width, page.Height), XStringFormats.TopLeft); //var sPdfFileName = Path.GetTempPath() + "PDFFile.pdf"; var imageAll = Path.GetTempPath() + "allgraf.png"; var imageGen = Path.GetTempPath() + "general.png"; var imageLay1 = Path.GetTempPath() + "layer1.png"; var imageLay2 = Path.GetTempPath() + "layer2.png"; var imageLay3 = Path.GetTempPath() + "layer3.png"; var imagePlotn = Path.GetTempPath() + "density.png"; var imageCount = Path.GetTempPath() + "count.png"; //Вызываем метод, чтобы сохранить график SaveAsPng(GetImage(GridAll), imageAll); SaveAsPng(GetImage(GridGen), imageGen); SaveAsPng(GetImage(GridLay1), imageLay1); SaveAsPng(GetImage(GridLay2), imageLay2); SaveAsPng(GetImage(GridLay3), imageLay3); SaveAsPng(GetImage(GridPlotn), imagePlotn); SaveAsPng(GetImage(GridCount), imageCount); //CreatePdfFromImage(sImagePath, sPdfFileName); var form = new XForm(document, XUnit.FromMillimeter(1500), XUnit.FromMillimeter(1600)); // Create an XGraphics object for drawing the contents of the form. var formGfx = XGraphics.FromForm(form); // Draw a large transparent rectangle to visualize the area the form occupies //var back = XColors.Orange; //var brush = new XSolidBrush(back); //formGfx.DrawRectangle(brush, -300, -300, 300, 300); //var state = formGfx.Save(); formGfx.DrawImage(XImage.FromFile(imageGen), 180, -4); formGfx.DrawImage(XImage.FromFile(imageCount), 35, 170); formGfx.DrawImage(XImage.FromFile(imageAll), 350, 170); formGfx.DrawImage(XImage.FromFile(imageLay3), 35, 390); formGfx.DrawImage(XImage.FromFile(imageLay2), 350, 390); formGfx.DrawImage(XImage.FromFile(imageLay1), 35, 600); formGfx.DrawImage(XImage.FromFile(imagePlotn), 350, 600); //formGfx.Restore(state); formGfx.Dispose(); // Draw the form on the page of the document in its original size gfx.DrawImage(form, 10, 130, 3600, 3800); //DrawImage(gfx, sImagePath, 50, 50, 250, 250); // Show save file dialog box var dlg = new SaveFileDialog { FileName = "Report", DefaultExt = ".text", Filter = "Text documents (.pdf)|*.pdf" }; var result = dlg.ShowDialog(); // Process save file dialog box results if (result == true) { // Save document var filename1 = dlg.FileName; using (var stm = File.Create(filename1)) { document.Save(stm); } Process.Start(filename1); } }
/// <summary> /// This method will print the Article detail table with appropriate /// column header according to the template /// </summary> /// <param name="colwidth">different column width</param> /// <param name="form">Supplied XForm</param> /// <param name="dtArticle">supplied datatable containing article information</param> private void PrintArticleDetail(double[] colwidth, ref XForm form, DataTable dtArticle) { XGraphics graphics = XGraphics.FromForm(form); XTextFormatter tf = new XTextFormatter(graphics); XTextFormatter tf1 = new XTextFormatter(graphics); XRect rec; int pagecounter = 0; double left = 0, top = 0; // Print header for (int index = 0; index < colwidth.Length; index++) { rec = new XRect(left, top, colwidth[index], 19); /*if (index % 2 == 0) * { * graphics.DrawRectangle(new XSolidBrush(XColor.FromArgb(120, 204, 204, 204)), rec); * } * else * {*/ graphics.DrawRectangle(XBrushes.Gray, rec); //} string header = dtArticle.Columns[index].ColumnName; int count = header.Length; if (dtArticle.Columns[index].DataType.FullName.Equals("System.String")) { tf.Alignment = XParagraphAlignment.Left; tf.DrawString(header.PadLeft(count + 3), report._smallFontBold, XBrushes.White, rec); } else { tf.Alignment = XParagraphAlignment.Center; tf.DrawString(header.PadRight(count + 3), report._smallFontBold, XBrushes.White, rec); } left += colwidth[index]; } //print Articles foreach (DataRow row in dtArticle.Rows) { pagecounter++; top += 20; left = 0; if (pagecounter % 15 == 0) { //top = -500; //report.document.AddPage(); report.gfx.DrawImage(form, 28, 350); top = 0; PdfPage page = new PdfPage(); page = report.document.Pages.Add(); report.gfx = XGraphics.FromPdfPage(page); form = new XForm(report.document, XUnit.FromMillimeter(1000), XUnit.FromMillimeter(400)); graphics = XGraphics.FromForm(form); tf = new XTextFormatter(graphics); tf1 = new XTextFormatter(graphics); //Print Invoice XForm form1 = new XForm(report.document, XUnit.FromMillimeter(1000), XUnit.FromMillimeter(400)); XGraphics graphics1 = XGraphics.FromForm(form1); double xInit = 0, yInit = 0; graphics1.DrawString(CulturalValues[0], report._largeFontBold, XBrushes.Black, xInit, yInit, XStringFormat.TopLeft); report.gfx.DrawImage(form1, 450, 40); // Print Customer Address form1 = new XForm(report.document, XUnit.FromMillimeter(1000), XUnit.FromMillimeter(400)); graphics1 = XGraphics.FromForm(form1); xInit = 95; yInit = 20; //graphics.DrawRectangle(report._borderPen, 0, 0, 300, 100); graphics1.DrawString(dthead1.Rows[0]["companyname"].ToString().Trim(), report._normalFont, XBrushes.Black, xInit, yInit - report._lineGap, XStringFormat.TopLeft); graphics1.DrawString(dthead1.Rows[0]["customer"].ToString().Trim(), report._normalFont, XBrushes.Black, xInit, yInit, XStringFormat.TopLeft); graphics1.DrawString(dthead1.Rows[0]["address"].ToString() + " " + dthead1.Rows[0]["housenr"].ToString(), report._normalFont, XBrushes.Black, xInit, yInit + report._lineGap, XStringFormat.TopLeft); graphics1.DrawString(dthead1.Rows[0]["postcode"].ToString() + " " + dthead1.Rows[0]["residence"].ToString(), report._normalFont, XBrushes.Black, xInit, yInit + report._lineGap * 2, XStringFormat.TopLeft); graphics1.DrawString(dthead1.Rows[0]["country"].ToString(), report._normalFont, XBrushes.Black, xInit, yInit + report._lineGap * 3, XStringFormat.TopLeft); report.gfx.DrawImage(form1, 245, 130); // Print Our VAT No + Bankaccount details form1 = new XForm(report.document, XUnit.FromMillimeter(1000), XUnit.FromMillimeter(400)); graphics1 = XGraphics.FromForm(form1); xInit = 5; yInit = 5; graphics1.DrawRectangle(XBrushes.Gray, 0, 0, 300, 20); graphics1.DrawString(CulturalValues[1], report._smallFont, XBrushes.White, xInit, yInit, XStringFormat.TopLeft); graphics1.DrawString(CulturalValues[2], report._smallFont, XBrushes.White, xInit + 120, yInit, XStringFormat.TopLeft); graphics1.DrawRectangle(new XSolidBrush(XColor.FromArgb(120, 204, 204, 204)), 0, 20, xInit + 115, 60); graphics1.DrawString("NL006012152B01", report._smallFontBold, XBrushes.Black, 5, yInit + 25, XStringFormat.TopLeft); graphics1.DrawRectangle(new XSolidBrush(XColor.FromArgb(80, 204, 204, 204)), xInit + 115, 20, 180, 60); graphics1.DrawString("ABNAMRO:", report._smallFont, XBrushes.Black, xInit + 120, yInit + 25, XStringFormat.TopLeft); graphics1.DrawString("61 26 26 032", report._smallFontBold, XBrushes.Black, xInit + 200, yInit + 25, XStringFormat.TopLeft); graphics1.DrawString("IBAN:", report._smallFont, XBrushes.Black, xInit + 120, yInit + 25 + report._lineGap, XStringFormat.TopLeft); graphics1.DrawString("NL08ABNA0612626032", report._smallFontBold, XBrushes.Black, xInit + 200, yInit + 25 + report._lineGap, XStringFormat.TopLeft); graphics1.DrawString("BIC:", report._smallFont, XBrushes.Black, xInit + 120, yInit + 25 + report._lineGap * 2, XStringFormat.TopLeft); graphics1.DrawString("ABNANL2A", report._smallFontBold, XBrushes.Black, xInit + 200, yInit + 25 + report._lineGap * 2, XStringFormat.TopLeft); report.gfx.DrawImage(form1, 28, 260); //print For payment please quote form1 = new XForm(report.document, XUnit.FromMillimeter(1000), XUnit.FromMillimeter(400)); graphics1 = XGraphics.FromForm(form1); xInit = 5; yInit = 5; graphics1.DrawRectangle(XBrushes.Gray, 0, 0, 230, 20); graphics1.DrawString(CulturalValues[3], report._smallFont, XBrushes.White, xInit, yInit, XStringFormat.TopLeft); graphics1.DrawRectangle(new XSolidBrush(XColor.FromArgb(120, 204, 204, 204)), 0, 20, 230, 60); graphics1.DrawString(CulturalValues[4], report._smallFont, XBrushes.Black, 5, yInit + 25, XStringFormat.TopLeft); graphics1.DrawString(dthead1.Rows[0]["customerid"].ToString().Trim(), report._smallFontBold, XBrushes.Black, xInit + 100, yInit + 25, XStringFormat.TopLeft); graphics1.DrawString(CulturalValues[5], report._smallFont, XBrushes.Black, 5, yInit + 25 + report._lineGap, XStringFormat.TopLeft); graphics1.DrawString(iid, report._smallFontBold, XBrushes.Black, xInit + 100, yInit + 25 + report._lineGap, XStringFormat.TopLeft); graphics1.DrawString(CulturalValues[6], report._smallFont, XBrushes.Black, 5, yInit + 25 + report._lineGap * 2, XStringFormat.TopLeft); string s = dthead1.Rows[0]["invoicedate"].ToString(); graphics1.DrawString(s, report._smallFontBold, XBrushes.Black, xInit + 100, yInit + 25 + report._lineGap * 2, XStringFormat.TopLeft); graphics1.DrawRectangle(report._borderPen, 0, 0, 230, 80); report.gfx.DrawImage(form1, 333, 260); form1 = new XForm(report.document, XUnit.FromMillimeter(1000), XUnit.FromMillimeter(400)); graphics1 = XGraphics.FromForm(form1); string Show_page = "Page " + pagenumber + " of " + totalpage + " (" + iid + ")."; pagenumber += 1; //graphics.DrawString(Show_page, report._smallFont, XBrushes.Black, 5, yInit + 25 + report._lineGap * 4, XStringFormat.TopLeft); graphics1.DrawString(Show_page, report._smallFont, XBrushes.Black, 5, yInit + 90, XStringFormat.TopLeft); report.gfx.DrawImage(form1, 28, 710); for (int index = 0; index < colwidth.Length; index++) { rec = new XRect(left, top, colwidth[index], 19); /*if (index % 2 == 0) * { * graphics.DrawRectangle(new XSolidBrush(XColor.FromArgb(120, 204, 204, 204)), rec); * } * else * {*/ graphics.DrawRectangle(XBrushes.Gray, rec); //} string header = dtArticle.Columns[index].ColumnName; int count = header.Length; if (dtArticle.Columns[index].DataType.FullName.Equals("System.String")) { tf.Alignment = XParagraphAlignment.Left; tf.DrawString(header.PadLeft(count + 3), report._smallFontBold, XBrushes.White, rec); } else { tf.Alignment = XParagraphAlignment.Center; tf.DrawString(header.PadRight(count + 3), report._smallFontBold, XBrushes.White, rec); } left += colwidth[index]; } left = 0; top += 20; //rec; //report.document.AddPage(page); //report.gfx = XGraphics.FromPdfPage(page, XGraphicsPdfPageOptions.Append); } for (int index = 0; index < colwidth.Length; index++) { //tf.Alignment = (dtArticle.Columns[index].DataType.FullName.Equals("System.String")) ? XParagraphAlignment.Left : XParagraphAlignment.Right; rec = new XRect(left, top, colwidth[index], 20); XRect rec1 = new XRect(left + 5, top, colwidth[index], 20); if (index % 2 == 0) { graphics.DrawRectangle(new XSolidBrush(XColor.FromArgb(120, 204, 204, 204)), rec); } else { graphics.DrawRectangle(new XSolidBrush(XColor.FromArgb(60, 204, 204, 204)), rec); } int count = row[index].ToString().Length; if (dtArticle.Columns[index].DataType.FullName.Equals("System.String")) { tf.Alignment = XParagraphAlignment.Left; //tf1.Alignment = XParagraphAlignment.Right; if (dtArticle.Columns[index].ToString().Equals(CulturalValues[19])) { tf.DrawString(row[index].ToString().PadLeft(count + 3), report._smallFont, XBrushes.Black, rec); } if (dtArticle.Columns[index].ToString().Equals(CulturalValues[20])) { if (row[index].ToString().Trim().Equals("Shipping and handling")) { if (CulturalValues[27] == "nl-NL") { tf.DrawString("Verzendkosten".ToString(), report._smallFont, XBrushes.Black, rec1); } else { tf.DrawString("Shipping and handling".ToString(), report._smallFont, XBrushes.Black, rec1); } } else { tf.DrawString(row[index].ToString() + " - " + row["Composer"].ToString(), report._smallFont, XBrushes.Black, rec1); } } } else { tf.Alignment = XParagraphAlignment.Right; tf.DrawString(row[index].ToString().PadRight(count + 3), report._smallFont, XBrushes.Black, rec); if (dtArticle.Columns[index].ToString().Equals(CulturalValues[22]) || dtArticle.Columns[index].ToString().Equals(CulturalValues[24])) { tf.DrawString("€".PadRight(22), report._smallFont, XBrushes.Black, rec); } } //tf.DrawString(row[index].ToString(), report._smallFont, XBrushes.Black, rec); left += colwidth[index]; } } }
/// <summary> /// Creates the normal appearance form X object for the annotation that represents /// this acro form text field. /// </summary> void RenderAppearance() { #if true_ PdfFormXObject xobj = new PdfFormXObject(Owner); Owner.Internals.AddObject(xobj); xobj.Elements["/BBox"] = new PdfLiteral("[0 0 122.653 12.707]"); xobj.Elements["/FormType"] = new PdfLiteral("1"); xobj.Elements["/Matrix"] = new PdfLiteral("[1 0 0 1 0 0]"); PdfDictionary res = new PdfDictionary(Owner); xobj.Elements["/Resources"] = res; res.Elements["/Font"] = new PdfLiteral("<< /Helv 28 0 R >> /ProcSet [/PDF /Text]"); xobj.Elements["/Subtype"] = new PdfLiteral("/Form"); xobj.Elements["/Type"] = new PdfLiteral("/XObject"); string s = "/Tx BMC " + '\n' + "q" + '\n' + "1 1 120.653 10.707 re" + '\n' + "W" + '\n' + "n" + '\n' + "BT" + '\n' + "/Helv 7.93 Tf" + '\n' + "0 g" + '\n' + "2 3.412 Td" + '\n' + "(Hello ) Tj" + '\n' + "20.256 0 Td" + '\n' + "(XXX) Tj" + '\n' + "ET" + '\n' + "Q" + '\n' + "";//"EMC"; int length = s.Length; byte[] stream = new byte[length]; for (int idx = 0; idx < length; idx++) { stream[idx] = (byte)s[idx]; } xobj.CreateStream(stream); // Get existing or create new appearance dictionary PdfDictionary ap = Elements[PdfAnnotation.Keys.AP] as PdfDictionary; if (ap == null) { ap = new PdfDictionary(_document); Elements[PdfAnnotation.Keys.AP] = ap; } // Set XRef to normal state ap.Elements["/N"] = xobj.Reference; //// HACK //string m = //"<?xpacket begin=\"\" id=\"W5M0MpCehiHzreSzNTczkc9d\"?>" + '\n' + //"<x:xmpmeta xmlns:x=\"adobe:ns:meta/\" x:xmptk=\"Adobe XMP Core 4.0-c321 44.398116, Tue Aug 04 2009 14:24:39\"> " + '\n' + //" <rdf:RDF xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\"> " + '\n' + //" <rdf:Description rdf:about=\"\" " + '\n' + //" xmlns:pdf=\"http://ns.adobe.com/pdf/1.3/\"> " + '\n' + //" <pdf:Producer>PDFsharp 1.40.2150-g (www.PdfSharpCore.com) (Original: Powered By Crystal)</pdf:Producer> " + '\n' + //" </rdf:Description> " + '\n' + //" <rdf:Description rdf:about=\"\" " + '\n' + //" xmlns:xap=\"http://ns.adobe.com/xap/1.0/\"> " + '\n' + //" <xap:ModifyDate>2011-07-11T23:15:09+02:00</xap:ModifyDate> " + '\n' + //" <xap:CreateDate>2011-05-19T16:26:51+03:00</xap:CreateDate> " + '\n' + //" <xap:MetadataDate>2011-07-11T23:15:09+02:00</xap:MetadataDate> " + '\n' + //" <xap:CreatorTool>Crystal Reports</xap:CreatorTool> " + '\n' + //" </rdf:Description> " + '\n' + //" <rdf:Description rdf:about=\"\" " + '\n' + //" xmlns:dc=\"http://purl.org/dc/elements/1.1/\"> " + '\n' + //" <dc:format>application/pdf</dc:format> " + '\n' + //" </rdf:Description> " + '\n' + //" <rdf:Description rdf:about=\"\" " + '\n' + //" xmlns:xapMM=\"http://ns.adobe.com/xap/1.0/mm/\"> " + '\n' + //" <xapMM:DocumentID>uuid:68249d89-baed-4384-9a2d-fbf8ace75c45</xapMM:DocumentID> " + '\n' + //" <xapMM:InstanceID>uuid:3d5f2f46-c140-416f-baf2-7f9c970cef1d</xapMM:InstanceID> " + '\n' + //" </rdf:Description> " + '\n' + //" </rdf:RDF> " + '\n' + //"</x:xmpmeta> " + '\n' + //" " + '\n' + //" " + '\n' + //" " + '\n' + //" " + '\n' + //" " + '\n' + //" " + '\n' + //" " + '\n' + //" " + '\n' + //" " + '\n' + //" " + '\n' + //"<?xpacket end=\"w\"?>"; //PdfDictionary mdict = (PdfDictionary)_document.Internals.GetObject(new PdfObjectID(32)); //length = m.Length; //stream = new byte[length]; //for (int idx = 0; idx < length; idx++) // stream[idx] = (byte)m[idx]; //mdict.Stream.Value = stream; #else PdfRectangle rect = Elements.GetRectangle(PdfAnnotation.Keys.Rect); XForm form = new XForm(_document, rect.Size); XGraphics gfx = XGraphics.FromForm(form); if (_backColor != XColor.Empty) { gfx.DrawRectangle(new XSolidBrush(BackColor), rect.ToXRect() - rect.Location); } string text = Text; if (text.Length > 0) { gfx.DrawString(Text, Font, new XSolidBrush(ForeColor), rect.ToXRect() - rect.Location + new XPoint(2, 0), XStringFormats.TopLeft); } form.DrawingFinished(); form.PdfForm.Elements.Add("/FormType", new PdfLiteral("1")); // Get existing or create new appearance dictionary. PdfDictionary ap = Elements[PdfAnnotation.Keys.AP] as PdfDictionary; if (ap == null) { ap = new PdfDictionary(_document); Elements[PdfAnnotation.Keys.AP] = ap; } // Set XRef to normal state ap.Elements["/N"] = form.PdfForm.Reference; PdfFormXObject xobj = form.PdfForm; if (xobj.Stream == null) { xobj.CreateStream(Encoding.ASCII.GetBytes(text)); } string s = xobj.Stream.ToString(); // Thank you Adobe: Without putting the content in 'EMC brackets' // the text is not rendered by PDF Reader 9 or higher. s = "/Tx BMC\n" + s + "\nEMC"; xobj.Stream.Value = new RawEncoding().GetBytes(s); #endif }
void RealizeLinearGradientBrush(LinearGradientBrush brush, XForm xform) { XMatrix matrix = currentTransform; PdfShadingPattern pattern = new PdfShadingPattern(writer.Owner); pattern.Elements[PdfShadingPattern.Keys.PatternType] = new PdfInteger(2); // shading pattern // Setup shading PdfShading shading = new PdfShading(writer.Owner); PdfColorMode colorMode = PdfColorMode.Rgb; //this.document.Options.ColorMode; PdfDictionary function = BuildShadingFunction(brush.GradientStops, colorMode); function.Elements.SetString("/@", "This is the shading function of a LinearGradientBrush"); shading.Elements[PdfShading.Keys.Function] = function; shading.Elements[PdfShading.Keys.ShadingType] = new PdfInteger(2); // Axial shading //if (colorMode != PdfColorMode.Cmyk) shading.Elements[PdfShading.Keys.ColorSpace] = new PdfName("/DeviceRGB"); //else //shading.Elements[Keys.ColorSpace] = new PdfName("/DeviceCMYK"); //double x1 = 0, y1 = 0, x2 = 0, y2 = 0; double x1 = brush.StartPoint.X; double y1 = brush.StartPoint.Y; double x2 = brush.EndPoint.X; double y2 = brush.EndPoint.Y; shading.Elements[PdfShading.Keys.Coords] = new PdfLiteral("[{0:0.###} {1:0.###} {2:0.###} {3:0.###}]", x1, y1, x2, y2); // old: Elements[Keys.Background] = new PdfRawItem("[0 1 1]"); // old: Elements[Keys.Domain] = shading.Elements[PdfShading.Keys.Extend] = new PdfLiteral("[true true]"); // Setup pattern pattern.Elements[PdfShadingPattern.Keys.Shading] = shading; pattern.Elements[PdfShadingPattern.Keys.Matrix] = PdfLiteral.FromMatrix(matrix); // new PdfLiteral("[" + PdfEncoders.ToString(matrix) + "]"); string name = writer.Resources.AddPattern(pattern); writer.WriteLiteral("/Pattern cs\n", name); writer.WriteLiteral("{0} scn\n", name); double alpha = brush.Opacity * brush.GradientStops.GetAverageAlpha(); if (alpha < 1 && writer.renderMode == RenderMode.Default) { #if true PdfExtGState extGState = writer.Owner.ExtGStateTable.GetExtGStateNonStroke(alpha); string gs = writer.Resources.AddExtGState(extGState); writer.WriteLiteral("{0} gs\n", gs); #else #if true if (xform == null) { PdfExtGState extGState = this.writer.Owner.ExtGStateTable.GetExtGStateNonStroke(alpha); string gs = this.writer.Resources.AddExtGState(extGState); this.writer.WriteGraphicState(extGState); } else { //PdfFormXObject pdfForm = this.writer.Owner.FormTable.GetForm(form); PdfFormXObject pdfForm = xform.pdfForm; pdfForm.Elements.SetString("/@", "This is the Form XObject of the soft mask"); string formName = this.writer.Resources.AddForm(pdfForm); PdfTransparencyGroupAttributes tgAttributes = new PdfTransparencyGroupAttributes(this.writer.Owner); //this.writer.Owner.Internals.AddObject(tgAttributes); tgAttributes.Elements.SetName(PdfTransparencyGroupAttributes.Keys.CS, "/DeviceRGB"); // Set reference to transparency group attributes pdfForm.Elements.SetObject(PdfFormXObject.Keys.Group, tgAttributes); pdfForm.Elements[PdfFormXObject.Keys.Matrix] = new PdfLiteral("[1.001 0 0 1.001 0.001 0.001]"); PdfSoftMask softmask = new PdfSoftMask(this.writer.Owner); this.writer.Owner.Internals.AddObject(softmask); softmask.Elements.SetString("/@", "This is the soft mask"); softmask.Elements.SetName(PdfSoftMask.Keys.S, "/Luminosity"); softmask.Elements.SetReference(PdfSoftMask.Keys.G, pdfForm); //pdfForm.Elements.SetName(PdfFormXObject.Keys.Type, "Group"); //pdfForm.Elements.SetName(PdfFormXObject.Keys.ss.Ss.Type, "Group"); PdfExtGState extGState = new PdfExtGState(this.writer.Owner); this.writer.Owner.Internals.AddObject(extGState); extGState.Elements.SetReference(PdfExtGState.Keys.SMask, softmask); this.writer.WriteGraphicState(extGState); } #else XForm form = new XForm(this.writer.Owner, 220, 140); XGraphics formGfx = XGraphics.FromForm(form); // draw something //XSolidBrush xbrush = new XSolidBrush(XColor.FromArgb(128, 128, 128)); XLinearGradientBrush xbrush = new XLinearGradientBrush(new XPoint(0, 0), new XPoint(220, 0), XColors.White, XColors.Black); formGfx.DrawRectangle(xbrush, -10000, -10000, 20000, 20000); //formGfx.DrawString("Text, Graphics, Images, and Forms", new XFont("Verdana", 10, XFontStyle.Regular), XBrushes.Navy, 3, 0, XStringFormat.TopLeft); formGfx.Dispose(); // Close form form.Finish(); PdfFormXObject pdfForm = this.writer.Owner.FormTable.GetForm(form); string formName = this.writer.Resources.AddForm(pdfForm); //double x = 20, y = 20; //double cx = 1; //double cy = 1; //this.writer.AppendFormat("q {2:0.###} 0 0 -{3:0.###} {0:0.###} {4:0.###} cm 100 Tz {5} Do Q\n", // x, y, cx, cy, y + 0, formName); //this.writer.AppendFormat("q {2:0.###} 0 0 -{3:0.###} {0:0.###} {4:0.###} cm 100 Tz {5} Do Q\n", // x, y, cx, cy, y + 220/1.5, formName); PdfTransparencyGroupAttributes tgAttributes = new PdfTransparencyGroupAttributes(this.writer.Owner); this.writer.Owner.Internals.AddObject(tgAttributes); tgAttributes.Elements.SetName(PdfTransparencyGroupAttributes.Keys.CS, "/DeviceRGB"); // Set reference to transparency group attributes pdfForm.Elements.SetReference(PdfFormXObject.Keys.Group, tgAttributes); PdfSoftMask softmask = new PdfSoftMask(this.writer.Owner); this.writer.Owner.Internals.AddObject(softmask); softmask.Elements.SetName(PdfSoftMask.Keys.S, "/Luminosity"); softmask.Elements.SetReference(PdfSoftMask.Keys.G, pdfForm); //pdfForm.Elements.SetName(PdfFormXObject.Keys.Type, "Group"); //pdfForm.Elements.SetName(PdfFormXObject.Keys.ss.Ss.Type, "Group"); PdfExtGState extGState = new PdfExtGState(this.writer.Owner); this.writer.Owner.Internals.AddObject(extGState); extGState.Elements.SetReference(PdfExtGState.Keys.SMask, softmask); this.writer.WriteGraphicState(extGState); #endif #endif } }
static void Main() { // Create a new PDF document PdfDocument document = new PdfDocument(); // Create a font XFont font = new XFont("Verdana", 16); // Create a new page PdfPage page = document.AddPage(); XGraphics gfx = XGraphics.FromPdfPage(page, XPageDirection.Downwards); gfx.DrawString("XPdfForm Sample", font, XBrushes.DarkGray, 15, 25, XStringFormats.Default); // Step 1: Create an XForm and draw some graphics on it // Create an empty XForm object with the specified width and height // A form is bound to its target document when it is created. The reason is that the form can // share fonts and other objects with its target document. XForm form = new XForm(document, XUnit.FromMillimeter(70), XUnit.FromMillimeter(55)); // Create an XGraphics object for drawing the contents of the form. XGraphics formGfx = XGraphics.FromForm(form); // Draw a large transparent rectangle to visualize the area the form occupies XColor back = XColors.Orange; back.A = 0.2; XSolidBrush brush = new XSolidBrush(back); formGfx.DrawRectangle(brush, -10000, -10000, 20000, 20000); // On a form you can draw... // ... text formGfx.DrawString("Text, Graphics, Images, and Forms", new XFont("Verdana", 10, XFontStyle.Regular), XBrushes.Navy, 3, 0, XStringFormats.TopLeft); XPen pen = XPens.LightBlue.Clone(); pen.Width = 2.5; // ... graphics like Bézier curves formGfx.DrawBeziers(pen, XPoint.ParsePoints("30,120 80,20 100,140 175,33.3")); // ... raster images like GIF files XGraphicsState state = formGfx.Save(); formGfx.RotateAtTransform(17, new XPoint(30, 30)); formGfx.DrawImage(XImage.FromFile("../../../../../../dev/XGraphicsLab/images/Test.gif"), 20, 20); formGfx.Restore(state); // ... and forms like XPdfForm objects state = formGfx.Save(); formGfx.RotateAtTransform(-8, new XPoint(165, 115)); formGfx.DrawImage(XPdfForm.FromFile("../../../../../PDFs/SomeLayout.pdf"), new XRect(140, 80, 50, 50 * Math.Sqrt(2))); formGfx.Restore(state); // When you finished drawing on the form, dispose the XGraphic object. formGfx.Dispose(); // Step 2: Draw the XPdfForm on your PDF page like an image // Draw the form on the page of the document in its original size gfx.DrawImage(form, 20, 50); #if true // Draw it stretched gfx.DrawImage(form, 300, 100, 250, 40); // Draw and rotate it const int d = 25; for (int idx = 0; idx < 360; idx += d) { gfx.DrawImage(form, 300, 480, 200, 200); gfx.RotateAtTransform(d, new XPoint(300, 480)); } #endif // Save the document... const string filename = "XForms_tempfile.pdf"; document.Save(filename); // ...and start a viewer. Process.Start(filename); }
/// <summary> /// Creates the normal appearance form X object for the annotation that represents /// this acro form text field. /// </summary> private void RenderAppearance() { for (var i = 0; i < Annotations.Elements.Count; i++) { var widget = Annotations.Elements[i]; if (widget == null) { continue; } if ((widget.Flags & PdfAnnotationFlags.Invisible) != 0 || (widget.Flags & PdfAnnotationFlags.NoView) != 0) { continue; } var rect = widget.Rectangle; var xRect = new XRect(0, 0, rect.Width, rect.Height); var form = (widget.Rotation == 90 || widget.Rotation == 270) && (widget.Flags & PdfAnnotationFlags.NoRotate) == 0 ? new XForm(_document, rect.Height, rect.Width) : new XForm(_document, xRect); EnsureFonts(form); using (var gfx = XGraphics.FromForm(form)) { var text = Text; if (MaxLength > 0) { text = text.Substring(0, Math.Min(Text.Length, MaxLength)); } var format = TextAlign == TextAlignment.Left ? XStringFormats.CenterLeft : TextAlign == TextAlignment.Center ? XStringFormats.Center : XStringFormats.CenterRight; if (MultiLine) { format.LineAlignment = XLineAlignment.Near; } if (text.Length > 0) { if (widget.Rotation != 0 && (widget.Flags & PdfAnnotationFlags.NoRotate) == 0) { // I could not get this to work using gfx.Rotate/Translate Methods... const double deg2Rad = 0.01745329251994329576923690768489; // PI/180 var sr = Math.Sin(widget.Rotation * deg2Rad); var cr = Math.Cos(widget.Rotation * deg2Rad); // see PdfReference 1.7, Chapter 8.3.3 (Common Transformations) // TODO: Is this always correct ? I had only the chance to test this with a 90 degree rotation... form.PdfForm.Elements.SetMatrix(PdfFormXObject.Keys.Matrix, new XMatrix(cr, sr, -sr, cr, xRect.Width, 0)); if (widget.Rotation == 90 || widget.Rotation == 270) { xRect = new XRect(0, 0, rect.Height, rect.Width); } } gfx.IntersectClip(xRect); // TODO: Not sure, if we should clip AFTER drawing background and border... TESTME ! // fill background if (!widget.BackColor.IsEmpty) { gfx.DrawRectangle(new XSolidBrush(widget.BackColor), xRect); } // draw border if (widget.BorderWidth > 0 && !widget.BorderColor.IsEmpty) { gfx.DrawRectangle(new XPen(widget.BorderColor, widget.BorderWidth), xRect); } // for Multiline fields, we use XTextFormatter to handle line-breaks and a fixed TextFormat (only TopLeft is supported) if (MultiLine) { var tf = new XTextFormatter(gfx); tf.DrawString(text, Font, new XSolidBrush(ForeColor), xRect, XStringFormats.TopLeft); } else { if (Combined && MaxLength > 0) { var combWidth = xRect.Width / MaxLength; var x = xRect.X; var cw = combWidth; var tb = new XSolidBrush(ForeColor); for (var ti = 0; ti < text.Length; ti++) { var combRect = new XRect(x, xRect.Y, cw, xRect.Height); gfx.DrawString(text[ti].ToString(), Font, tb, combRect, XStringFormats.Center); x += cw; } } else { gfx.DrawString(text, Font, new XSolidBrush(ForeColor), xRect, format); } } } } form.DrawingFinished(); form.PdfForm.Elements.Add("/FormType", new PdfLiteral("1")); // Get existing or create new appearance dictionary. var ap = widget.Elements[PdfAnnotation.Keys.AP] as PdfDictionary; if (ap == null) { ap = new PdfDictionary(_document); widget.Elements[PdfAnnotation.Keys.AP] = ap; } widget.Elements.SetName(PdfAnnotation.Keys.AS, "/N"); // set appearance state // Set XRef to normal state ap.Elements["/N"] = form.PdfForm.Reference; form.PdfRenderer.Close(); var xobj = form.PdfForm; var s = xobj.Stream.ToString(); // Thank you Adobe: Without putting the content in 'EMC brackets' // the text is not rendered by PDF Reader 9 or higher. s = "/Tx BMC\n" + s + "\nEMC"; xobj.Stream.Value = new RawEncoding().GetBytes(s); } }
public static bool Attach_DrukWplatyZUS(SPWeb web, SPListItem item, string nazwaPliku, string numerRachunku, double kwotaDoZaplaty, string nadawca, string nip, string typIdentyfikatora, string drugiIdentyfikator, string identyfikatorDeklaracji) { nadawca = nadawca.ToUpper(); const int maxLen = 27; nazwaPliku = CleanupFileName(nazwaPliku); if (numerRachunku.Length != 26) { return(false); } else { numerRachunku = String.Format(@"{0} {1}", numerRachunku.Substring(0, 2), numerRachunku.Substring(20, 1)); } if (item.Attachments.Count > 0) { foreach (string fname in item.Attachments) { if (fname == nazwaPliku) { item.Attachments.DeleteNow(fname); break; } } } //string pdfFilePath = @"SiteAssets/Templates/DW-ZUS.pdf"; string pdfFilePath = @"SiteAssets/Templates/Szablon_DW_ZUSBW300hh.pdf"; int x0 = 90; int dx = 136; int y0 = 35; int dy = 76; int formoffset = 297; double ofset0 = 14; //odstępo pomiędzy znakami ?14.18 double ofset1 = 23.6; //odstęp pomiędzy liniami ?23.2 int c01 = 3; int r01 = 52; int r02 = r01 + (int)(ofset1 * 1); int r03 = r01 + (int)(ofset1 * 2); int c02 = 215; //221 int r04 = r01 + (int)(ofset1 * 3); int r05 = r01 + (int)(ofset1 * 4); int r06 = r01 + (int)(ofset1 * 5); int r07 = r01 + (int)(ofset1 * 6); SPFile file = web.GetFile(pdfFilePath); if (file.Exists) { int bufferSize = 20480; byte[] byteBuffer = new byte[bufferSize]; byteBuffer = file.OpenBinary(); MemoryStream coverSheetContent = new MemoryStream(); coverSheetContent.Write(byteBuffer, 0, byteBuffer.Length); int t = PdfReader.TestPdfFile(coverSheetContent); PdfDocument document = PdfReader.Open(coverSheetContent); PdfPage page = document.Pages[0]; XForm form = new XForm(document, XUnit.FromMillimeter(dx + 10), XUnit.FromMillimeter(dy)); XGraphics formGfx = XGraphics.FromForm(form); #if DEBUG XColor back = XColors.Orange; #else XColor back = XColors.White; #endif back.A = 0.2; XSolidBrush brush = new XSolidBrush(back); formGfx.DrawRectangle(brush, -10000, -10000, 20000, 20000); //XFont font = new XFont("Verdana", 10, XFontStyle.Bold); XFont font = new XFont("Verdana", 10, XFontStyle.Bold); XFont fontR = new XFont("Verdana", 10, XFontStyle.Regular); PlotText(numerRachunku, c01, r01, ofset0, formGfx, font); PlotText(" X", c01, r02, ofset0, formGfx, font); PlotText(" " + (string)(String.Format("{0:#0.00}", kwotaDoZaplaty) + "************").Substring(0, 12), c01, r02, ofset0, formGfx, font); int zlote = (int)kwotaDoZaplaty; int grosze = (int)(100 * kwotaDoZaplaty) % 100; string kwota = String.Format("{0} {1}", KwotaSlownie.LiczbaSlownie(zlote), grosze + "/100"); //formGfx.DrawString("*" + kwota + "*", new XFont("Verdana", 10, XFontStyle.Regular), XBrushes.Navy, c01, r03, XStringFormats.TopLeft); formGfx.DrawString("*" + kwota + "*", fontR, XBrushes.Navy, c01, r03, XStringFormats.TopLeft); string nadawca2 = string.Empty; if (nadawca.Length > maxLen) { nadawca2 = nadawca.Substring(maxLen, nadawca.Length - maxLen); if (nadawca2.Length > maxLen) { nadawca2 = nadawca2.Substring(0, maxLen); } nadawca = nadawca.Substring(0, maxLen); } PlotText(nadawca, c01, r04, ofset0, formGfx, font); PlotText(nadawca2, c01, r05, ofset0, formGfx, font); PlotText(nip, c01, r06, ofset0, formGfx, font); PlotText(typIdentyfikatora, c01 + (int)(11 * ofset0), r06, ofset0, formGfx, font); PlotText(drugiIdentyfikator, c01 + (int)(13 * ofset0), r06, ofset0, formGfx, font); PlotText(identyfikatorDeklaracji, c01, r07, ofset0, formGfx, font); XPen pen = XPens.LightBlue.Clone(); pen.Width = 2.5; XGraphics gfx = XGraphics.FromPdfPage(page); // Draw the form on the page of the document in its original size gfx.DrawImage(form, x0, y0); gfx.DrawImage(form, x0, y0 + formoffset); MemoryStream ms = new MemoryStream(); document.Save(ms); item.Attachments.Add(nazwaPliku, ms.GetBuffer()); item.SystemUpdate(); return(true); } else { return(false); } }
public static bool Attach_DrukWplatyPD(SPWeb web, SPListItem item, string nazwaPliku, string odbiorca, string numerRachunku, double kwotaDoZaplaty, string zleceniodawca, string nip, string typIdentyfikatora, string okres, string symbolFormularza, string identyfikacjaZobowiazania) { const int maxLen = 27; odbiorca = odbiorca.ToUpper(); zleceniodawca = zleceniodawca.ToUpper(); //unormowanie nazwy pliku nazwaPliku = CleanupFileName(nazwaPliku); if (numerRachunku.Length != 26) { return(false); } if (item.Attachments.Count > 0) { foreach (string fname in item.Attachments) { if (fname == nazwaPliku) { item.Attachments.DeleteNow(fname); break; } } } string pdfFilePath = @"SiteAssets/Templates/Szablon_DW_PDBW300h.pdf"; int x0 = 88; //85 int dx = 136; int y0 = 35; int dy = 76; double ofset0 = 14.18; //14.5 dotyczy numeru rachunku var r = 5; var rOffset = 23.8; //23.2 int c01 = 5; int r01 = r; int r02 = (int)(r + rOffset * 1); int r03 = (int)(r + rOffset * 2); int c02 = 217; //220 int r04 = (int)(r + rOffset * 3); int r05 = (int)(r + rOffset * 4); int r06 = (int)(r + rOffset * 5); int r07 = (int)(r + rOffset * 6); int r08 = (int)(r + rOffset * 7); int r09 = (int)(r + rOffset * 8); SPFile file = web.GetFile(pdfFilePath); if (file.Exists) { int bufferSize = 20480; byte[] byteBuffer = new byte[bufferSize]; //byteBuffer = File.ReadAllBytes(pdfFilePath); byteBuffer = file.OpenBinary(); MemoryStream coverSheetContent = new MemoryStream(); coverSheetContent.Write(byteBuffer, 0, byteBuffer.Length); int t = PdfReader.TestPdfFile(coverSheetContent); PdfDocument document = PdfReader.Open(coverSheetContent); PdfPage page = document.Pages[0]; XForm form = new XForm(document, XUnit.FromMillimeter(dx), XUnit.FromMillimeter(dy)); XGraphics formGfx = XGraphics.FromForm(form); // Draw a large transparent rectangle to visualize the area the form occupies #if DEBUG XColor back = XColors.Orange; #else XColor back = XColors.White; #endif back.A = 0.2; XSolidBrush brush = new XSolidBrush(back); formGfx.DrawRectangle(brush, -10000, -10000, 20000, 20000); XFont font = new XFont("Verdana", 10, XFontStyle.Bold); //XFont("Verdana", 10, XFontStyle.Regular) string odbiorca2 = string.Empty; if (odbiorca.Length > maxLen) { odbiorca2 = odbiorca.Substring(maxLen, odbiorca.Length - maxLen); if (odbiorca2.Length > maxLen) { odbiorca2 = odbiorca2.Substring(0, maxLen); } odbiorca = odbiorca.Substring(0, maxLen); } PlotText(odbiorca, c01, r01, ofset0, formGfx, font); PlotText(odbiorca2, c01, r02, ofset0, formGfx, font); PlotText(numerRachunku, c01, r03, ofset0, formGfx, font); PlotText("X", c01 + (int)(9 * ofset0) + 2, r04 - 3, ofset0, formGfx, font); PlotText((string)(String.Format("{0:#0.00}", kwotaDoZaplaty) + "************").Substring(0, 12), c02, r04, ofset0, formGfx, font); int zlote = (int)kwotaDoZaplaty; int grosze = (int)(100 * kwotaDoZaplaty) % 100; string kwota = String.Format("{0} {1}", KwotaSlownie.LiczbaSlownie(zlote), grosze + "/100"); formGfx.DrawString("*" + kwota + "*", new XFont("Verdana", 10, XFontStyle.Regular), XBrushes.Navy, c01, r05, XStringFormats.TopLeft); string zleceniodawca2 = string.Empty; if (zleceniodawca.Length > maxLen) { zleceniodawca2 = zleceniodawca.Substring(maxLen, zleceniodawca.Length - maxLen); if (zleceniodawca2.Length > maxLen) { zleceniodawca2 = zleceniodawca2.Substring(0, maxLen); } zleceniodawca = zleceniodawca.Substring(0, maxLen); } PlotText(zleceniodawca, c01, r06, ofset0, formGfx, font); PlotText(zleceniodawca2, c01, r07, ofset0, formGfx, font); PlotText(nip, c01, r08, ofset0, formGfx, font); PlotText(typIdentyfikatora, c01 + (int)(15 * ofset0), r08, ofset0, formGfx, font); PlotText(okres, c01 + (int)(19 * ofset0), r08, ofset0, formGfx, font); PlotText(symbolFormularza, c01, r09, ofset0, formGfx, font); PlotText(identyfikacjaZobowiazania, c01 + (int)(7 * ofset0), r09, ofset0, formGfx, font); XPen pen = XPens.LightBlue.Clone(); pen.Width = 2.5; XGraphics gfx = XGraphics.FromPdfPage(page); // Draw the form on the page of the document in its original size gfx.DrawImage(form, x0, y0); gfx.DrawImage(form, x0, y0 + 297); //294 MemoryStream ms = new MemoryStream(); document.Save(ms); item.Attachments.Add(nazwaPliku, ms.GetBuffer()); item.SystemUpdate(); return(true); } else { return(false); } }
public static bool Attach_DrukWplaty(SPWeb web, SPListItem item, string nazwaPliku, string odbiorca, string numerRachunku, double kwotaDoZaplaty, string zleceniodawca, string tytulem) { //const int maxLen = 27; const int maxLen = 46; odbiorca = odbiorca.ToUpper(); zleceniodawca = zleceniodawca.ToUpper(); tytulem = tytulem.ToUpper(); //unormowanie nazwy pliku nazwaPliku = CleanupFileName(nazwaPliku); numerRachunku = Format_KontoBezSpacji(numerRachunku); if (numerRachunku.Length != 26) { return(false); } if (item.Attachments.Count > 0) { foreach (string fname in item.Attachments) { if (fname == nazwaPliku) { item.Attachments.DeleteNow(fname); break; } } } string pdfFilePath = @"SiteAssets/Templates/Szablon_DWBW300h.pdf"; //koordynaty ramki int x0 = 92; int y0 = 34; SPFile file = web.GetFile(pdfFilePath); if (file.Exists) { int bufferSize = 20480; byte[] byteBuffer = new byte[bufferSize]; //byteBuffer = File.ReadAllBytes(pdfFilePath); byteBuffer = file.OpenBinary(); MemoryStream coverSheetContent = new MemoryStream(); coverSheetContent.Write(byteBuffer, 0, byteBuffer.Length); int t = PdfReader.TestPdfFile(coverSheetContent); PdfDocument document = PdfReader.Open(coverSheetContent); PdfPage page = document.Pages[0]; // Create an empty XForm object with the specified width and height // A form is bound to its target document when it is created. The reason is that the form can // share fonts and other objects with its target document. XForm form = new XForm(document, XUnit.FromMillimeter(133), XUnit.FromMillimeter(75)); // Create an XGraphics object for drawing the contents of the form. XGraphics formGfx = XGraphics.FromForm(form); // Draw a large transparent rectangle to visualize the area the form occupies #if DEBUG XColor back = XColors.Orange; #else XColor back = XColors.White; #endif back.A = 0.2; XSolidBrush brush = new XSolidBrush(back); formGfx.DrawRectangle(brush, -10000, -10000, 20000, 20000); // On a form you can draw... // ... text XFont font = new XFont("Verdana", 10, XFontStyle.Bold); //XFont("Verdana", 10, XFontStyle.Regular) string odbiorca2 = string.Empty; if (odbiorca.Length > maxLen) { odbiorca2 = odbiorca.Substring(maxLen, odbiorca.Length - maxLen); if (odbiorca2.Length > maxLen) { odbiorca2 = odbiorca2.Substring(0, maxLen); } odbiorca = odbiorca.Substring(0, maxLen); } var r = 8; var offsetR = 23.3; formGfx.DrawString(odbiorca, font, XBrushes.Navy, 8, r, XStringFormats.TopLeft); formGfx.DrawString(odbiorca2, font, XBrushes.Navy, 8, r + offsetR, XStringFormats.TopLeft); //formGfx.DrawString("Numer rachunku odbiorcy przekazu pocztowego", new XFont("Verdana", 10, XFontStyle.Regular), XBrushes.Navy, 8, 57, XStringFormats.TopLeft); int n = 0; formGfx.DrawString(numerRachunku.Substring(n, 2), font, XBrushes.Navy, 13, r + offsetR * 2, XStringFormats.TopLeft); n = n + 2; int offset = 57; // 57; - odstęp pomiędzy liczbami w rachunku bankowym int targetX = 40; formGfx.DrawString(numerRachunku.Substring(n, 4), font, XBrushes.Navy, targetX, r + offsetR * 2, XStringFormats.TopLeft); n = n + 4; formGfx.DrawString(numerRachunku.Substring(n, 4), font, XBrushes.Navy, targetX + 1 * offset, r + offsetR * 2, XStringFormats.TopLeft); n = n + 4; formGfx.DrawString(numerRachunku.Substring(n, 4), font, XBrushes.Navy, targetX + 2 * offset, r + offsetR * 2, XStringFormats.TopLeft); n = n + 4; formGfx.DrawString(numerRachunku.Substring(n, 4), font, XBrushes.Navy, targetX + 3 * offset, r + offsetR * 2, XStringFormats.TopLeft); n = n + 4; formGfx.DrawString(numerRachunku.Substring(n, 4), font, XBrushes.Navy, targetX + 4 * offset, r + offsetR * 2, XStringFormats.TopLeft); n = n + 4; formGfx.DrawString(numerRachunku.Substring(n, 4), font, XBrushes.Navy, targetX + 5 * offset, r + offsetR * 2, XStringFormats.TopLeft); formGfx.DrawString("X", new XFont("Verdana", 10, XFontStyle.Regular), XBrushes.Navy, 125, r + offsetR * 3, XStringFormats.TopLeft); formGfx.DrawString("***" + String.Format("{0:#,0.00}", kwotaDoZaplaty) + "***", font, XBrushes.Navy, 220, r + offsetR * 3, XStringFormats.TopLeft); int zlote = (int)kwotaDoZaplaty; int grosze = (int)(100 * kwotaDoZaplaty) % 100; string kwota = String.Format("{0} {1}", KwotaSlownie.LiczbaSlownie(zlote), grosze + "/100"); formGfx.DrawString("***" + kwota + "***", new XFont("Verdana", 10, XFontStyle.Regular), XBrushes.Navy, 8, r + offsetR * 4, XStringFormats.TopLeft); string zleceniodawca2 = string.Empty; if (zleceniodawca.Length > maxLen) { zleceniodawca2 = zleceniodawca.Substring(maxLen, zleceniodawca.Length - maxLen); if (zleceniodawca2.Length > maxLen) { zleceniodawca2 = zleceniodawca2.Substring(0, maxLen); } zleceniodawca = zleceniodawca.Substring(0, maxLen); } formGfx.DrawString(zleceniodawca, font, XBrushes.Navy, 8, r + offsetR * 5, XStringFormats.TopLeft); formGfx.DrawString(zleceniodawca2, font, XBrushes.Navy, 8, r + offsetR * 6, XStringFormats.TopLeft); string tytulem2 = string.Empty; if (tytulem.Length > maxLen) { tytulem2 = tytulem.Substring(maxLen, tytulem.Length - maxLen); if (tytulem2.Length > maxLen) { tytulem2 = tytulem2.Substring(0, maxLen); } tytulem = tytulem.Substring(0, maxLen); } formGfx.DrawString(tytulem, font, XBrushes.Navy, 8, r + offsetR * 7, XStringFormats.TopLeft); formGfx.DrawString(tytulem2, font, XBrushes.Navy, 8, r + offsetR * 8, XStringFormats.TopLeft); XPen pen = XPens.LightBlue.Clone(); pen.Width = 2.5; XGraphics gfx = XGraphics.FromPdfPage(page); // Draw the form on the page of the document in its original size gfx.DrawImage(form, x0, y0); gfx.DrawImage(form, x0, y0 + 296); MemoryStream ms = new MemoryStream(); document.Save(ms); item.Attachments.Add(nazwaPliku, ms.GetBuffer()); item.SystemUpdate(); return(true); } else { return(false); } }
// draws a single Paper Wallet in to a PdfSharp XForm private PdfSharp.Drawing.XForm getSingleWallet(PdfDocument doc, WalletBundle b, XImage imgArtwork, string address, string privkey, int numberWithinBatch, bool layoutDebugging) { WalletTemplate t = b.template; double width = t.widthMM; double height = t.heightMM; XUnit walletSizeWide = XUnit.FromMillimeter(width); XUnit walletSizeHigh = XUnit.FromMillimeter(height); PdfSharp.Drawing.XForm form = new PdfSharp.Drawing.XForm(doc, walletSizeWide, walletSizeHigh); using (XGraphics formGfx = XGraphics.FromForm(form)) { XGraphicsState state = formGfx.Save(); bool interpolateArtwork = true; bool interpolateQRcodes = false; // XImage imgArtwork is now provided by caller, so this process only has to be done ONCE - because the artwork does not change between Wallets in a run! //XImage imgArtwork = XImage.FromGdiPlusImage(b.getArtworkImage()); imgArtwork.Interpolate = interpolateArtwork; formGfx.DrawImage(imgArtwork, new RectangleF(0f, 0f, (float)walletSizeWide.Point, (float)walletSizeHigh.Point)); // draw the QR codes and legible-text things // Address // QR Bitmap bmpAddress = BtcAddress.QR.EncodeQRCode(address); XImage imgAddress = XImage.FromGdiPlusImage(bmpAddress); imgAddress.Interpolate = interpolateQRcodes; XUnit addressQrLeft = XUnit.FromMillimeter(t.addressQrLeftMM); XUnit addressQrTop = XUnit.FromMillimeter(t.addressQrTopMM); XUnit addressQrSize = XUnit.FromMillimeter(t.addressQrSizeMM); // only print Address QR if called for if (t.addressQrSizeMM > 0.1) { XRect addressQrRect = new XRect(addressQrLeft.Point, addressQrTop.Point, addressQrSize.Point, addressQrSize.Point); formGfx.DrawImage(imgAddress, addressQrRect); } // text address string addressSplitForLines = addressOrReferencePrep(address, t.addressTextCharsPerLine, t.addressTextContentVariant, numberWithinBatch); XFont fontAddress = new XFont(t.addressTextFontName, t.addressTextFontSize, t.addressTextFontStyle); XTextFormatter tf = new XTextFormatter(formGfx); XUnit addressTxtLeft = XUnit.FromMillimeter(t.addressTextLeftMM); XUnit addressTxtTop = XUnit.FromMillimeter(t.addressTextTopMM); XUnit addressTxtWidth = XUnit.FromMillimeter(t.addressTextWidthMM); XUnit addressTxtHeight = XUnit.FromMillimeter(t.addressTextHeightMM); XRect addressRect = new XRect(addressTxtLeft.Point, addressTxtTop.Point, addressTxtWidth.Point, addressTxtHeight.Point); tf.Alignment = XParagraphAlignment.Center; TextRotation addressTxtRotation = t.addressTextRotation; double addressTxtRotationDegrees = RotationMarkerToDegrees(addressTxtRotation); if (layoutDebugging) { formGfx.DrawRectangle(XBrushes.PowderBlue, addressRect); } XPoint rotateCentre = new XPoint(addressTxtLeft + (addressTxtWidth / 2), addressTxtTop + (addressTxtHeight / 2)); XPoint matrixRotatePoint = new XPoint(addressRect.X + (addressRect.Width / 2), addressRect.Y + (addressRect.Height / 2)); XMatrix rotateMatrix = new XMatrix(); rotateMatrix.RotateAtAppend(addressTxtRotationDegrees, rotateCentre); addressRect.Transform(rotateMatrix); if (layoutDebugging) { // draw a little tracer dot for where the centre of rotation is going to be double rotateDotSize = 2.0; formGfx.DrawEllipse(XBrushes.Red, rotateCentre.X - (rotateDotSize / 2), rotateCentre.Y - (rotateDotSize / 2), rotateDotSize, rotateDotSize); } // maybe even do some rotation of the lovely text! formGfx.Save(); formGfx.RotateAtTransform(addressTxtRotationDegrees, rotateCentre); if (layoutDebugging) { formGfx.DrawRectangle(XPens.OrangeRed, addressRect); } if (t.addressTextWidthMM > 0.1) { tf.DrawString(addressSplitForLines, fontAddress, t.GetBrushAddress, addressRect); } formGfx.Restore(); // Privkey // QR Bitmap bmpPrivkey = BtcAddress.QR.EncodeQRCode(privkey); XImage imgPrivkey = XImage.FromGdiPlusImage(bmpPrivkey); imgPrivkey.Interpolate = interpolateQRcodes; XUnit privkeyQrLeft = XUnit.FromMillimeter(t.privkeyQrLeftMM); XUnit privkeyQrTop = XUnit.FromMillimeter(t.privkeyQrTopMM); XUnit privkeyQrSize = XUnit.FromMillimeter(t.privkeyQrSizeMM); XRect privkeyQrRect = new XRect(privkeyQrLeft.Point, privkeyQrTop.Point, privkeyQrSize.Point, privkeyQrSize.Point); // only print privkey QR if specified - but you'd have to be an UTTER IDIOT to want to exclude this. Still, user input comes first! if (t.privkeyQrSizeMM > 0.1) { formGfx.DrawImage(imgPrivkey, privkeyQrRect); } // legible string privkeySplitForLines = lineSplitter(privkey, t.privkeyTextCharsPerLine); XFont fontPrivkey = new XFont(t.privkeyTextFontName, t.privkeyTextFontSize, t.privkeyTextFontStyle); XUnit privkeyTxtLeft = XUnit.FromMillimeter(t.privkeyTextLeftMM); XUnit privkeyTxtTop = XUnit.FromMillimeter(t.privkeyTextTopMM); XUnit privkeyTxtWidth = XUnit.FromMillimeter(t.privkeyTextWidthMM); XUnit privkeyTxtHeight = XUnit.FromMillimeter(t.privkeyTextHeightMM); TextRotation privkeyTxtRotation = t.privkeyTextRotation; double privkeyTxtRotationDegrees = RotationMarkerToDegrees(privkeyTxtRotation); XRect privkeyRect = new XRect(privkeyTxtLeft.Point, privkeyTxtTop.Point, privkeyTxtWidth.Point, privkeyTxtHeight.Point); if (layoutDebugging) { // draw a tracer rectangle for the original un-rotated text rectangle formGfx.DrawRectangle(XBrushes.PowderBlue, privkeyRect); } // rotate that lovely text around its middle when drawing! rotateCentre = new XPoint(privkeyTxtLeft + (privkeyTxtWidth / 2), privkeyTxtTop + (privkeyTxtHeight / 2)); matrixRotatePoint = new XPoint(privkeyRect.X + (privkeyRect.Width / 2), privkeyRect.Y + (privkeyRect.Height / 2)); rotateMatrix = new XMatrix(); rotateMatrix.RotateAtAppend(privkeyTxtRotationDegrees, rotateCentre); privkeyRect.Transform(rotateMatrix); if (layoutDebugging) { // draw a little tracer dot for where the centre of rotation is going to be double rotateDotSize = 2.0; formGfx.DrawEllipse(XBrushes.Red, rotateCentre.X - (rotateDotSize / 2), rotateCentre.Y - (rotateDotSize / 2), rotateDotSize, rotateDotSize); } formGfx.Save(); formGfx.RotateAtTransform(privkeyTxtRotationDegrees, rotateCentre); if (layoutDebugging) { formGfx.DrawRectangle(XPens.OrangeRed, privkeyRect); } // only print privkey text if specified. if (t.privkeyTextWidthMM > 0.1) { tf.DrawString(privkeySplitForLines, fontPrivkey, t.GetBrushPrivkey, privkeyRect); } formGfx.Restore(); } return(form); }
void RenderAppearance() { var format = TextAlign == TextAlignment.Left ? XStringFormats.CenterLeft : TextAlign == TextAlignment.Center ? XStringFormats.Center : XStringFormats.CenterRight; for (var idx = 0; idx < Annotations.Elements.Count; idx++) { var widget = Annotations.Elements[idx]; if (widget == null) { continue; } var rect = widget.Rectangle; var xRect = new XRect(0, 0, rect.Width, rect.Height); var form = new XForm(_document, xRect); EnsureFonts(form); using (var gfx = XGraphics.FromForm(form)) { if (widget.BackColor != XColor.Empty) { gfx.DrawRectangle(new XSolidBrush(widget.BackColor), xRect); } // Draw Border if (!widget.BorderColor.IsEmpty) { gfx.DrawRectangle(new XPen(widget.BorderColor), xRect); } var lineHeight = Font.Size * 1.2; var y = 0.0; var startIndex = Math.Min(TopIndex, Options.Count - (int)(rect.Height / lineHeight)); for (var i = startIndex; i < Options.Count; i++) { var text = Options[i]; // offset and shrink a bit to not draw on top of the outer border var lineRect = new XRect(1, y + 1, rect.Width - 2, lineHeight - 1); var selected = false; if (text.Length > 0) { if (SelectedIndices.Contains(i)) { gfx.DrawRectangle(new XSolidBrush(HighlightColor), lineRect); selected = true; } lineRect.Inflate(-2, 0); gfx.DrawString(text, Font, new XSolidBrush(selected ? HighlightTextColor : ForeColor), lineRect, format); y += lineHeight; } } form.DrawingFinished(); var ap = new PdfDictionary(this._document); widget.Elements[PdfAnnotation.Keys.AP] = ap; // Set XRef to normal state ap.Elements["/N"] = form.PdfForm.Reference; widget.Elements.SetName(PdfAnnotation.Keys.AS, "/N"); // set appearance state // Set XRef to normal state ap.Elements["/N"] = form.PdfForm.Reference; var xobj = form.PdfForm; var s = xobj.Stream.ToString(); s = "/Tx BMC\n" + s + "\nEMC"; xobj.Stream.Value = new RawEncoding().GetBytes(s); } } }