Posted 23 April 2019, 1:08 am EST
Hello,
Could you provide some example vb.net code for embedding a html and .pdf document in a Flex report?
I have a difficult report task, SQL data, HTML files and .PDF files all in one report.
Thank you,
Chuck
Forums Home / ComponentOne / WinForms Edition
Posted by: cvandien on 23 April 2019, 1:08 am EST
Posted 23 April 2019, 1:08 am EST
Hello,
Could you provide some example vb.net code for embedding a html and .pdf document in a Flex report?
I have a difficult report task, SQL data, HTML files and .PDF files all in one report.
Thank you,
Chuck
Posted 23 April 2019, 10:03 pm EST
Hello Chuck,
It is not possible to embed html and pdf files in a FlexReport.
However, you can add html text to a SuperLabel custom field manually and by reading the html file content. The attached application shows how this is done.
You can learn more about SuperLabel from the below mentioned documentation link:
http://help.grapecity.com/componentone/NetHelp/FlexReport/webframe.html#SuperLabelCustomField.html
Further, though pdf files cannot be embedded in a FlexReport, you can view them in a C1FlexViewer using the C1PdfDocumentSource control. You can learn about the same from here: https://help.grapecity.com/componentone/NetHelp/C1Document/webframe.html#PDFDocumentSource-for-WinForms.html
Refer Form2.vb in the attached application showing how this is done.
Best Regards,
Esha
Posted 29 April 2019, 12:05 am EST
Hello,
Thank you for your reply.
I need to assemble several .PDF and several .HTML pages that exists as files in a folder - along with SQL record data - into some sort of contiguous set of pages (a report of some sort) I was hoping to write VB.NET code (VS2017) using the ComponentOne Winform controls to assemble this report and view it in the Flex Viewer.
Can you direct me specifically in this direction?
I used ComponentOne tools several years ago and was able to do this in your older technology - I’m back purchasing this new license and was certain I could bring this collection of data into some sort of contiguous set of pages and have my user view it.
Thank you
Chuck
Posted 29 April 2019, 12:22 am EST
The prj_FlexReport code worked like a charm… still need to do this exact thing for .PDF…
Does my WinForms licensed set of tools have a way to convert the .PDF file into something I can call and embed similar to to how this .HTML is being embedded… maybe converting the .PDF to an image and then embedding… anything?
TY
Posted 29 April 2019, 4:43 am EST
Follow-up… the source you provided was awesome, TY.
Chuck
Posted 29 April 2019, 5:01 am EST
Regarding the prj_FlexReport VB.NET solution that is attached to this tread… the concatenation of each of the 2 C1FlexViewer1.DocumentSource (Form1 + Form2) will satisfy my requirements if there is a way to append them into one such that the output of each Form example could be viewed in 1 FlexViewer instance… In other words, how can Form2.C1PdfDocumentSource1 get appended/concatenated/added at the end of Form1.C1FlexReport1 as a single C1FlexViewer1.DocumentSource ? What would the code look like to do so?
Posted 29 April 2019, 8:54 pm EST
Hi Chuck,
PDF file’s images can be obtained by exporting C1PdfDocumentSource to an image, using JpegFilter, for example.
This is done as follows:
'Create JPEGFilter object
Dim filter As New JpegFilter()
filter.FileName = "../../Images/DefaultDocument.jpg"
C1PdfDocumentSource1.Export(filter)
Now, these images are added to subsections that are created based on the number of images generated. This is done in a loop and thereby renders the images on FlexReport using ImageFields.
You can refer the attached modified application showing the same.
Hope it helps.
Best Regards,
Esha
prj_FlexReport_Mod.zip
Posted 29 April 2019, 11:04 pm EST
Esha,
Your example is excellent, thank you!
Chuck
Posted 30 April 2019, 12:07 am EST
Esha,
I think there is a problem with the Control… I’m getting duplicate pages (bank redundant pages) when I format the .PDF page (image) to fit entirely on the same Report page - my desire is to put a border around the image to show the resize limits… If you copy the following code into the modified project, you’ll see that there is a blank page following each populated page… I’ve tried a small enough image dimension to suspect this may be a bug ***you can show me a work-around solution for eliminating each extra page?
C1PdfDocumentSource1.LoadFromFile("../../demo.pdf")
'Create JPEGFilter object
Dim filter As New JpegFilter()
filter.FileName = "../../Images/DefaultDocument.jpg"
C1PdfDocumentSource1.Export(filter)
Dim d As New System.IO.DirectoryInfo(directoryName)
Dim img As ImageField
For i = 1 To d.GetFiles.GetUpperBound(0) + 1
img = New ImageField
Dim subSection As SubSection = C1FlexReport1.Sections.Detail.SubSections.Add()
subSection.Visible = True
subSection.Height = C1FlexReport1.Layout.PageSize.Height
subSection.AutoHeight = AutoSizeBehavior.None
img.Top = 0
img.Left = 0
img.MarginTop = 0
img.MarginBottom = 0
img.Height = 1440 * 8.9
img.Width = 1440 * 7.9
'img.AutoHeight = AutoSizeBehavior.GrowAndShrink
'img.AutoWidth = AutoSizeBehavior.GrowAndShrink
img.PictureScale = PictureScaleEnum.Scale
img.BackColor = Color.LightGray
img.Picture = Image.FromFile(Path.Combine(directoryName, "DefaultDocument_page" & i & ".jpg"))
subSection.Fields.Add(img)
Next
Posted 30 April 2019, 5:18 pm EST - Updated 3 October 2022, 4:16 pm EST
Hi Chuck,
You would need to adjust the size of the subsection, along with the image size. Also, the report margins would need to be modified to make the subsection control stick to a page.
C1FlexReport1.Layout.MarginLeft = 50
C1FlexReport1.Layout.MarginTop = 50
...
...
...
Dim subSection As SubSection = C1FlexReport1.Sections.Detail.SubSections.Add()
subSection.Visible = True
subSection.Height = 1440 * 8
I have attached the modified application for your reference.
Thanks,
Esha
Posted 1 May 2019, 8:12 am EST
Thank you Esha