private void DrawLogImage() { // define local image resources // resolution 96 pixels per inch, image quality 100% PdfImageControl ImageControl = new PdfImageControl(); ImageControl.Resolution = 96.0; ImageControl.ImageQuality = 100; CreateLogoFile(); PdfImage Image1 = new PdfImage(Document, "temps/" + pk.Logo.Filename, ImageControl); // save graphics state Contents.SaveGraphicsState(); // translate coordinate origin to the center of the picture Contents.Translate(0, 10); // adjust image size an preserve aspect ratio PdfRectangle NewSize = Image1.ImageSizePosition(3, 1.1, ContentAlignment.MiddleCenter); // clipping path Contents.DrawOval(NewSize.Left, NewSize.Bottom, NewSize.Width, NewSize.Height, PaintOp.Fill); // draw image Contents.DrawImage(Image1, NewSize.Left, NewSize.Bottom, NewSize.Width, NewSize.Height); // restore graphics state Contents.RestoreGraphicsState(); return; }
//////////////////////////////////////////////////////////////////// /// <summary> /// Add pages to PDF document /// </summary> /// <remarks> /// The PrintDoc.Print method will call BeginPrint method, /// next it will call multiple times PrintPage method and finally /// it will call EndPrint method. /// </remarks> //////////////////////////////////////////////////////////////////// public void AddPagesToPdfDocument() { // print the document by calling BeginPrint, PrintPage multiple times and finally EndPrint Print(); // get printing results in the form of array of images one per page // image format is Metafile PreviewPageInfo[] PageInfo = ((PreviewPrintController)PrintController).GetPreviewPageInfo(); // page size in user units Double PageWidth = Document.PageSize.Width / Document.ScaleFactor; Double PageHeight = Document.PageSize.Height / Document.ScaleFactor; // define empty image source rectangle Rectangle SourceRect = new Rectangle(); // add pages to pdf document for (Int32 ImageIndex = 0; ImageIndex < PageInfo.Length; ImageIndex++) { // add page to document PdfPage Page = new PdfPage(Document); // add contents to the page PdfContents Contents = new PdfContents(Page); // page image Image PageImage = PageInfo[ImageIndex].Image; // no crop if (CropRect.IsEmpty) { // convert metafile image to PdfImage PdfImage Image = new PdfImage(Contents.Document, PageImage, Resolution); // draw the image Contents.DrawImage(Image, 0.0, 0.0, PageWidth, PageHeight); } // crop else { Int32 ImageWidth = PageImage.Width; Int32 ImageHeight = PageImage.Height; SourceRect.X = (Int32)(ImageWidth * CropRect.X / PageWidth + 0.5); SourceRect.Y = (Int32)(ImageHeight * CropRect.Y / PageHeight + 0.5); SourceRect.Width = (Int32)(ImageWidth * CropRect.Width / PageWidth + 0.5); SourceRect.Height = (Int32)(ImageHeight * CropRect.Height / PageHeight + 0.5); // convert metafile image to PdfImage PdfImage PdfPageImage = new PdfImage(Contents.Document, PageImage, SourceRect, Resolution); // draw the image Contents.DrawImage(PdfPageImage, CropRect.X, PageHeight - CropRect.Y - CropRect.Height, CropRect.Width, CropRect.Height); } } return; }
public void appendTopHeader(string title, string logoPath, bool includeSecondLine = true, string assessmentType = "") { drawY -= .7; string logoDir = Path.GetDirectoryName(logoPath); PdfImage logo = new PdfImage(doc, logoPath); double logoHeight = .6; double logoWidth = logoHeight * logo.WidthPix / logo.HeightPix; // standard (left) header logo cont.DrawImage(logo, firstColumnHeaderX, drawY - .2, logoWidth, logoHeight); // right header logo string logoRight = Path.Combine(logoDir, "logo-right.png"); if (File.Exists(logoRight)) { PdfImage logoR = new PdfImage(doc, logoRight); cont.DrawImage(logoR, secondColumnHeaderX + 1.7, drawY + .05, logoWidth, logoHeight); } //cont.DrawText(logoFont, 50.0, firstColumnHeaderX, drawY, sisred, "AAIDD"); double titleSize = includeSecondLine ? 10.0 : 15.0; double titleY = includeSecondLine ? drawY + .15 : drawY + .07; cont.DrawText(boldFont, titleSize, 3.6, titleY, title); if (includeSecondLine) { // customize header text for SIS-A/C if (!String.IsNullOrEmpty(assessmentType)) { if (assessmentType == "SIS-A") { cont.DrawText(contentFont, 7.5, 3.6, drawY, "Confidential Interview and Profile Results for the Supports Intensity Scale Adult Version : SIS-A"); cont.DrawText(contentFont, 5, 7.63, drawY + .03, "TM"); cont.DrawText(contentFont, 5, 8.09, drawY + .03, "TM"); } if (assessmentType == "SIS-C") { cont.DrawText(contentFont, 7.5, 3.6, drawY, "Confidential Interview and Profile Results for the Supports Intensity Scale Children's Version : SIS-C"); cont.DrawText(contentFont, 5, 7.85, drawY + .03, "TM"); cont.DrawText(contentFont, 5, 8.33, drawY + .03, "TM"); } } else { cont.DrawText(contentFont, 7.5, 3.6, drawY, "Confidential Interview and Profile Results for the Supports Intensity Scale"); } } }
//////////////////////////////////////////////////////////////////// // Draw image and clip it //////////////////////////////////////////////////////////////////// private void DrawImage() { // define local image resources // resolution 96 pixels per inch, image quality 50% PdfImageControl ImageControl = new PdfImageControl(); ImageControl.Resolution = 96.0; ImageControl.ImageQuality = 50; // ImageControl.SaveAs = SaveImageAs.GrayImage; // ImageControl.ReverseBW = true; PdfImage Image1 = new PdfImage(Document, "TestImage.jpg", ImageControl); // save graphics state Contents.SaveGraphicsState(); // translate coordinate origin to the center of the picture Contents.Translate(2.6, 5.0); // adjust image size an preserve aspect ratio PdfRectangle NewSize = Image1.ImageSizePosition(1.75, 1.5, ContentAlignment.MiddleCenter); // clipping path Contents.DrawOval(NewSize.Left, NewSize.Bottom, NewSize.Width, NewSize.Height, PaintOp.ClipPathEor); // draw image Contents.DrawImage(Image1, NewSize.Left, NewSize.Bottom, NewSize.Width, NewSize.Height); // restore graphics state Contents.RestoreGraphicsState(); return; }
//////////////////////////////////////////////////////////////////// // Draw image and clip it //////////////////////////////////////////////////////////////////// private void DrawImage(float originx, float originy) { // define local image resources // resolution 96 pixels per inch, image quality 50% PdfImageControl ImageControl = new PdfImageControl(); ImageControl.Resolution = 300; ImageControl.ImageQuality = 80; ; // ImageControl.SaveAs = SaveImageAs.GrayImage; // ImageControl.ReverseBW = true; PdfImage Image1 = new PdfImage(Document, @"C:\Users\Sriram\Downloads\10-05-2017_17-59-05_Report\20170510063212x3.jpg", ImageControl); //TestImage.jpg // save graphics state Contents.SaveGraphicsState(); // translate coordinate origin to the center of the picture //Contents.Translate(2.6, 5.0); Contents.Translate(originx, originy); // adjust image size an preserve aspect ratio PdfRectangle NewSize = Image1.ImageSizePosition(300, 200, ContentAlignment.MiddleCenter); // clipping path //Contents.DrawOval(NewSize.Left, NewSize.Bottom, NewSize.Width, NewSize.Height, PaintOp.ClipPathEor); // draw image Contents.DrawImage(Image1, NewSize.Left, NewSize.Bottom, NewSize.Width, NewSize.Height); // restore graphics state Contents.RestoreGraphicsState(); return; }
//////////////////////////////////////////////////////////////////// // Draw image of a flower and clip it //////////////////////////////////////////////////////////////////// private void DrawFlower ( PdfDocument Document, PdfContents Contents ) { // define local image resources PdfImage Image1 = new PdfImage(Document, "flower.jpg"); // image size will be limited to 1.4" by 1.4" SizeD ImageSize = Image1.ImageSize(1.4, 1.4); // save graphics state Contents.SaveGraphicsState(); // translate coordinate origin to the center of the picture Contents.Translate(3.36, 5.7); // clipping path Contents.DrawOval(-ImageSize.Width / 2, -ImageSize.Height / 2, ImageSize.Width, ImageSize.Height, PaintOp.ClipPathEor); // draw image Contents.DrawImage(Image1, -ImageSize.Width / 2, -ImageSize.Height / 2, ImageSize.Width, ImageSize.Height); // restore graphics state Contents.RestoreGraphicsState(); return; }
//////////////////////////////////////////////////////////////////// // Draw image and clip it //////////////////////////////////////////////////////////////////// private static void DrawTitle() { // define local image resources as 200ppi and 100% quality PdfImageControl ImageControl = new PdfImageControl(); ImageControl.Resolution = 200; ImageControl.ImageQuality = 100; // Get image from embedded local resource Image BocTitle = Properties.Resources.BocTitleBitmap; PdfImage titleImage = new PdfImage(document, BocTitle, ImageControl); // save graphics state Contents.SaveGraphicsState(); // set coordinate Contents.Translate(1.3, 26.8); // set image size PdfRectangle size = titleImage.ImageSizePosition(18.39, 1.85, ContentAlignment.MiddleCenter); // clipping path Contents.DrawRectangle(size.Left, size.Bottom, size.Width, size.Height, PaintOp.ClipPathEor); // draw image Contents.DrawImage(titleImage, size.Left, size.Bottom, size.Width, size.Height); // restore graphics state Contents.RestoreGraphicsState(); return; }
//////////////////////////////////////////////////////////////////// // Draw Barcode //////////////////////////////////////////////////////////////////// private void DrawBarcode() { // save graphics state Contents.SaveGraphicsState(); // draw EAN13 barcode BarcodeEAN13 Barcode1 = new BarcodeEAN13("1234567890128"); Contents.DrawBarcode(1.3, 7.05, 0.012, 0.75, Barcode1, ArialNormal, 8.0); // create QRCode barcode QREncoder QREncoder = new QREncoder(); // set error correction code QREncoder.ErrorCorrection = ErrorCorrection.M; // set module size in pixels QREncoder.ModuleSize = 1; // set quiet zone in pixels QREncoder.QuietZone = 4; // encode your text or byte array QREncoder.Encode(ArticleLink); // convert QRCode to black and white image PdfImage BarcodeImage = new PdfImage(Document); BarcodeImage.LoadImage(QREncoder); // draw image (height is the same as width for QRCode) Contents.DrawImage(BarcodeImage, 6.0, 6.8, 1.2); // define a web link area coinsiding with the qr code Page.AddWebLink(6.0, 6.8, 7.2, 8.0, ArticleLink); // restore graphics sate Contents.RestoreGraphicsState(); return; }
private void button2_Click(object sender, EventArgs e) { if (folderDiag.SelectedPath != null && folderDiag.SelectedPath != "") { textBox1.Text = "Adding pages"; Image[] pages = System.IO.Directory.GetFiles(folderDiag.SelectedPath) .Select(file => System.Drawing.Image.FromFile(file)) .ToArray(); string title = titleBox.Text == "Title" ? "untitled" : titleBox.Text; PdfDocument book = new PdfDocument(title + ".pdf"); PdfPage page; PdfContents contents; PdfImage pic; foreach (Image i in pages) { double height = i.Height; double width = i.Width; page = new PdfPage(book, width, height); contents = new PdfContents(page); contents.SaveGraphicsState(); pic = new PdfImage(book, i); contents.DrawImage(pic, 0, 0, width, height); contents.RestoreGraphicsState(); contents.CommitToPdfFile(true); } book.CreateFile(); textBox1.Text = "Book created"; pages = null; book = null; page = null; contents = null; pic = null; } else { textBox1.Text = "No directory selected"; } }
//////////////////////////////////////////////////////////////////// /// <summary> /// Add pages to PDF document /// </summary> /// <remarks> /// The PrintDoc.Print method will call BeginPrint method, /// next it will call multiple times PrintPage method and finally /// it will call EndPrint method. /// </remarks> //////////////////////////////////////////////////////////////////// public void AddPagesToPdfDocument() { // print the document by calling BeginPrint, PrintPage multiple times and finally EndPrint Print(); // get printing results in the form of array of images one per page // image format is Metafile PreviewPageInfo[] PageInfo = ((PreviewPrintController)PrintController).GetPreviewPageInfo(); // page size in user units double PageWidth = Document.PageSize.Width / Document.ScaleFactor; double PageHeight = Document.PageSize.Height / Document.ScaleFactor; // add pages to pdf document for (int ImageIndex = 0; ImageIndex < PageInfo.Length; ImageIndex++) { // add page to document PdfPage Page = new PdfPage(Document); // add contents to the page PdfContents Contents = new PdfContents(Page); // page image Image PageImage = PageInfo[ImageIndex].Image; // empty pdf image PdfImage PdfImage = new PdfImage(Contents.Document); PdfImage.Resolution = Resolution; PdfImage.SaveAs = SaveAs; PdfImage.ImageQuality = ImageQuality; PdfImage.GrayToBWCutoff = GrayToBWCutoff; PdfImage.CropRect = Rectangle.Empty; PdfImage.CropPercent = RectangleF.Empty; // no crop if (PageCropRect.IsEmpty) { // convert metafile image to PdfImage PdfImage.LoadImage(PageImage); // draw the image Contents.DrawImage(PdfImage, 0.0, 0.0, PageWidth, PageHeight); } // crop else { int ImageWidth = PageImage.Width; int ImageHeight = PageImage.Height; PdfImage.CropRect.X = (int)(ImageWidth * PageCropRect.X / PageWidth + 0.5); PdfImage.CropRect.Y = (int)(ImageHeight * PageCropRect.Y / PageHeight + 0.5); PdfImage.CropRect.Width = (int)(ImageWidth * PageCropRect.Width / PageWidth + 0.5); PdfImage.CropRect.Height = (int)(ImageHeight * PageCropRect.Height / PageHeight + 0.5); // convert metafile image to PdfImage PdfImage.LoadImage(PageImage); // draw the image Contents.DrawImage(PdfImage, PageCropRect.X, PageHeight - PageCropRect.Y - PageCropRect.Height, PageCropRect.Width, PageCropRect.Height); } } return; }
//////////////////////////////////////////////////////////////////// // create base contents for all pages //////////////////////////////////////////////////////////////////// /// <summary> /// ovde se kreira naslov svake strane, zaglavlje tabele kao i same ivice tabela /// </summary> public void CreateBaseContents() { // create unattached contents BaseContents = new PdfContents(Document); // save graphics state BaseContents.SaveGraphicsState(); // restore graphics state BaseContents.RestoreGraphicsState(); BaseContents.DrawText(ArialBold, 14, 0.5 * PageWidth, 11.5, TextJustify.Center, "IZVEŠTAJ O ISPITIVANJU MEHANIČKIH OSOBINA"); //draw logo PdfImage Image2 = new PdfImage(Document, System.Environment.CurrentDirectory + "\\logoLjig.png"); //BaseContents.DrawImage(Image1, 0.95, p1.Y - 3.8, ImageSize.Width - 1, ImageSize.Height); BaseContents.DrawImage(Image2, 8.5, 7.7, 1.4, 0.7); BaseContents.DrawText(ArialNormal, 8, 0.48, 7.85, TextJustify.Left, "BR. ZB. IZVEŠTAJA "); BaseContents.DrawLine(1.6, 8.0, 2.3, 8.0); BaseContents.DrawLine(1.6, 7.8, 2.3, 7.8); BaseContents.DrawLine(1.6, 8.0, 1.6, 7.8); BaseContents.DrawLine(2.3, 8.0, 2.3, 7.8); BaseContents.DrawText(ArialNormal, 8, 1.6, 7.85, TextJustify.Left, _sumReport.Records[0].BrzbIzvestaja); //horizontal lines BaseContents.DrawLine(0.45, 7.6, 10.8, 7.6); //BaseContents.DrawLine(0.45, 7.4, 10.8, 7.4); BaseContents.DrawLine(0.45, 7.2, 10.8, 7.2); BaseContents.DrawLine(0.45, 7.0, 10.8, 7.0); BaseContents.DrawLine(0.45, 6.8, 10.8, 6.8); BaseContents.DrawLine(0.45, 6.6, 10.8, 6.6); BaseContents.DrawLine(0.45, 6.4, 10.8, 6.4); BaseContents.DrawLine(0.45, 6.2, 10.8, 6.2); BaseContents.DrawLine(0.45, 6.0, 10.8, 6.0); BaseContents.DrawLine(0.45, 5.8, 10.8, 5.8); BaseContents.DrawLine(0.45, 5.6, 10.8, 5.6); BaseContents.DrawLine(0.45, 5.4, 10.8, 5.4); BaseContents.DrawLine(0.45, 5.2, 10.8, 5.2); BaseContents.DrawLine(0.45, 5.0, 10.8, 5.0); BaseContents.DrawLine(0.45, 4.8, 10.8, 4.8); BaseContents.DrawLine(0.45, 4.6, 10.8, 4.6); BaseContents.DrawLine(0.45, 4.4, 10.8, 4.4); BaseContents.DrawLine(0.45, 4.2, 10.8, 4.2); BaseContents.DrawLine(0.45, 4.0, 10.8, 4.0); BaseContents.DrawLine(0.45, 3.8, 10.8, 3.8); BaseContents.DrawLine(0.45, 3.6, 10.8, 3.6); BaseContents.DrawLine(0.45, 3.4, 10.8, 3.4); BaseContents.DrawLine(0.45, 3.2, 10.8, 3.2); BaseContents.DrawLine(0.45, 3.0, 10.8, 3.0); BaseContents.DrawLine(0.45, 2.8, 10.8, 2.8); BaseContents.DrawLine(0.45, 2.6, 10.8, 2.6); BaseContents.DrawLine(0.45, 2.4, 10.8, 2.4); BaseContents.DrawLine(0.45, 2.2, 10.8, 2.2); BaseContents.DrawLine(0.45, 2.0, 10.8, 2.0); BaseContents.DrawLine(0.45, 1.8, 10.8, 1.8); BaseContents.DrawLine(0.45, 1.6, 10.8, 1.6); BaseContents.DrawLine(0.45, 1.4, 10.8, 1.4); BaseContents.DrawLine(0.45, 1.2, 10.8, 1.2); //BaseContents.DrawLine(0.45, 1.0, 10.8, 1.0);//31st row //BaseContents.DrawLine(0.45, 0.8, 10.8, 0.8);//32nd row //BaseContents.DrawLine(0.45, 0.6, 10.8, 0.6);//33th row //BaseContents.DrawLine(0.45, 0.4, 10.8, 0.4);//34th row //vertical two lines //BaseContents.DrawLine(0.45, 7.6, 0.45, 0.4);//this is for 34 rows per page //BaseContents.DrawLine(10.8, 7.6, 10.8, 0.4); BaseContents.DrawLine(0.45, 7.6, 0.45, 1.2); BaseContents.DrawLine(10.8, 7.6, 10.8, 1.2); //header BaseContents.DrawLine(0.75, 7.6, 0.75, 7.2); BaseContents.DrawText(ArialNormal, 8, 0.48, 7.42, TextJustify.Left, "RED."); BaseContents.DrawText(ArialNormal, 8, 0.48, 7.24, TextJustify.Left, "BR."); BaseContents.DrawLine(1.45 + 0.2125, 7.6, 1.45 + 0.2125, 7.2); BaseContents.DrawText(ArialNormal, 8, 1.00, 7.42, TextJustify.Left, "BROJ" /*"POLAZNI"*/); BaseContents.DrawText(ArialNormal, 8, 1.00, 7.24, TextJustify.Left, "UZORKA" /*"KVALITET"*/); BaseContents.DrawLine(2.15 + 2 * 0.2125, 7.6, 2.15 + 2 * 0.2125, 7.2); BaseContents.DrawText(ArialNormal, 8, 1.95, 7.32, TextJustify.Left, "ŠARŽA" /*"NAZIVNA"*/); //BaseContents.DrawText(ArialNormal, 8, 1.75, 7.24, TextJustify.Left, "DEBLJINA"); //BaseContents.DrawLine(3.8, 7.6, 3.8, 7.2); //BaseContents.DrawText(ArialNormal, 8, 2.67, 7.42, TextJustify.Left, "ISPITIVAČ"); BaseContents.DrawLine(4.5 - 0.7125, 7.6, 4.5 - 0.7125, 7.2); BaseContents.DrawText(ArialNormal, 8, 2.95, 7.42, TextJustify.Left, "POLAZNI" /*"BROJ"*/); BaseContents.DrawText(ArialNormal, 8, 2.95, 7.24, TextJustify.Left, "KVALITET" /*"UZORKA"*/); BaseContents.DrawLine(4.6, 7.6, 4.6, 7.2); BaseContents.DrawText(ArialNormal, 8, 3.95, 7.42, TextJustify.Left, "NAZIVNA" /*"ŠARŽA"*/); BaseContents.DrawText(ArialNormal, 8, 3.95, 7.24, TextJustify.Left, "DEBLJINA" /*"ŠARŽA"*/); //BaseContents.DrawLine(8.5, 7.6, 8.5, 7.2);//vertical line na kraju mehanicko tehnickih osobina BaseContents.DrawLine(8.5, 7.4, 8.5, 7.2); // samo za A ne za sve jel smo dodali Z BaseContents.DrawLine(4.6, 7.4, 9.4, 7.4); //horizontal line BaseContents.DrawText(ArialNormal, 8.5, 6.0, 7.45, TextJustify.Left, "MEHANIČKO-TEHNIČKE OSOBINE"); BaseContents.DrawText(ArialNormal, 8, 7.45 /*4.65*/, 7.24, TextJustify.Left, "Rm[MPa]"); BaseContents.DrawLine(5.2 + 0.00, 7.4, 5.2 + 0.00, 7.2); BaseContents.DrawText(ArialNormal, 8, 4.65 /*5.28*/, 7.24, TextJustify.Left, "R"); BaseContents.DrawText(ArialNormal, 6.5, 4.73 /*5.36*/, 7.24, TextJustify.Left, "p0.2"); BaseContents.DrawText(ArialNormal, 8, 4.92 /*5.55*/, 7.24, TextJustify.Left, "[MPa]"); BaseContents.DrawLine(5.9 + 0.00, 7.4, 5.9 + 0.00, 7.2); BaseContents.DrawText(ArialNormal, 8, 5.28 /*5.98*/, 7.24, TextJustify.Left, "R"); BaseContents.DrawText(ArialNormal, 6.5, 5.36 /*6.05*/, 7.24, TextJustify.Left, "t0.5"); BaseContents.DrawText(ArialNormal, 8, 5.55 /*6.24*/, 7.24, TextJustify.Left, "[MPa]"); BaseContents.DrawLine(6.6 + 2 * 0.00, 7.4, 6.6 + 2 * 0.00, 7.2); BaseContents.DrawText(ArialNormal, 8, 6.0 /*6.7*/, 7.24, TextJustify.Left, "ReL[MPa]"); BaseContents.DrawLine(7.3 + 3 * 0.00, 7.4, 7.3 + 3 * 0.00, 7.2); BaseContents.DrawText(ArialNormal, 8, 6.7 /*7.41*/, 7.24, TextJustify.Left, "ReH[MPa]"); BaseContents.DrawLine(8.0 + 4 * 0.00, 7.4, 8.0 + 4 * 0.00, 7.2); //BaseContents.DrawLine(8.7, 7.4, 8.7, 7.2); BaseContents.DrawText(ArialNormal, 8, 8.05, 7.24, TextJustify.Left, "A[%]"); BaseContents.DrawLine(9.0 + 4 * 0.00, 7.6, 9.0 + 4 * 0.00, 7.2);//za kraj mehanicko tehnickih osobina vertikalna linija BaseContents.DrawText(ArialNormal, 8, 9.15, 7.24, TextJustify.Left, "KV[J]"); BaseContents.DrawLine(9.6 + 4 * 0.00, 7.4, 9.6 + 4 * 0.00, 7.2); BaseContents.DrawText(ArialNormal, 8, 9.75, 7.24, TextJustify.Left, "KU[J]"); BaseContents.DrawLine(10.2 + 4 * 0.00, 7.4, 10.2 + 4 * 0.00, 7.2); //BaseContents.DrawLine(9.4, 7.4, 9.4, 7.2); //BaseContents.DrawText(ArialNormal, 8, 9.0, 7.24, TextJustify.Left, "At"); //BaseContents.DrawLine(10.8, 7.6, 10.8, 7.4);//vertical line BaseContents.DrawLine(9.4, 7.4, 10.8, 7.4);//horizontal line //BaseContents.DrawText(ArialNormal, 8, 9.45, 7.42, TextJustify.Left, "FAKTOR"); //BaseContents.DrawLine(10.2, 7.6, 10.2, 7.2);//faktor BaseContents.DrawText(ArialNormal, 8, 10.5, 7.24, TextJustify.Left, "n"); BaseContents.DrawText(ArialNormal, 8, 8.6, 7.24, TextJustify.Left, "Z[%]"); //BaseContents.DrawText(ArialNormal, 8, 0.5, 7.05, TextJustify.Left, "NAPOMENATEST"); //BaseContents.DrawLine(0.75, 7.4, 0.75, 7.2); //BaseContents.DrawLine(1.45, 7.4, 1.45, 7.2); //BaseContents.DrawLine(2.15, 7.4, 2.15, 7.2); //BaseContents.DrawLine(3.8, 7.4, 3.8, 7.2); BaseContents.DrawText(ArialNormal, 8, 0.45, 0.25, TextJustify.Left, "VERIFIKOVAO"); BaseContents.DrawLine(1.3, 0.2, 5, 0.2);//horizontal line BaseContents.DrawText(ArialNormal, 8, 7, 0.25, TextJustify.Left, "ISPITIVAČ"); BaseContents.DrawLine(7.8, 0.4, 9.8, 0.4); BaseContents.DrawLine(7.8, 0.2, 7.8, 0.4); BaseContents.DrawLine(9.8, 0.2, 9.8, 0.4); BaseContents.DrawLine(7.8, 0.2, 9.8, 0.2); BaseContents.DrawText(ArialNormal, 8, 7.8 + 0.01, 0.25, TextJustify.Left, _sumReport.Records[0].Ispitivac);//u jednom zbirnom izvestaju treba da ima samo jedan ispitivac // exit return; }
public void Test ( bool Debug, string InputFileName ) { // create document using (Document = new PdfDocument(PaperType.Letter, false, UnitOfMeasure.Inch, InputFileName)) { // set document page mode to open the layers panel Document.InitialDocDisplay = InitialDocDisplay.UseLayers; // define font ArialFont = PdfFont.CreatePdfFont(Document, "Arial", FontStyle.Bold); // open layer control object (in PDF terms optional content object) PdfLayers Layers = new PdfLayers(Document, "PDF layers group"); // set layer panel to incluse all layers including ones that are not visible Layers.ListMode = ListMode.AllPages; // Add new page PdfPage Page = new PdfPage(Document); // Add contents to page PdfContents Contents = new PdfContents(Page); // heading Contents.DrawText(ArialFont, 24, 4.25, 10, TextJustify.Center, "PDF File Writer Layer Test/Demo"); // define layers PdfLayer DrawingTest = new PdfLayer(Layers, "Drawing Test"); PdfLayer Rectangle = new PdfLayer(Layers, "Rectangle"); PdfLayer HorLines = new PdfLayer(Layers, "Horizontal Lines"); PdfLayer VertLines = new PdfLayer(Layers, "Vertical Lines"); PdfLayer QRCodeLayer = new PdfLayer(Layers, "QRCode barcode"); PdfLayer Pdf417Layer = new PdfLayer(Layers, "PDF417 barcode"); PdfLayer NoBarcodeLayer = new PdfLayer(Layers, "No barcode"); // combine three layers into one group of radio buttons QRCodeLayer.RadioButton = "Barcode"; Pdf417Layer.RadioButton = "Barcode"; NoBarcodeLayer.RadioButton = "Barcode"; // set the order of layers in the layer pane Layers.DisplayOrder(DrawingTest); Layers.DisplayOrder(Rectangle); Layers.DisplayOrder(HorLines); Layers.DisplayOrder(VertLines); Layers.DisplayOrderStartGroup("Barcode group"); Layers.DisplayOrder(QRCodeLayer); Layers.DisplayOrder(Pdf417Layer); Layers.DisplayOrder(NoBarcodeLayer); Layers.DisplayOrderEndGroup(); // start a group layer Contents.LayerStart(DrawingTest); // sticky note annotation PdfAnnotation StickyNote = Page.AddStickyNote(2.0, 9.0, "My sticky note", StickyNoteIcon.Note); StickyNote.LayerControl = DrawingTest; // draw a single layer Contents.LayerStart(Rectangle); Contents.DrawText(ArialFont, 14, 1.0, 8.0, TextJustify.Left, "Draw rectangle"); Contents.LayerEnd(); // draw a single layer Contents.LayerStart(HorLines); Contents.DrawText(ArialFont, 14, 1.0, 7.5, TextJustify.Left, "Draw horizontal lines"); Contents.LayerEnd(); // draw a single layer Contents.LayerStart(VertLines); Contents.DrawText(ArialFont, 14, 1.0, 7.0, TextJustify.Left, "Draw vertical lines"); Contents.LayerEnd(); double Left = 4.0; double Right = 7.0; double Top = 9.0; double Bottom = 6.0; // draw a single layer Contents.LayerStart(Rectangle); Contents.SaveGraphicsState(); Contents.SetLineWidth(0.1); Contents.SetColorStroking(Color.Black); Contents.SetColorNonStroking(Color.LightBlue); Contents.DrawRectangle(Left, Bottom, 3.0, 3.0, PaintOp.CloseFillStroke); Contents.RestoreGraphicsState(); Contents.LayerEnd(); // save graphics state Contents.SaveGraphicsState(); // draw a single layer Contents.SetLineWidth(0.02); Contents.LayerStart(HorLines); for (int Row = 1; Row < 6; Row++) { Contents.DrawLine(Left, Bottom + 0.5 * Row, Right, Bottom + 0.5 * Row); } Contents.LayerEnd(); // draw a single layer Contents.LayerStart(VertLines); for (int Col = 1; Col < 6; Col++) { Contents.DrawLine(Left + 0.5 * Col, Bottom, Left + 0.5 * Col, Top); } Contents.LayerEnd(); // restore graphics state Contents.RestoreGraphicsState(); // terminate a group of layers Contents.LayerEnd(); // define QRCode barcode QREncoder QREncoder = new QREncoder(); QREncoder.ErrorCorrection = ErrorCorrection.M; QREncoder.Encode(QRCodeArticle); PdfImage QRImage = new PdfImage(Document); QRImage.LoadImage(QREncoder); // define PDF417 barcode Pdf417Encoder Pdf417Encoder = new Pdf417Encoder(); Pdf417Encoder.ErrorCorrection = ErrorCorrectionLevel.AutoMedium; Pdf417Encoder.Encode(Pdf417Article); PdfImage Pdf417Image = new PdfImage(Document); Pdf417Image.LoadImage(Pdf417Encoder); // draw a single layer Contents.LayerStart(QRCodeLayer); Contents.DrawText(ArialFont, 14, 1.0, 2.5, TextJustify.Left, "QRCode Barcode"); Contents.DrawImage(QRImage, 3.7, 2.5 - 1.75, 3.5); Contents.LayerEnd(); // draw a single layer Contents.LayerStart(Pdf417Layer); Contents.DrawText(ArialFont, 14, 1.0, 2.5, TextJustify.Left, "PDF417 Barcode"); Contents.DrawImage(Pdf417Image, 3.7, 2.5 - 1.75 * Pdf417Encoder.ImageHeight / Pdf417Encoder.ImageWidth, 3.5); Contents.LayerEnd(); // draw a single layer Contents.LayerStart(NoBarcodeLayer); Contents.DrawText(ArialFont, 14, 1.0, 3.0, TextJustify.Left, "Display no barcode"); Contents.LayerEnd(); // create pdf file Document.CreateFile(); // start default PDF reader and display the file Process Proc = new Process(); Proc.StartInfo = new ProcessStartInfo(InputFileName); Proc.Start(); } return; }
public FileInfo CreateOfferDocument(Offer offer, bool asOrder = false, bool withPreview = true) { ResetVars(); myOffer = offer; PdfDocument doc; PdfPage page; PdfContents content; PdfImage img; double lineSpacing; double descent; const double fontSize = 10.0; bool isOffer = (this.myOffer.Bestellkennzeichen | asOrder); string fullName = Path.Combine(CatalistRegistry.Application.OfferFilePath, offer.OfferId + ".pdf"); doc = new PdfDocument(PaperType.A4, false, UnitOfMeasure.mm, fullName); doc.Debug = false; page = new PdfPage(doc); content = new PdfContents(page); content.SetLineWidth(0.03); fontDefault = new PdfFont(doc, "Calibri", System.Drawing.FontStyle.Regular, true); myFontBold = new PdfFont(doc, "Calibri", System.Drawing.FontStyle.Bold, true); fontFooter = new PdfFont(doc, "Calibri Light", System.Drawing.FontStyle.Regular, true); fontFooterBold = new PdfFont(doc, "Calibri Light", System.Drawing.FontStyle.Bold, true); fontPriceTotal = new PdfFont(doc, "Calibri Light", System.Drawing.FontStyle.Bold, true); lineSpacing = fontDefault.LineSpacing(fontSize); descent = fontDefault.Descent(fontSize); // Header string imagePath = Path.Combine(CatalistRegistry.Application.PicturePath, "briefkopf.png"); img = new PdfImage(doc, imagePath); content.DrawImage(img, 5, pageHeight - 27.9 - 5, 199.6, 27.4); content.DrawLine(xLeftMargin - 5, pageHeight - 27.9 - 5 - 2, xRightMargin + 5, pageHeight - 27.9 - 5 - 2); string absender = @"Cut & Print Media GmbH & Co. KG · Osterheide 9 · 49124 Georgsmarienhütte"; content.DrawText(fontDefault, fontSize - 4, 18, pageHeight - 49.5, absender); content.DrawLine(18, pageHeight - 50.5, 84.5, pageHeight - 50.5, 0.1); content.DrawText(fontDefault, fontSize + 2, 18, pageHeight - 55, offer.Customer.CompanyName1); content.DrawText(fontDefault, fontSize + 2, 18, pageHeight - 65, offer.Customer.Street); string zipCity = string.Format("{0} {1}", offer.Customer.ZipCode, offer.Customer.City); content.DrawText(fontDefault, fontSize + 2, 18, pageHeight - 71, zipCity); string vorgang = isOffer ? "Bestellung" : "Angebot"; content.DrawText(fontDefault, fontSize + 2, xVLine3 + 5, pageHeight - 55, "Kunden-Nr.:"); content.DrawText(fontDefault, fontSize + 2, xVLine5 - 13, pageHeight - 55, offer.CustomerId.Substring(0, 5)); content.DrawText(fontDefault, fontSize + 2, xVLine3 + 5, pageHeight - 60, vorgang + " Nr.:"); content.DrawText(fontDefault, fontSize + 2, xVLine5 - 13, pageHeight - 60, offer.OfferId); content.DrawText(fontDefault, fontSize + 2, xVLine3 + 5, pageHeight - 65, "Datum:"); content.DrawText(fontDefault, fontSize + 2, xVLine5 - 13, pageHeight - 65, offer.ChangeDate.ToShortDateString()); content.DrawText(fontDefault, fontSize + 2, xVLine3 + 5, pageHeight - 70, "Bearbeitet von:"); content.DrawText(fontDefault, fontSize + 2, xVLine5 - 13, pageHeight - 70, offer.ChangeUser); content.DrawText(myFontBold, fontSize + 2, 10, pageHeight - 96.5, vorgang + " " + offer.OfferId); var table = new PdfTable(page, content, fontDefault, 9); table.TableStartEvent += tab_TableStartEvent; table.TableEndEvent += tab_TableEndEvent; table.TableArea = new PdfRectangle(10D, 35D, 200D, pageHeight - 40); table.RowTopPosition = pageHeight - 100D; // 10cm vom oberen Rand table.SetColumnWidth(9D, 34D, 86D, 13D, 19D, 19D); table.HeaderOnEachPage = true; table.Header[colPos].Style = table.HeaderStyle; table.Header[colPos].Style.Alignment = System.Drawing.ContentAlignment.MiddleRight; table.Header[colPos].Value = "Pos."; table.Header[colArtNr].Value = "Artikel-Nr."; table.Header[colArtBez].Value = "Artikelbezeichnung"; table.Header[colMenge].Style = table.HeaderStyle; table.Header[colMenge].Style.Alignment = System.Drawing.ContentAlignment.MiddleRight; table.Header[colMenge].Value = "Menge"; table.Header[colPreis].Style = table.HeaderStyle; table.Header[colPreis].Style.Alignment = System.Drawing.ContentAlignment.MiddleRight; table.Header[colPreis].Value = "Einzelpreis"; table.Header[colGesamt].Style = table.HeaderStyle; table.Header[colGesamt].Style.Alignment = System.Drawing.ContentAlignment.MiddleRight; table.Header[colGesamt].Value = "Gesamtpreis"; table.DefaultHeaderStyle.Font = myFontBold; table.DefaultHeaderStyle.Alignment = System.Drawing.ContentAlignment.TopLeft; table.DefaultHeaderStyle.MultiLineText = false; table.DefaultCellStyle.Font = fontDefault; table.DefaultCellStyle.FontSize = 9; table.DefaultCellStyle.Alignment = System.Drawing.ContentAlignment.TopLeft; table.Cell[colPos].Style = table.CellStyle; table.Cell[colPos].Style.Alignment = System.Drawing.ContentAlignment.TopRight; table.Cell[colArtNr].Style = table.CellStyle; table.Cell[colArtNr].Style.TextBoxTextJustify = TextBoxJustify.Left; table.Cell[colArtBez].Style = table.CellStyle; table.Cell[colArtBez].Style.TextBoxTextJustify = TextBoxJustify.Left; table.Cell[colMenge].Style = table.CellStyle; table.Cell[colMenge].Style.Format = "#,##0"; table.Cell[colMenge].Style.Alignment = System.Drawing.ContentAlignment.TopRight; table.Cell[colPreis].Style = table.CellStyle; table.Cell[colPreis].Style.Format = "#,##0.00"; table.Cell[colPreis].Style.Alignment = System.Drawing.ContentAlignment.TopRight; table.Cell[colGesamt].Style = table.CellStyle; table.Cell[colGesamt].Style.ForegroundColor = System.Drawing.Color.DarkRed; table.Cell[colGesamt].Style.Format = "#,##0.00"; table.Cell[colGesamt].Style.Alignment = System.Drawing.ContentAlignment.TopRight; int dCount = offer.OfferDetails.Count; for (int i = 0; i < dCount; i++) { lastRow |= i == dCount - 1; table.Cell[colPos].Value = offer.OfferDetails[i].Position; table.Cell[colArtNr].Value = offer.OfferDetails[i].Artikelnummer; TextBox txtBezeichnung = table.Cell[colArtBez].CreateTextBox(); txtBezeichnung.AddText(myFontBold, 9, offer.OfferDetails[i].Artikelname); if (!isOffer) { txtBezeichnung.AddText(fontDefault, 9, string.Format("\n\n{0}", offer.OfferDetails[i].Artikeltext.Replace("\t", " "))); } table.Cell[colMenge].Value = string.Format("{0:#,##0} {1}", offer.OfferDetails[i].Menge, offer.OfferDetails[i].Einheit); if (!isOffer) { table.Cell[colPreis].Value = offer.OfferDetails[i].Kundenpreis; table.Cell[colGesamt].Value = offer.OfferDetails[i].Zeilensumme; zwischenSumme += offer.OfferDetails[i].Zeilensumme; } else { table.Cell[colPreis].Value = "-"; table.Cell[colGesamt].Value = "-"; } table.DrawRow(offer.OfferDetails[i].NeueSeite); } table.Close(); try { doc.CreateFile(); if (File.Exists(fullName) && withPreview) { // Datei in das lokale TEMP Verzeichnis kopieren var temp = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); string prefix = asOrder ? "B" : "A"; var tempFilename = string.Format("{0}{1}.pdf", prefix, DateTime.Now.ToString("yyyy-MM-dd_hh.mm.ss")); var tempFileAndPath = Path.Combine(temp, tempFilename); File.Copy(fullName, tempFileAndPath); var proc = new Process(); proc.StartInfo = new ProcessStartInfo(tempFileAndPath); proc.Start(); } return(new FileInfo(fullName)); } catch (Exception ex) { throw ex; } }