private void btnOk_Click(object sender, EventArgs e) { this.DialogResult = DialogResult.OK; List <int> pageIndexes = new List <int>(); for (int i = 0; i < lvPages.Items.Count; i++) { if (lvPages.Items[i].Checked) { pageIndexes.Add(i); } } /*Bitmap[] bmps = MupdfSharp.PageRenderer.Render(path, PAGETHEIGHTPIXEL, pageIndexes.ToArray()); * for(int i = 0; i < bmps.Length; i++) * { * Bitmap tmp = bmps[i]; * bmps[i] = tmp.MakeBackgroundTransparent(Color.White); * tmp.Dispose(); * }*/ if (!Directory.Exists(TmpManager.GetTmpDir() + "\\render")) { Directory.CreateDirectory(TmpManager.GetTmpDir() + "\\render"); } Pages = new KPage[pageIndexes.Count]; pdf.PdfDocument pdfdoc = pdf_io.PdfReader.Open(path, pdf_io.PdfDocumentOpenMode.Modify | pdf_io.PdfDocumentOpenMode.Import); for (int i = 0; i < pageIndexes.Count; i++) { int p = pageIndexes[i]; KPage page = new KPage(KDocument.EmptyDocument); pdf.PdfPage pPage = pdfdoc.Pages[p]; float w = (float)pPage.Width.Millimeter; float h = (float)pPage.Height.Millimeter; if (pPage.Rotate == 90 || pPage.Rotate == 270) { Util.Swap(ref w, ref h); } page.Format = new PageFormat(w, h); page.Background = null; page.ShowDate = false; page.OriginalPage = pPage; /*page.BackgroundImage * = new Renderer.Image(bmps[i]);*/ page.PdfRenderPath = TmpManager.NewFilename(TmpManager.GetTmpDir() + "\\render", "page", ".png"); Pages[i] = page; } pdfdoc.Close(); }
public void createPDF(Bitmap bmp, string saveAsPath) { PdfDocument doc = new PdfDocument(); PdfPage page = doc.AddPage(new PdfPage()); //new //doc.Pages.Add(new PdfPage()); //old page.Width = bmp.Height; page.Height = bmp.Width; page.Orientation = PdfSharp.PageOrientation.Landscape; XGraphics xgr = XGraphics.FromPdfPage(page); XImage image = XImage.FromGdiPlusImage(bmp); xgr.DrawImage(image, 0, 0); doc.Save(saveAsPath); doc.Close(); }
private static void combinaPDF(List<string> files) { string originalFile = files[0]; string destFile = ""; PdfDocument output; //try //{ // output = PdfReader.Open(originalFile, PdfDocumentOpenMode.Modify); //} //catch (PdfSharp.PdfSharpException) //{ // destFile = System.IO.Path.GetTempFileName(); // System.IO.File.Copy(originalFile, destFile, true); // output = new PdfDocument(destFile); //} destFile = System.IO.Path.GetTempFileName(); output = new PdfDocument(destFile); foreach (string file in files) { //if (file != originalFile || !string.IsNullOrWhiteSpace(destFile)) //{ PdfDocument input = PdfReader.Open(file, PdfDocumentOpenMode.Import); int count = input.PageCount; for (int idx = 0; idx < count; idx++) { PdfPage page = input.Pages[idx]; output.AddPage(page); } System.IO.File.Delete(file); //} } output.Save(originalFile); output.Close(); output.Dispose(); if (!string.IsNullOrWhiteSpace(destFile)) { System.IO.File.Delete(originalFile); System.IO.File.Copy(destFile, originalFile, true); System.IO.File.Delete(destFile); } }
private void comPDF0(List <string> filelist, string path0) { Sharp.PdfDocument outputDocument = new Sharp.PdfDocument(); outputDocument.PageLayout = Sharp.PdfPageLayout.TwoColumnLeft; foreach (string f in filelist) { Sharp.PdfDocument inputDocument = SharpIO.PdfReader.Open(f, SharpIO.PdfDocumentOpenMode.Import); int count = inputDocument.PageCount; for (int idx = 0; idx < count; idx++) { Sharp.PdfPage page = inputDocument.Pages[idx]; outputDocument.AddPage(page); } inputDocument.Close(); } string filename = path0; outputDocument.Save(filename); }
//2 private void MergenAllPDFsIntoOnePDF_Click(object sender, EventArgs e) { PdfSharp.Pdf.PdfDocument onePdf; PdfSharp.Pdf.PdfDocument outPdf = new PdfSharp.Pdf.PdfDocument(); pathOfFolderWithMergedPDF = pathOfFolderOnDesktop + "\\2"; System.IO.Directory.CreateDirectory(pathOfFolderWithMergedPDF); DirectoryInfo toChange = new DirectoryInfo(pathOfFolderWithAllNumberedPDFs); foreach (var fi in toChange.GetFiles().OrderBy(fi => fi.Name)) { onePdf = PdfSharp.Pdf.IO.PdfReader.Open(fi.FullName, PdfDocumentOpenMode.Import); CopyPages(onePdf, outPdf); onePdf.Close(); //fi.Delete(); } outPdf.Save(pathOfFolderWithMergedPDF + "\\" + "Merge.pdf"); outPdf.Close(); MessageBox.Show("Alle Zeichnungen werden in" + pathOfFolderWithMergedPDF + " Merge.pdf zusammengefügt", "My Application", MessageBoxButtons.OK, MessageBoxIcon.Question); EnableOnlyOneButton(btnNameChange); }
private void button1_Click(object sender, EventArgs e) { string target = this.tbxInput.Text; string cat = this.tbxSet.Text; int size = int.Parse(this.tbxSize.Text); string pdf = this.tbxOutput.Text; int labelsize = int.Parse(this.tbxLabelSize.Text); int lwidth = int.Parse(this.tbxWidth.Text); int label_h = labelsize; int size_w = size; int size_h = size + label_h; List<string> pdfpages = new List<string>(); IPageLayout3 layout = new PageLayoutClass(); IGraphicsContainer con = layout as IGraphicsContainer; IPage page = layout.Page; page.FormID = esriPageFormID.esriPageFormA4; page.Units = esriUnits.esriPoints; double width; double height; page.QuerySize(out width, out height); int col = (int)Math.Floor(width / size_w); int row = (int)Math.Floor(height / size_h); IStyleGalleryStorage sgs = new StyleGalleryClass(); while (sgs.FileCount > 0) { sgs.RemoveFile(sgs.get_File(0)); } IStyleGallery sg = sgs as IStyleGallery; sgs.AddFile(target); sgs.TargetFile = target; if (cbPoint.Checked) { List<string> ps = ExportSymbol(sg, "Marker Symbols", col, row, size, lwidth,labelsize, label_h, size_w, size_h, height, cat, layout); pdfpages.AddRange(ps); } if(cbLine.Checked) { List<string> ps = ExportSymbol(sg, "Line Symbols", col, row, size, lwidth, labelsize, label_h, size_w, size_h, height, cat, layout); pdfpages.AddRange(ps); } if (cbArea.Checked) { List<string> ps = ExportSymbol(sg, "Fill Symbols", col, row, size, lwidth, labelsize, label_h, size_w, size_h, height, cat, layout); pdfpages.AddRange(ps); } PdfDocument doc = new PdfDocument(); foreach (string temp in pdfpages) { PdfDocument temp_doc = PdfReader.Open(temp, PdfDocumentOpenMode.Import); doc.AddPage(temp_doc.Pages[0]); } if (doc.PageCount > 0) { doc.Save(pdf); } doc.Close(); MessageBox.Show("成功生成符号图集"); }
public void Select2PDF() { foreach (ListViewItem Item in listView1.SelectedItems) { Debug.Print(Item.Index.ToString()); PdfDocument doc = new PdfDocument(); //int pageCount = listView1.Items.Count; //for (int i = 0; i <= pageCount - 1; i++) //{ PdfPage page = new PdfPage(); //Image tiffImg = tiff.getTiffImage(fileName, i); //Image tiffImg = Image.FromFile(Application.StartupPath + "temp" + i + ".png"); Image tiffImg = Image.FromStream(imgLst[Item.Index].ImageStream); XImage img = XImage.FromGdiPlusImage(tiffImg); page.Width = img.PointWidth; page.Height = img.PointHeight; doc.Pages.Add(page); //XGraphics xgr = XGraphics.FromPdfPage(doc.Pages(i)); XGraphics xgr = XGraphics.FromPdfPage(doc.Pages[0]); xgr.DrawImage(img, 0, 0); string filename = "temp" + (Item.Index +1) + ".pdf"; doc.Save(filename); doc.Close(); } }
/// <summary> /// store a pdf to a file. will call PrintPage automatically /// </summary> public void SavePDF(string AFilename, PaperKind APaperKind, Margins AMargins, float AWidthInPoint, float AHeightInPoint) { if (Directory.Exists("/usr/share/fonts/")) { PdfSharp.Internal.NativeMethods.FontDirectory = "/usr/share/fonts/"; } if (RegionInfo.CurrentRegion == null) { // https://bugzilla.novell.com/show_bug.cgi?id=588708 // RegionInfo.CurrentRegion is null throw new Exception("Mono bug: CurrentRegion is still null, invariant culture. Please set LANG environment variable"); } FPdfDocument = new PdfDocument(); do { PdfPage page = FPdfDocument.AddPage(); if (APaperKind != PaperKind.Custom) { // see if we can match PaperKind to PageSize by name foreach (PageSize MyPageSize in Enum.GetValues(typeof(PageSize))) { if (MyPageSize.ToString() == APaperKind.ToString()) { page.Size = MyPageSize; break; } } } if ((AWidthInPoint != -1) && (AHeightInPoint != -1)) { // to get the points, eg. inch * 72 page.Width = AWidthInPoint; page.Height = AHeightInPoint; } FXGraphics = XGraphics.FromPdfPage(page, XGraphicsUnit.Inch); FXGraphics.MFEH = PdfFontEmbedding.Always; // it seems for Linux we better reset the FEv, otherwise the positions are only correct on the first page, but wrong on the following pages // was: if (FEv == null) if (true) { PrinterSettings myPrinterSettings = new PrinterSettings(); PageSettings myPageSettings = new PageSettings(myPrinterSettings); myPageSettings.Color = true; myPageSettings.Landscape = false; myPageSettings.Margins = AMargins; myPageSettings.PaperSize = new PaperSize(page.Size.ToString(), Convert.ToInt32(page.Width.Point / 72.0f * 100.0f), Convert.ToInt32(page.Height.Point / 72.0f * 100.0f)); try { myPageSettings.PrinterResolution.X = DEFAULTPRINTERRESOLUTION; myPageSettings.PrinterResolution.Y = DEFAULTPRINTERRESOLUTION; } catch (Exception) { // if no printer is installed we get an exception, but it should work anyway } FEv = new PrintPageEventArgs(FXGraphics.Graphics, new Rectangle(20, 20, 787, 1110), new Rectangle(0, 0, 827, 1169), myPageSettings); FEv.HasMorePages = true; FEv.Graphics.PageUnit = GraphicsUnit.Inch; FEv.Graphics.TranslateTransform(0, 0); InitFontsAndPens(); } PrintPage(null, FEv); } while (HasMorePages()); // should we catch an exception if document cannot be written? FPdfDocument.Save(AFilename); FPdfDocument.Close(); }
private void button2_Click(object sender, EventArgs e) { System.Drawing.Rectangle r = pictureBox1.RectangleToScreen(pictureBox1.ClientRectangle); Bitmap b = new Bitmap(r.Width - 5, r.Height - 5); Graphics g = Graphics.FromImage(b); g.CopyFromScreen(r.Location, new Point(0, 0), r.Size); b.Save("111.png"); SaveFileDialog saveFileDialog1 = new SaveFileDialog(); saveFileDialog1.Filter = "pdf|*.pdf"; if (saveFileDialog1.ShowDialog() == DialogResult.OK) { PdfDocument doc = new PdfDocument(); // Set font encoding to unicode XPdfFontOptions options = new XPdfFontOptions(PdfFontEncoding.Unicode, PdfFontEmbedding.Always); XFont font = new XFont("Times New Roman", 12, XFontStyle.Regular, options); XImage img = XImage.FromFile("111.png"); PdfPage page = doc.AddPage(); XGraphics xgr = XGraphics.FromPdfPage(page); xgr.DrawImage(img,30,80,538,242); xgr.DrawString("Спроектированный шкаф: ", font, XBrushes.Black,new XRect(20, 50, page.Width - 200, 600), XStringFormats.TopCenter); doc.Save(@saveFileDialog1.FileName + ".pdf"); doc.Close(); } // File.Delete("111.png"); }
public static bool WriteToPdf(string tifFileName, string pdfFileName, string author = null, string title = null, string isbn = null) { if (String.IsNullOrEmpty(tifFileName)) new ArgumentNullException("tifFileName"); if (!System.IO.File.Exists(tifFileName)) throw new ArgumentException(String.Format("Soubor '{0}' neexistuje, nelze vytvořit PDF soubor.", tifFileName)); if (File.Exists(pdfFileName)) File.Delete(pdfFileName); using (PdfDocument doc = new PdfDocument()) { doc.Info.Author = author; doc.Info.Title = title; doc.Info.Keywords = String.Format("ISBN:{0}", isbn); doc.Info.Subject = "OBSAH"; doc.Info.Creator = App.Configuration.CompanyName; doc.Info.CreationDate = DateTime.Now; Image tiff = System.Drawing.Image.FromFile(tifFileName); int count = tiff.GetFrameCount(FrameDimension.Page); for (int pageNum = 0; pageNum < count; pageNum++) { tiff.SelectActiveFrame(FrameDimension.Page, pageNum); XImage ximg = XImage.FromGdiPlusImage(tiff); PdfPage page = new PdfPage(); page.Width = ximg.PointWidth; page.Height = ximg.PointHeight; doc.Pages.Add(page); XGraphics xgr = XGraphics.FromPdfPage(page); xgr.DrawImage(ximg, 0, 0); } doc.Save(pdfFileName); doc.Close(); } return true; }
/// <summary> /// Create a new PDF document and start the viewer. /// </summary> void MakePdf() { string filename = Guid.NewGuid().ToString().ToUpper() + ".pdf"; PdfDocument document = new PdfDocument(filename); document.Info.Creator = "Preview Sample"; PdfPage page = document.AddPage(); page.Size = PageSize.A4; XGraphics gfx = XGraphics.FromPdfPage(page); if (this.renderEvent != null) this.renderEvent(gfx); document.Close(); Process.Start(filename); }
public static void CreateParcourPDF(ParcourPictureBox picBox, Client.DataAccess c, String parcourName, String pathToPDF, String overlayText) { //PdfDocument doc = new PdfDocument(@"Resources\PDFTemplates\Competition_Map.pdf"); PdfDocument doc = new PdfDocument(); doc.Info.Author = "*****@*****.**"; doc.Info.Keywords = "ANRL Parcour Printout"; doc.Info.Subject = "Parcour Printout generated from ANRL Client on " + DateTime.Now.ToString(); doc.Info.Title = "Parcour Printout"; doc.Options.ColorMode = PdfColorMode.Cmyk; doc.Language = "EN"; doc.PageLayout = PdfPageLayout.SinglePage; PdfPage page = doc.AddPage(); page.Orientation = PdfSharp.PageOrientation.Landscape; page.Size = PdfSharp.PageSize.A4; XGraphics gfx = XGraphics.FromPdfPage(page); AddLogo(gfx, page); gfx.DrawString("Competition: " + c.SelectedCompetition.Name, new XFont("Verdana", 16, XFontStyle.Bold), XBrushes.Black, new XPoint(XUnit.FromCentimeter(2), XUnit.FromCentimeter(2))); gfx.DrawString("Parcour: " + parcourName, new XFont("Verdana", 14, XFontStyle.Bold), XBrushes.Black, new XPoint(XUnit.FromCentimeter(2), XUnit.FromCentimeter(3))); XImage image = XImage.FromGdiPlusImage(picBox.PrintOutImage); double distX = picBox.GetXDistanceKM() / 2;//1:200 000 in cm double distY = picBox.GetYDistanceKM() / 2;//1:200 000 in cm gfx.DrawImage(image, XUnit.FromCentimeter(1), XUnit.FromCentimeter(4), page.Width.Point * (distX / page.Width.Centimeter), page.Height.Point * (distY / page.Height.Centimeter)); double startX = 190; List<XPoint> points = new List<XPoint>(); points.Add(new XPoint(Unit.FromMillimeter(startX), Unit.FromMillimeter(40))); points.Add(new XPoint(Unit.FromMillimeter(startX + 18 * 5), Unit.FromMillimeter(40))); points.Add(new XPoint(Unit.FromMillimeter(startX + 18 * 5), Unit.FromMillimeter(40 + 9))); points.Add(new XPoint(Unit.FromMillimeter(startX), Unit.FromMillimeter(40 + 9))); points.Add(new XPoint(Unit.FromMillimeter(startX), Unit.FromMillimeter(40))); gfx.DrawLines(XPens.Black, points.ToArray()); for (int i = 0; i < 5; i++) { if (i == 1) continue; points = new List<XPoint>(); points.Add(new XPoint(Unit.FromMillimeter(startX + 18 * i), Unit.FromMillimeter(40))); points.Add(new XPoint(Unit.FromMillimeter(startX + 18 * i), Unit.FromMillimeter(40 + 9))); gfx.DrawLines(XPens.Black, points.ToArray()); } gfx.DrawString("Comp. Nr:", new XFont("Verdana", 14, XFontStyle.Bold), XBrushes.Black, new XPoint(Unit.FromMillimeter(startX + 1), Unit.FromMillimeter(40 + 7))); gfx.DrawString("Track:", new XFont("Verdana", 14, XFontStyle.Bold), XBrushes.Black, new XPoint(Unit.FromMillimeter(startX + 18 * 3 + 1), Unit.FromMillimeter(40 + 7))); double startY = 40 + 9 + 5; double colWidth = 18; double rowHeight = 9; for (int i = 0; i < 16; i++) { points = new List<XPoint>(); points.Add(new XPoint(Unit.FromMillimeter(startX), Unit.FromMillimeter(startY + i * rowHeight))); points.Add(new XPoint(Unit.FromMillimeter(startX + colWidth * 5), Unit.FromMillimeter(startY + i * rowHeight))); gfx.DrawLines(XPens.Black, points.ToArray()); } for (int i = 0; i < 6; i++) { points = new List<XPoint>(); points.Add(new XPoint(Unit.FromMillimeter(startX + i * colWidth), Unit.FromMillimeter(startY))); points.Add(new XPoint(Unit.FromMillimeter(startX + i * colWidth), Unit.FromMillimeter(startY + 15 * rowHeight))); gfx.DrawLines(XPens.Black, points.ToArray()); } gfx.DrawString("Dist.", new XFont("Verdana", 14, XFontStyle.Bold), XBrushes.Black, new XPoint(Unit.FromMillimeter(startX + colWidth * 1 + 1), Unit.FromMillimeter(startY + 7))); gfx.DrawString("TT", new XFont("Verdana", 14, XFontStyle.Bold), XBrushes.Black, new XPoint(Unit.FromMillimeter(startX + colWidth * 2 + 1), Unit.FromMillimeter(startY + 7))); gfx.DrawString("EET", new XFont("Verdana", 14, XFontStyle.Bold), XBrushes.Black, new XPoint(Unit.FromMillimeter(startX + colWidth * 3 + 1), Unit.FromMillimeter(startY + 7))); gfx.DrawString("ETO", new XFont("Verdana", 14, XFontStyle.Bold), XBrushes.Black, new XPoint(Unit.FromMillimeter(startX + colWidth * 4 + 1), Unit.FromMillimeter(startY + 7))); gfx.DrawString("T/O", new XFont("Verdana", 14, XFontStyle.Bold), XBrushes.Black, new XPoint(Unit.FromMillimeter(startX + 1), Unit.FromMillimeter(startY + rowHeight * 1 + 7))); gfx.DrawString("SP", new XFont("Verdana", 14, XFontStyle.Bold), XBrushes.Black, new XPoint(Unit.FromMillimeter(startX + 1), Unit.FromMillimeter(startY + rowHeight * 2 + 7))); for (int i = 3; i < 13; i++) { gfx.DrawString("TP" + (i - 3), new XFont("Verdana", 14, XFontStyle.Bold), XBrushes.Black, new XPoint(Unit.FromMillimeter(startX + 1), Unit.FromMillimeter(startY + rowHeight * i + 7))); } gfx.DrawString("FP", new XFont("Verdana", 14, XFontStyle.Bold), XBrushes.Black, new XPoint(Unit.FromMillimeter(startX + 1), Unit.FromMillimeter(startY + rowHeight * 13 + 7))); gfx.DrawImage(XImage.FromFile(@"Resources\Summe.png"), new XPoint(Unit.FromMillimeter(startX + 1), Unit.FromMillimeter(startY + rowHeight * 14 + 2))); if (overlayText != null && overlayText != "") { XRect rect = new XRect(new XPoint(Unit.FromMillimeter(startX - 80 - 2), Unit.FromMillimeter(startY + rowHeight * 14 + 2 - 16)), new XSize(Unit.FromCentimeter(8), Unit.FromCentimeter(3.6))); gfx.DrawRectangle(XBrushes.White, rect); XTextFormatter tf = new XTextFormatter(gfx); tf.DrawString(overlayText, new XFont("Verdana", 13, XFontStyle.Bold), XBrushes.Black, rect, XStringFormats.TopLeft); } doc.Save(pathToPDF); doc.Close(); Process.Start(pathToPDF); }
public static void CreateResultPDF(VisualisationPictureBox picBox, Client.DataAccess c, QualificationRound competition, List<ComboBoxFlights> competitionTeam, String pathToPDF) { int counter = 0; List<Flight> tempList = new List<Flight>(); foreach (ComboBoxFlights cbct in competitionTeam) { GC.Collect(); PdfDocument doc = new PdfDocument(); doc.Info.Author = "*****@*****.**"; doc.Info.Keywords = "ANRL Results Printout"; doc.Info.Subject = "Results Printout generated from ANRL Client on " + DateTime.Now.ToString(); doc.Info.Title = "Results Printout"; doc.Options.ColorMode = PdfColorMode.Cmyk; doc.Language = "EN"; doc.PageLayout = PdfPageLayout.SinglePage; tempList.Clear(); tempList.Add(cbct.flight); picBox.SetData(tempList); PdfPage page = doc.AddPage(); page.Orientation = PdfSharp.PageOrientation.Landscape; page.Size = PdfSharp.PageSize.A4; XGraphics gfx = XGraphics.FromPdfPage(page); AddLogo(gfx, page); XImage image = XImage.FromGdiPlusImage(picBox.PrintOutImage); double distX = picBox.GetXDistanceKM() / 2;//1:200 000 in cm double distY = picBox.GetYDistanceKM() / 2;//1:200 000 in cm gfx.DrawImage(image, XUnit.FromCentimeter(2).Point, XUnit.FromCentimeter(3).Point, page.Width.Point * (distX / page.Width.Centimeter), page.Height.Point * (distY / page.Height.Centimeter)); gfx.DrawString("Competition: " + c.SelectedCompetition.Name, new XFont("Verdana", 13, XFontStyle.Bold), XBrushes.Black, new XPoint(XUnit.FromCentimeter(2), XUnit.FromCentimeter(1.5))); gfx.DrawString("Q-Round: " + competition.Name, new XFont("Verdana", 11, XFontStyle.Bold), XBrushes.Black, new XPoint(XUnit.FromCentimeter(2), XUnit.FromCentimeter(2.1))); gfx.DrawString("Crew: " + getTeamDsc(c, cbct.flight), new XFont("Verdana", 11, XFontStyle.Bold), XBrushes.Black, new XPoint(XUnit.FromCentimeter(2), XUnit.FromCentimeter(2.7))); int sum = 0; int line = 0; int offsetLine = 20; //gfx.DrawString("ID", new XFont("Verdana", 11, XFontStyle.Bold), XBrushes.Black, new XPoint(XUnit.FromCentimeter(18), XUnit.FromCentimeter(3))); gfx.DrawString("Points ", new XFont("Verdana", 11, XFontStyle.Bold), XBrushes.Black, new XPoint(XUnit.FromCentimeter(offsetLine), XUnit.FromCentimeter(3))); gfx.DrawString("Reason ", new XFont("Verdana", 11, XFontStyle.Bold), XBrushes.Black, new XPoint(XUnit.FromCentimeter(offsetLine + 2), XUnit.FromCentimeter(3))); foreach (Penalty penalty in cbct.flight.Penalty) { sum += penalty.Points; line++; //gfx.DrawString(penalty.ID.ToString(), new XFont("Verdana", 9, XFontStyle.Regular), XBrushes.Black, new XPoint(XUnit.FromCentimeter(18), XUnit.FromCentimeter(3 + line * 0.4))); gfx.DrawString(penalty.Points.ToString(), new XFont("Verdana", 9, XFontStyle.Regular), XBrushes.Black, new XPoint(XUnit.FromCentimeter(offsetLine), XUnit.FromCentimeter(3 + line * 0.4))); List<String> reason = getWrapped(penalty.Reason); bool loop = false; foreach (String s in reason) { gfx.DrawString(s, new XFont("Verdana", 9, XFontStyle.Regular), XBrushes.Black, new XPoint(XUnit.FromCentimeter(offsetLine + 2), XUnit.FromCentimeter(3 + line * 0.4))); line++; loop = true; } if (loop) { line--; } } line++; //gfx.DrawString("-", new XFont("Verdana", 9, XFontStyle.Regular), XBrushes.Black, new XPoint(XUnit.FromCentimeter(18), XUnit.FromCentimeter(3 + line * 0.4))); gfx.DrawString(sum.ToString(), new XFont("Verdana", 10, XFontStyle.Bold), XBrushes.Black, new XPoint(XUnit.FromCentimeter(offsetLine), XUnit.FromCentimeter(3 + line * 0.4))); gfx.DrawString("Total Points", new XFont("Verdana", 10, XFontStyle.Bold), XBrushes.Black, new XPoint(XUnit.FromCentimeter(offsetLine + 2), XUnit.FromCentimeter(3 + line * 0.4))); String path = pathToPDF.Replace(".pdf", (counter++ + "_" + getTeamDsc(c, cbct.flight) + ".pdf")); doc.Save(path); doc.Close(); Process.Start(path); } }
public static void CreateParcourPDF100k(ParcourPictureBox picBox, Client.DataAccess c, String parcourName, String pathToPDF, String overlayText) { PdfDocument doc = new PdfDocument(); doc.Info.Author = "*****@*****.**"; doc.Info.Keywords = "ANRL Parcour Printout"; doc.Info.Subject = "Parcour Printout generated from ANRL Client on " + DateTime.Now.ToString(); doc.Info.Title = "Parcour Printout"; doc.Options.ColorMode = PdfColorMode.Cmyk; doc.Language = "EN"; doc.PageLayout = PdfPageLayout.SinglePage; PdfPage page = doc.AddPage(); page.Orientation = PdfSharp.PageOrientation.Landscape; page.Size = PdfSharp.PageSize.A3; XGraphics gfx = XGraphics.FromPdfPage(page); AddLogo(gfx, page); gfx.DrawString("Competition: " + c.SelectedCompetition.Name, new XFont("Verdana", 16, XFontStyle.Bold), XBrushes.Black, new XPoint(XUnit.FromCentimeter(2), XUnit.FromCentimeter(2))); gfx.DrawString("Parcour: " + parcourName, new XFont("Verdana", 14, XFontStyle.Bold), XBrushes.Black, new XPoint(XUnit.FromCentimeter(2), XUnit.FromCentimeter(3))); XImage image = XImage.FromGdiPlusImage(picBox.PrintOutImage); double distX = picBox.GetXDistanceKM();//1:100 000 in cm double distY = picBox.GetYDistanceKM();//1:100 000 in cm gfx.DrawImage(image, XUnit.FromCentimeter(1), XUnit.FromCentimeter(4), page.Width.Point * (distX / page.Width.Centimeter), page.Height.Point * (distY / page.Height.Centimeter)); if (overlayText != null && overlayText != "") { XRect rect = new XRect(new XPoint(Unit.FromCentimeter(page.Width.Centimeter - 8), Unit.FromCentimeter(page.Height.Centimeter-4)), new XSize(Unit.FromCentimeter(8), Unit.FromCentimeter(3.6))); gfx.DrawRectangle(XBrushes.White, rect); XTextFormatter tf = new XTextFormatter(gfx); tf.DrawString(overlayText, new XFont("Verdana", 13, XFontStyle.Bold), XBrushes.Black, rect, XStringFormats.TopLeft); } doc.Save(pathToPDF); doc.Close(); Process.Start(pathToPDF); }
//Scanner Click Event private void btnScan_Click(object sender, EventArgs e) { try { // Select the scanner from list var device = lbDevices.SelectedItem as Scanner; this.txtProgress.Text="You selected "+device+" as your Scanner"; if (device == null) { System.Windows.MessageBox.Show("Please select a device.", "Warning"); return; } // Scan var image = device.Scan(); //List to hold images List<WIA.ImageFile> wiaImagesList = new List<WIA.ImageFile>(); //Add to list wiaImagesList.Add(image); if (wiaImagesList.Count() == 0) { return; } this.txtProgress.Text = "Scanning in Progress..........."; //creat pdf PdfDocument doc = new PdfDocument(); string destination = @"C:\ScannerFolder\" + DateTime.Now.ToString("yyyy-MM-dd HHmmss") + ".pdf"; string tempDestination = @"C:\TempScannerFolder" + DateTime.Now.ToString("yyyy-MM-dd HHmmss") + ".pdf"; //create folder to store image System.IO.Directory.CreateDirectory(folderName); System.IO.Directory.CreateDirectory(tempFolderName); foreach (WIA.ImageFile img in wiaImagesList) { //For each image to be scanned string tempFilename = @"C:\ScannerFolder\" + rtbResult.Text + DateTime.Now.ToString("yyyy-MM-dd HHmmss") + ".tiff"; string filename = @"C:\TempScannerFolder\" + rtbResult.Text + DateTime.Now.ToString("yyyy-MM-dd HHmmss") + ".tiff";// can get barcode from rtbResult.Text to save image as barcode //save the tiff image.SaveFile(filename); //add image to the pdf and Custom user control and save doc.Pages.Add(new PdfPage()); XGraphics xgr = XGraphics.FromPdfPage(doc.Pages[0]); XImage imgX = XImage.FromFile(filename); xgr.DrawImage(imgX, 0, 0); //save to destinatin folder doc.Save(destination); //doc.Save(tempFilename); showPath.Text += destination; tempList.Add(destination); doc.Close(); this.txtProgress.Text = "Scanning complete, converting to PDF"; // User control to display pdf var uc = new UserControl1(destination); this.windowsFormsHost1.Child = uc; } //Convert Wia imageFile to a bitmap Bitmap bmp = ConvertImageToBitmap(image); DateTime dtStart = DateTime.Now; //read barcode form Bitmap string[] barcode = ReadBarcodeFromBitmap(bmp); // Show the results in a message box string result = string.Empty; if (barcode != null) { foreach (String code in barcode){ result += code; } } else{ result += "Failed to find a barcode."; } //Show barcode rtbResult.Text = result; GetDocumentType(); } catch (Exception) { System.Windows.MessageBox.Show("A scanner error occoured, check feeder"); } }
public void MakePDF(List<int[,]> cards) { string imgName = @"BingoPlader.png"; string imgSource = Path.Combine(Directory.GetCurrentDirectory(), "..\\..\\", @"Resources\", imgName); if (_outputDirectory != null) { imgSource = _outputDirectory; } string saveLoc = imgSource.Replace("png", "pdf"); PdfDocument doc = new PdfDocument(); XImage img = XImage.FromFile(imgSource); XFont numberFont = new XFont("Verdana", 125, XFontStyle.Italic); XFont plateNumFont = new XFont("Verdana", 30, XFontStyle.Regular); XImage pdfSize = XImage.FromFile(imgSource); #region PixelStuff int startPlateY = 834; int startX = 356; int jumpX = 222; int jumpY = 240; int jumpYPlate = 796; int plateNumX = 45; int plateNumY = 3300; #endregion for (int i = 0; i < cards.Count; i++) { if (cards[i][0,0] != -1) { PdfPage page = new PdfPage(); //Template for page //XSize size = PageSizeConverter.ToSize(PdfSharp.PageSize.A4); page.Width = pdfSize.PixelWidth; page.Height = pdfSize.PixelHeight; page.TrimMargins.Top = 0; page.TrimMargins.Right = 0; page.TrimMargins.Bottom = 0; page.TrimMargins.Left = -30; doc.Pages.Add(page); XGraphics xgr = XGraphics.FromPdfPage(doc.Pages[doc.PageCount-1]); xgr.DrawImage(img, 0, 0, page.Width, page.Height); int plateChooser = startPlateY; int rowChooser = plateChooser; int columnChooser = startX; for (int j = 0; j < 3; j++) //Pladenummer. Styrer y-akses startpunkt { rowChooser = plateChooser; for (int row = 0; row < 3; row++) //rækkenummer. Placerer y-akseværdi { for (int column = 0; column < 9; column++) { if (cards[i][column, row] != 0) { if (cards[i][column, row] < 10) { xgr.DrawString(" " + Convert.ToString(cards[i][column, row]), numberFont, XBrushes.Black, new XRect(columnChooser, rowChooser, 10, 0), XStringFormats.TopLeft); } else xgr.DrawString(Convert.ToString(cards[i][column, row]), numberFont, XBrushes.Black, new XRect(columnChooser, rowChooser, 10, 0), XStringFormats.TopLeft); } columnChooser += jumpX; //Hopper med en kolonne per iteration } columnChooser = startX; rowChooser += jumpY; //Hopper en række per iteration } plateChooser += jumpYPlate; // hopper en plade per iteration } xgr.DrawString("Pladenummer: " + Convert.ToString(i), plateNumFont, XBrushes.Black, new XRect(plateNumX, plateNumY, 10, 0), XStringFormats.TopLeft); } } doc.Save(saveLoc); doc.Close(); }
private void btnPdf_Click(object sender, System.EventArgs e) { string filename = Guid.NewGuid().ToString().ToUpper() + ".pdf"; PdfDocument document = new PdfDocument(filename); PdfPage page = document.AddPage(); page.Size = PageSize.A4; XGraphics gfx = XGraphics.FromPdfPage(page); this.chartFrame.Draw(gfx); document.Close(); Process.Start(filename); }
public void OKCmdExecute() { if (System.IO.File.Exists(GetSavePath())) { DialogResult result = MessageBox.Show("Exist, wanna replace?", "Exist, wanna replace?", MessageBoxButtons.YesNo); if(result == DialogResult.Yes) { System.IO.File.Delete(GetSavePath()); } else if(result == DialogResult.No) { return; } } List<PdfDocument> documents = new List<PdfDocument>(); PdfDocument outPdf = new PdfDocument(); try { foreach (File file in selectedFiles) { PdfDocument pdf = PdfReader.Open(file.Path, PdfDocumentOpenMode.Import); documents.Add(pdf); CopyPages(pdf, outPdf); } Directory.CreateDirectory(Path.GetDirectoryName(GetSavePath())); outPdf.Save(GetSavePath()); } catch (Exception e) { outPdf.Close(); return; } outPdf.Close(); MySqlHelper.RefreshAll(); }
void MakePdf() { // Let's torture the garbage collector... const int fileCount = 1; const int pageCount = 1; string lastFilename = ""; for (int fileIdx = 0; fileIdx < fileCount; fileIdx++) { string filename = Guid.NewGuid().ToString().ToUpper() + ".pdf"; //PdfSharp.Drawing.XGraphic gfx = new PdfSharp.Drawing.XGraphic(); PdfDocument document = new PdfDocument(filename); document.Options.ColorMode = XGraphicsLab.properties.General.ColorMode; #if true_ DateTime now = DateTime.Now; for (int i = 0; i < 10000000; i++) document.Info.Title = "Hallö €-δ-α-β-☺♥♦♠♣x"; TimeSpan span = DateTime.Now - now; Debug.WriteLine("span = " + span.TotalSeconds.ToString()); #endif for (int pageIdx = 0; pageIdx < pageCount; pageIdx++) { PdfPage page = document.AddPage(); page.Size = PageSize.A4; XGraphics gfx = XGraphics.FromPdfPage(page, XGraphicsLab.properties.General.PageDirection); if (this.renderEvent != null) this.renderEvent(gfx); } //document.WriteToFile(filename); #if true_ // Check protection document.SecuritySettings.UserPassword = "******"; document.SecuritySettings.OwnerPassword = "******"; //document.SecuritySettings.PermitModifyDocument = false; //document.SecuritySettings.PermitPrint = true; #endif document.Close(); lastFilename = filename; } UpdateStatusBar(); Process.Start(lastFilename); }
private void toolStripButton1_Click(object sender, EventArgs e) { SaveFileDialog svdlg = new SaveFileDialog(); if (svdlg.ShowDialog() == System.Windows.Forms.DialogResult.OK) { Bitmap MemoryImage = new Bitmap(groupBox1.Width, groupBox1.Height); Rectangle rect = new Rectangle(0, 0, groupBox1.Width, groupBox1.Height); groupBox1.DrawToBitmap(MemoryImage, new Rectangle(0, 0, groupBox1.Width, groupBox1.Height)); PdfDocument doc = new PdfDocument(); doc.Pages.Add(new PdfPage()); XGraphics xgr = XGraphics.FromPdfPage(doc.Pages[0]); XImage img = XImage.FromGdiPlusImage(MemoryImage);//XImage.FromFile(source); xgr.DrawImage(img, 0, 0); doc.Save(svdlg.FileName); doc.Close(); } }
private string MakePdf(IEnumerable<DownloadFile> listPictures) { try { using (var document = new PdfDocument()) { document.Info.Creator = "TWAIN@Web 1.3beta (http://unit6.ru/twain-web)"; var dir = Path.GetTempPath(); foreach (var image in listPictures) { // Create an empty page var page = document.AddPage(); // Get an XGraphics object for drawing var gfx = XGraphics.FromPdfPage(page); var ximage = XImage.FromFile(dir + image.TempFile); page.Height = ximage.PointHeight; page.Width = ximage.PointWidth; gfx.DrawImage(ximage, 0, 0); ximage.Dispose(); } var file = Path.GetTempFileName(); document.Save(file); document.Close(); var fileId = Path.GetFileName(file); GlobalDictionaries.Scans.Add(fileId); return fileId; } } catch (Exception ex) { return null; } }
private void btnPdf_Click(object sender, System.EventArgs e) { string filename = Guid.NewGuid().ToString().ToUpper() + ".pdf"; //PdfSharp.Drawing.XGraphic gfx = new PdfSharp.Drawing.XGraphic(); PdfDocument document = new PdfDocument(filename); PdfPage page = document.AddPage(); double width = page.Width; double height = page.Height; page.Height = width; page.Width = height; XGraphics gfx = XGraphics.FromPdfPage(page); this.tester.RenderPage(gfx); //document.WriteToFile(filename); document.Close(); Process.Start(filename); }
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e) { if (backgroundWorker1 != null) { while (!backgroundWorker1.CancellationPending && finished == false) { int i = 0; backgroundWorker1.ReportProgress(i); //============Variables=========================// string inputfile = input_bestand; string inputfolder = System.IO.Path.GetTempPath() + "\\strips"; string outputfile = Path.GetDirectoryName(inputfile) + "\\" + Path.GetFileNameWithoutExtension(inputfile) + ".pdf"; i = 20; backgroundWorker1.ReportProgress(i); // Determine whether the directory exists. if (!Directory.Exists(inputfolder)) { DirectoryInfo di = Directory.CreateDirectory(inputfolder); } System.IO.DirectoryInfo downloadedMessageInfo = new DirectoryInfo(System.IO.Path.GetTempPath() + "\\strips"); foreach (FileInfo file in downloadedMessageInfo.GetFiles()) { file.Delete(); } foreach (DirectoryInfo dir in downloadedMessageInfo.GetDirectories()) { dir.Delete(true); } i = 40; backgroundWorker1.ReportProgress(i); //CBR Unzipping=========================================// Chilkat.Rar rar = new Chilkat.Rar(); Chilkat.Zip zip = new Chilkat.Zip(); zip.UnlockComponent("ZIPT34MB34N_2E76BEB1p39E"); bool rarsuccess; bool zipsucces; rarsuccess = rar.Open(inputfile); if (rarsuccess != true) { zipsucces = zip.OpenZip(inputfile); if (zipsucces != true) { MessageBox.Show(zip.LastErrorText); System.Environment.Exit(1); } } rarsuccess = rar.Unrar(inputfolder); if (rarsuccess != true) { int zipreturn = zip.Unzip(inputfolder); if (zipreturn == -1) { MessageBox.Show(zip.LastErrorText); System.Environment.Exit(1); } } else { } i = 60; backgroundWorker1.ReportProgress(i); string[] folders_all = System.IO.Directory.GetDirectories(inputfolder, "*", System.IO.SearchOption.AllDirectories); string[] plaatjes; if (folders_all.Length == 0) { plaatjes = Directory.GetFiles(inputfolder, "*.jpg"); } else { string folder = folders_all[0]; plaatjes = Directory.GetFiles(folder, "*.jpg"); } PdfDocument doc = new PdfDocument(); foreach (string source in plaatjes) { PdfPage page = doc.AddPage(); XGraphics xgr = XGraphics.FromPdfPage(page); XImage img = XImage.FromFile(source); xgr.DrawImage(img, 0, 0, 595, 841); } i = 80; backgroundWorker1.ReportProgress(i); doc.Save(outputfile); doc.Close(); i = 100; finished = true; backgroundWorker1.ReportProgress(i); } } }
/// <summary> /// Takes a Bitmap and a file path and saves the bitmap as a pdf /// </summary> /// <param name="bitmap"></param> /// <param name="pathPdf"></param> private void saveAsPdf(Bitmap bitmap, string pathPdf) { var doc = new PdfDocument(); doc.Pages.Add(new PdfPage()); var xgr = XGraphics.FromPdfPage(doc.Pages[0]); var img = XImage.FromGdiPlusImage(bitmap); xgr.DrawImage(img, 0, 0, doc.Pages[0].Width, doc.Pages[0].Height); doc.Save(pathPdf); doc.Close(); }
public void tiff2PDF() { PdfDocument doc = new PdfDocument(); //int pageCount = tiff.getPageCount(fileName); int pageCount = listView1.Items.Count; for (int i = 0; i <= pageCount - 1; i++) { PdfPage page = new PdfPage(); //Image tiffImg = tiff.getTiffImage(fileName, i); //Image tiffImg = Image.FromFile(Application.StartupPath + "temp" + i + ".png"); Image tiffImg = Image.FromStream(imgLst[i].ImageStream); XImage img = XImage.FromGdiPlusImage(tiffImg); page.Width = img.PointWidth; page.Height = img.PointHeight; doc.Pages.Add(page); //XGraphics xgr = XGraphics.FromPdfPage(doc.Pages(i)); XGraphics xgr = XGraphics.FromPdfPage(doc.Pages[i]); xgr.DrawImage(img, 0, 0); } doc.Save("temp.pdf"); doc.Close(); Process.Start("temp.pdf"); }
/// <summary> /// Create pdf file with name pliking.pdf into the application folder /// </summary> /// <param name="sStrSource">Text Language source</param> /// <param name="sStrDest">Text Language dest</param> /// <param name="sFileName">File name pdf to create</param> /// <returns>true if the pdf file is created</param> public bool CreatePdfFile(String sStrSource, String sStrDest, String sFileName) { bool bret=false; try { PdfDocument _document = new PdfDocument(); _document = new PdfDocument(); _document.Info.Title = "Pikling"; _document.Info.Author = "http://www.7touchgroup.com/"; _document.Info.Subject = ""; _document.Info.Keywords = ""; PdfPage page = _document.AddPage(); XGraphics gfxG = XGraphics.FromPdfPage(page); XImage image = XImage.FromFile(System.Windows.Forms.Application.StartupPath + "\\logo.jpg"); // Left position in point double x = (250 - image.PixelWidth * 72 / image.HorizontalResolution) / 2; gfxG.DrawImage(image, x, 0); DrawTitle(page, gfxG, "http://www.7touchgroup.com/"); /*gfxG.MUH = PdfFontEncoding.Unicode; gfxG.MFEH = PdfFontEmbedding.Default;*/ XPdfFontOptions options = new XPdfFontOptions(PdfFontEncoding.Unicode, PdfFontEmbedding.Always); string facename = "Verdana"; XFont fontRegular = new XFont(facename, 14, XFontStyle.Regular, options); String sStr = sStrSource; int iY = 200; int i; for (i = 0; i < 2; i++) { if (i == 1) { sStr = sStrDest; iY += 30; } String sStrLine = ""; string[] myFields = sStr.Split(' '); int iCharForRow = 60; foreach (String sf in myFields) { if (sf.Length + sStrLine.Length >= iCharForRow || sf.LastIndexOf('\r') >= 0) { gfxG.DrawString(sStrLine, fontRegular, XBrushes.DarkSlateGray, 20, iY); sStrLine = sf + " "; iY += 20; } else sStrLine += sf + " "; } if (sStrLine != String.Empty) gfxG.DrawString(sStrLine, fontRegular, XBrushes.DarkSlateGray, 20, iY); } // Save the document... _document.Save(sFileName); // show the pdf //Process.Start(sFileName); _document.Close(); bret = true; } catch (Exception ex) { Program.MainForm.AddLog("CreatePdfFile Exception:" + ex.Message); } return bret; }