How to get Telerik RadHtmlChart into PowerPoint presentation - vb.net

I am using VB Net and telerik controls to build a web application. I have a screen with a few ColumnChart RadHtmlCharts on, and I need to get them into a PowerPoint Presentation in the Code Behind file.
My current approach is taking an existing .PPTX file and stepping through it, replacing text where required and so on. Now I just need to get the charts into the presentation.
Here is the loop that I am making through the slides.
' generate
For Each slide As SlidePart In pCopy.PresentationPart.SlideParts
' THIS IS WHERE THE CHARTS NEED TO BE ADDED TO THE SLIDE
Next
Note: I have written a function that returns the chart, all I am missing now is the steps required to get it into the presentation.
Here are the 'Imports' I have included...
Imports Telerik.Web.UI
Imports System.Data
Imports System.IO
Imports System.Data.SqlClient
Imports Microsoft.Office.Interop
Imports Microsoft.Office.Interop.PowerPoint
Imports DocumentFormat.OpenXml
Imports DocumentFormat.OpenXml.Packaging
Imports DocumentFormat.OpenXml.Presentation
Any help will be greatly appreciated

Just as rdmptn has suggested I took the chart and saved that as an image first, and then from there added the images to the slides using templates.
So the basic steps I took were...
1) Create Powerpoint presentation with a holding image in (name the image via the 'Selection Pane')
2) In the Code Behind loop through all of the slideparts, checking if the name of the part (image) is the chart we are looking for
3) Using the following code replace the holding image with the generated image of the chart (GenerateChartImage() returns the filepath to the generated image)
Using imgStream As FileStream = New FileStream(GenerateChartImage(), FileMode.Open)
imagePart.FeedData(imgStream)
End Using
Here is how I saved the chart as an image (where generate chart just builds the chart programatically...
Dim Chart As New RadChart()
Dim FilePath As String = "~/Folder/" & FileName & ".jpg"
Dim Path As String = Server.MapPath(FilePath)
Chart = GenerateChart(Index)
' save the image and return the filepath
Chart.Save(Path, System.Drawing.Imaging.ImageFormat.Jpeg)
return Path
I hope this helps someone else as I understand this topic can be very confusing!

Assuming you know how to put images in the pptx file (I, myself, don't), you "only" need to get the images from the HtmlChart. There several approaches:
start from the following code library on exporting the control: http://www.telerik.com/support/code-library/exporting-radhtmlchart-to-png-and-pdf Using the ClientExportManager control is quite straightforward.
this should provide you with an image of the chart on your server that you can use in your existing code
Other ideas you can consider:
you can use a service to get many images on your server first if you want to embed multiple charts: http://docs.telerik.com/devtools/aspnet-ajax/controls/clientexportmanager/how-to/save-exported-files
tools like PhantomJS can let you run the browser on the server so it can generate the charts, that you can export and embed. Otherwise you will need end user action to load the page with the charts

Related

Cropping a PDF to png using Ghostscript.net

I'm using visual studio 2015 with VB language Web application, my issue in brief I used Ghostscript to extract pdf first page to png its work fine but if pdf file name contain space its does not extract png and no error show up or if written on other language the error " Page number is not in pages number range!".
I appreciate any help.
test.pdf ---> work fine
new york.pdf --->nothing happen no error
show up
pdf file name not written in English --->error "Page number is
not in pages number range!"
code is
Imports Ghostscript.NET
Imports Ghostscript.NET.Rasterizer
Imports System.IO
Imports System.Drawing.Imaging
Imports System.Drawing
Partial Class Default6
Inherits System.Web.UI.Page
Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim inputPdfPath As String = "d:\test\test.pdf"
Dim outputPath As String = "d:\test\"
Using Rasterizer = New GhostscriptRasterizer
Rasterizer.CustomSwitches.Add("-dUseTrimBox")
Rasterizer.CustomSwitches.Add("-g683x960")
Rasterizer.CustomSwitches.Add("-f")
Rasterizer.Open(inputPdfPath)
Dim pageFilePath As String = Path.Combine(outputPath, "Page1" + ".jpg")
Dim img As Image = Rasterizer.GetPage(100, 1)
img.Save(pageFilePath, ImageFormat.Png)
Console.WriteLine(pageFilePath)
End Using
End Sub
End Class
First posted in the comments section, I'm including information as answer, as it worked for the user.
Here is a link useful to solve the blank spaces trouble:
https://www.vbforums.com/showthread.php?703121-RESOLVED-How-to-Shell-from-a-directory-with-spaces-in-path
For non-english characters, please try with the following approach:
Illegal characters in path (Chinese characters)
If the last solution does not work, another alternative is to loop through files in directory and identify the one you are looking for by another meta-data ou file info. In this case, please check this link:
vb.net how to loop through a directory listing?

Clear cells in multiple sheets from SSIS by VBA

How I can use below VBA coding in SSIS vba. I want to clear cells(data) from multiple sheets from SSIS by VBA coding
sub cod()
ThisWorkbook.Worksheets("Case management details").Range("A2:K10000").clear
ThisWorkbook.Worksheets("interface Timeliness").Range("A2:G20000").clear
ThisWorkbook.Worksheets("Life Events").Range("A2:N10000").clear
End sub
I had the same problem here. If you decided to solve this using SSIS component try with Script Task.
After you create excel steps will be:
Add Script Task on control flow.
Double click on component.
Press 'Edit Script...' button.
Right-click on the project in new visual studio windows (should be something like 'ST_' and some guid) and click on Manage NuGet Packages...
From 'Browse' tab install:
Microsoft.Office.Interop.Excel
Microsoft.CSharp
Into namespaces region add these 2 lines:
using Microsoft.Office.Interop.Excel;
using Microsoft.CSharp.RuntimeBinder;
Copy below code into ScriptMain class:
var appExcel = new Excel.Application();
string filename = #"D:\PathToExcel\ExcelFile.xlsx";
var newBook = appExcel.Workbooks.Open(filename);
var oSheet1 = newBook.Worksheets["Case management details"];
oSheet1.Range("A2", "K10000").Delete();
newBook.Save();
appExcel.Workbooks.Close();
appExcel.Quit();
Close without saving the second visual studio window (where you write script code).
Run the package
Note:
Instead of hardcoded file location, you can replace it with a package variable. In this case 2nd line will be:
string filename = Dts.Variables["User::ExcelFilePath"].Value.ToString();
I tested this package before write answer and everything work perfect!
With this logic, create multiple sheet instance and delete what you want.
If something isn't clear or non-logical write me in a comment and I will make correction.

How to properly import a txt file into a rich text box in visual basic?

I am trying to import a text file into a rich text box for my Visual Basic project (Its a Windows Forms App (.Net Framework)). I copied the text information from the internet, and pasted it into notepad. Then I saved this in a folder I created called txtFiles inside the Bin folder of my project. However, when I used the FileOpen command, it gives me an error.
The code I used:
Dim strTemp As String = ""
rtbReference.Text = Nothing
FileOpen(1, "../txtFiles/Thriller.txt", OpenMode.Input)
Do Until EOF(1) = True
Input(1, strTemp)
rtbReference.Text = strTemp
Loop
FileClose(1)
Picture:
The error that I got when running my program
Any help would be appreciated, thank you so much
There are more easier methods of working with files in the 21st century. I mean the IO namespace provides a handful of methods.
Try any of the following. Add this at the top of your code file
Imports System.IO
Method 0: File.ReadAllText
Since the file you want to load is a plain tet file, I suggest you use this.
RichTextBox1.Text = File.ReadAllText(pathtofile)
Method 1: Richtextbox.LoadFile()
Someone (or something) has already posted the link to an article on this in the comments but i'm pretty sure you've not gone through it. Well here's how to use it
RichTextBox1.LoadFile(pathtofile)
I use this method for only rtf files but it was completely my decision.
Method 2 To n - 1
You need to know how to use a search engine as there are many methods out there that can be used such as the StreamReader and so on.

Executing mailmerge removes all bookmarks. What's the alternative?

So my challange is this.
I've created a Word Macro Enabled Template (MS Word 2016) which creates a document using the MailMerge function using data from an Excel file which colleagues complete.
Once completed, they add in their signature - a scanned jpeg file of their signature from a central network.
My code worked on the principle of attaching to a bookmark, unbeknown to me that when executing a MailMerge, it removes all bookmarks.
I am thinking that if I can change my code after ActiveDocument so that instead of looking for Bookmark it looks for specific text, I can then insert this text in the specific place in the Word template so when the MailMerge is executed it places their signature in that specific [text] place.
Is this possible?
Thanks in advance.
My code is
Sub CurrentUserSignature()
Dim folder As String
folder = "C:\\MacroTemp\\"
Dim path As String
path = folder & Application.UserName & ".jpg"
Dim shape As InlineShape
Set shape = ActiveDocument.Bookmarks("Signature").Range.InlineShapes.AddPicture(path, False, True)
With shape
.LockAspectRatio = msoTrue
.Height = CentimetersToPoints(4.3)
End With
End Sub
`
You could simply insert a borderless single-cell table, a Rich Text Content Control, or a Picture Content Control at the desired location in the mailmerge main document, then access each of those in the output document. If you use a borderless single-cell table, you can give it a fixed height and width so the inserted image's size is automatically constrained to fit.
Where multiple output documents are being produced, each to be signed by the same person, you might do better to insert the signature into the mailmerge main document before execution, then close that without saving changes post-merge.
Alternatively, especially if different records require different signatures and the relevant details can be gleaned from the data source, you can add field coding to the mailmerge main document to automatically add the signature images. See Managing Mailmerge Graphics in the Mailmerge Tips and Tricks thread at:
http://www.msofficeforums.com/mail-merge/21803-mailmerge-tips-tricks.html
or:
http://windowssecrets.com/forums/showthread.php/163017-Word-Mailmerge-Tips-amp-Tricks

vb.net 2013 - itextsharp retrive checkbox state

this is my first post here in stackoverflow,but I followed too much about my favourite vb.net articles...
now I want to share my little experience and ask another one that I can't do...
I have precompiled pdf file with some field, textbox and checkbox. My goal is after user filling, open the pdf file with my software that can read text value from textbox and state form check box. The first is done, check the following code:
Imports iTextSharp
Imports iTextSharp.text
Imports iTextSharp.text.pdf
Imports iTextSharp.text.xml
'open file dialog code...
Dim pdfTemplate As String = lbl_file.Text
Dim readerPDF As New PdfReader(pdfTemplate)
Dim name As Object = readerPDF.AcroFields.GetField("name")
Try
txt_name.Text = name
Catch Ex As Exception
End Try
This part of code, search a textbox called "name" and put here text proprieties into my text box. WOW...but to check a checkbox state?do you have any idea please? Thank's in advance for all.
maybe i found a way to do...check this and, what do you think about?
Dim male As Object = readerPDF.AcroFields.GetField("male")
If male = "On" Then
cmb_male.Checked = True
End If
I saw in acrobat default output value from checkbox is "On" than is enough check it and change checkbox value as needed.