public void updatePostion(string deviceID) { string json; deviceID = "1"; using (var client = new WebClient()) { json = client.DownloadString("http://www.supectco.com/webs/GDP/Admin/getListOfFeatures.php?CatID=" + deviceID); } FeatureModel log = JsonConvert.DeserializeObject <FeatureModel>(json); var testFile = ""; testFile = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "PDF/pump.pdf"); Spire.Pdf.PdfDocument doc = new Spire.Pdf.PdfDocument(); doc.LoadFromFile(testFile); PdfTextFind results = null; //setting position for every title PdfPageBase page; foreach (var item in log.featureData.First().subFeatures) { if (item.title == "keyfidalilyek") { } int PAGE = Convert.ToInt32(item.page) - 1; page = doc.Pages[PAGE]; string xposition = ""; string yposition = "0"; if (item.value != "master") { results = page.FindText(item.title).Finds.First(); float width = results.Size.Width; xposition = (results.Position.X + width).ToString(); yposition = (results.Position.Y).ToString(); } string json2; using (var client = new WebClient()) { json2 = client.DownloadString("http://www.supectco.com/webs/GDP/Admin/setPositionForFeatures.php?ID=" + item.ID + "&xpos=" + xposition + "&ypos=" + yposition); } } }
private void button1_Click(object sender, EventArgs e) { String input = @"..\..\..\..\..\..\Data\SearchReplaceTemplate.pdf"; PdfDocument doc = new PdfDocument(); // Read a pdf file doc.LoadFromFile(input); // Get the first page of pdf file PdfPageBase page = doc.Pages[0]; // Searches "Spire.PDF for .NET" by ignoring case PdfTextFindCollection collection = page.FindText("Spire.PDF for .NET", TextFindParameter.IgnoreCase); String newText = "Spire.PDF API"; // Gets the first found object PdfTextFind find = collection.Finds[0]; // Creates a brush PdfBrush brush = new PdfSolidBrush(Color.DarkBlue); // Defines a font PdfTrueTypeFont font = new PdfTrueTypeFont(new Font("Arial", 15f, FontStyle.Bold)); // Gets the bound of the first found text in page RectangleF rec = find.Bounds; page.Canvas.DrawRectangle(PdfBrushes.White, rec); // Draws new text as defined font and color page.Canvas.DrawString(newText, font, brush, rec); // This method can directly replace old text with newText,but it just can set the background color, can not set font/forecolor // find.ApplyRecoverString(newText, Color.Gray); String result = "ReplaceFirstSearchedText_out.pdf"; //Save the document doc.SaveToFile(result); //Launch the Pdf file PDFDocumentViewer(result); }
public MemoryStream FillReport(Student student, ReportDetails details) { List <string> tagsToFind = new List <string>() { "$subject", "$topicno", "$author", "$teacher", "$year", "$major", "$typeofstudies", "$semester", "$labdate", "$group", "$section", "$deadlinedate", "$returneddate" }; foreach (String tag in tagsToFind) { PdfPageBase page = template.Pages[0]; PdfTextFind location = page.FindText(tag, TextFindParameter.None)?.Finds[0]; if (location != null) { string replacement; PdfTrueTypeFont font; switch (tag) { case "$subject": replacement = details.Subject; font = new PdfTrueTypeFont(new Font("Calibri", 18f, FontStyle.Bold)); break; case "$topicno": replacement = details.TopicNo.ToString(); font = new PdfTrueTypeFont(new Font("Calibri", 18f, FontStyle.Regular)); break; case "$author": replacement = student.Name; font = new PdfTrueTypeFont(new Font("Calibri", 12f, FontStyle.Regular)); break; case "$teacher": replacement = details.TeacherName; font = new PdfTrueTypeFont(new Font("Calibri", 12f, FontStyle.Regular)); break; case "$year": replacement = DateTime.Now.Month < 10 ? (DateTime.Now.Year - 1).ToString() + "/" + DateTime.Now.Year.ToString() : DateTime.Now.Year.ToString() + "/" + (DateTime.Now.Year + 1).ToString(); font = new PdfTrueTypeFont(new Font("Calibri", 12f, FontStyle.Regular)); break; case "$major": replacement = student.Major; font = new PdfTrueTypeFont(new Font("Calibri", 12f, FontStyle.Regular)); break; case "$typeofstudies": replacement = student.TypeOfStudies; font = new PdfTrueTypeFont(new Font("Calibri", 12f, FontStyle.Regular)); break; case "$semester": replacement = student.Semester.ToString(); font = new PdfTrueTypeFont(new Font("Calibri", 12f, FontStyle.Regular)); break; case "$labdate": replacement = details.LabDate.ToString(); font = new PdfTrueTypeFont(new Font("Calibri", 12f, FontStyle.Regular)); break; case "$group": replacement = student.Group.ToString(); font = new PdfTrueTypeFont(new Font("Calibri", 12f, FontStyle.Regular)); break; case "$section": replacement = student.Section.ToString(); font = new PdfTrueTypeFont(new Font("Calibri", 12f, FontStyle.Regular)); break; case "$deadlinedate": replacement = details.DeadlineDate.ToString("dd/MM/yy"); font = new PdfTrueTypeFont(new Font("Calibri", 12f, FontStyle.Regular)); break; case "$returneddate": replacement = DateTime.Now.ToString("dd/MM/yy"); font = new PdfTrueTypeFont(new Font("Calibri", 12f, FontStyle.Regular)); break; default: replacement = "ERROR"; font = new PdfTrueTypeFont(new Font("Calibri", 12f, FontStyle.Underline)); break; } RectangleF rec = location.Bounds; page.Canvas.DrawRectangle(PdfBrushes.White, rec); page.Canvas.DrawString(replacement, font, PdfBrushes.Black, new PointF(rec.Left, rec.Top - 3f)); } } //template.SaveToFile("C:\\Users\\Lenovo\\source\\repos\\ApiConcept\\ApiConcept\\Templates\\report.pdf"); MemoryStream stream = new MemoryStream(); template.SaveToStream(stream); return(stream); }