This is a migrated thread and some comments may be shown as answers.

Open PDF from html document

16 Answers 266 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
Runjith
Top achievements
Rank 2
Runjith asked on 14 Aug 2014, 09:36 AM
Hi,

I have html document(xyz.html),Under click event i want to open PDF file from html Document using Telerik.

Please let me know how can I proceed.

Regards,
Ranjith

16 Answers, 1 is accepted

Sort by
0
Petya
Telerik team
answered on 19 Aug 2014, 08:15 AM
Hello Ranjith,

RadRichTextBox exposes several format providers that allow you to convert a document from one type to another. In your case you can import the HTML with HtmlFormatProvider and export it to PDF with the PdfFormatProvider class. More information is available in the Import/Export help article.

Once you've generated the desired PDF you can use the RadPdfViewer component which is part of the Telerik UI for WPF suite to show it. I suggest you check the documentation of the control as well as its SDK examples: RadPdfViewer OverviewShowing a FileSDK Samples Browser.

I hope this is helpful.

Regards,
Petya
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
0
Runjith
Top achievements
Rank 2
answered on 22 Aug 2014, 08:42 AM
Hi,

Please find the below code,while opening pdf from html file.

​ string html = File.ReadAllText(ViewDetails.html);
string pdfPath = strDestinationPath + strSessionID + _Params.CustomizeID +"Configuration Details.pdf";
HtmlFormatProvider provider = new HtmlFormatProvider();
RadDocument document = provider.Import(html);
PdfFormatProvider pdf = new PdfFormatProvider();
var bytes= pdf.Export(document);
if (File.Exists(pdfPath))
{
File.SetAttributes(pdfPath, FileAttributes.Normal);
}

var fs = new FileStream(pdfPath, FileMode.Create);
fs.Write(bytes, 0, bytes.Length);
fs.Close();
Process.Start(pdfPath);

It is displaying empty PDF file.But "ViewDetails.html" having data.If i open in browser it will display the datails.

How can i display Html data into PDF.

Regards,
Ranjith

0
Petya
Telerik team
answered on 26 Aug 2014, 03:33 PM
Hello Ranjith,

I am not sure what might be causing this result on your end. Could you confirm this is the behavior with all HTML documents or does the issue depend on the HTML content? Please also try the behavior of the attached application, the source HTML it uses is located in the \ExportPdfDemo\ExportPdfDemo\bin\Debug\SampleData folder.

I'm looking forward to your reply.

Regards,
Petya
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
0
Runjith
Top achievements
Rank 2
answered on 28 Aug 2014, 08:14 AM
Hi,

When i add this code

 string html = File.ReadAllText(@"C:\Users\ranjith.p01\Downloads\ExportPdfDemo\bin\Debug\SampleData\test.html");
            string pdfPath = "SampleData\\Configuration Details.pdf";

            HtmlFormatProvider provider = new HtmlFormatProvider();
            RadDocument document = provider.Import(html);
            PdfFormatProvider pdf = new PdfFormatProvider();

            var bytes = pdf.Export(document);
            if (File.Exists(pdfPath))
            {
                File.SetAttributes(pdfPath, FileAttributes.Normal);
            }

            var fs = new FileStream(pdfPath, FileMode.Create);
            fs.Write(bytes, 0, bytes.Length);
            fs.Close();
            Process.Start(pdfPath);

I am getting Error:The type initializer for 'Telerik.Windows.Documents.Model.RadDocument' threw an exception.

near this line: RadDocument document = provider.Import(html);

Please give me reply ASAP.



Regards,
Ranjith
0
Runjith
Top achievements
Rank 2
answered on 28 Aug 2014, 09:39 AM
Hi,

It is working fine with html which you have attached.But if i give my own HTML file it is not working.

Please tell me what is the problem here.

Regards,
Ranjith
0
Runjith
Top achievements
Rank 2
answered on 01 Sep 2014, 06:32 AM
Working fine without errors, but It Opens empty PDF file.
Not loading my Html data.

Regards,
Ranjith
0
Petya
Telerik team
answered on 01 Sep 2014, 12:51 PM
Hello Ranjith,

Could you provide us with the source document that you are having troubles exporting? I'm afraid that I am unable to comment on what might be causing this without investigating the HTML first. 

Note that the public forums do not allow attachments. You can open a support ticket and attach the file there.

Looking forward to hearing from you.

Regards,
Petya
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
0
Runjith
Top achievements
Rank 2
answered on 02 Sep 2014, 08:43 AM
Hi,

I have raised the support ticket.

Please find the ticket id.
855410 (view all your support tickets)
0
Petya
Telerik team
answered on 04 Sep 2014, 03:48 PM
Hello,

For anyone else that might encounter this topic, the issue was caused due to specific content in the HTML that prevents the document from being imported in the control. The public item for this can be found at Documents with STYLE tag are not imported properly.

Regards,
Petya
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
0
Runjith
Top achievements
Rank 2
answered on 16 Sep 2014, 01:06 PM
Hi,
Please find the attached PDF screens.

How to remove the space between line to line and How to reduce font size in PDF document.

I am using below code for converting HTML to PDF.

            string html = File.ReadAllText(path);
           // string html = File.ReadAllText(@"C:\Test1.html");
            string pdfPath = "C:\\Configuration Details.pdf";
            HtmlImportSettings uri = new HtmlImportSettings();
            uri.LoadImageFromUrl += uri_LoadImageFromUrl;
            
            HtmlFormatProvider provider = new HtmlFormatProvider();
            provider.ImportSettings = uri;
            RadDocument document = provider.Import(html);
            document.LayoutMode = DocumentLayoutMode.Paged;
            PdfFormatProvider pdf = new PdfFormatProvider();

            var bytes = pdf.Export(document);
            if (File.Exists(pdfPath))
            {
                File.SetAttributes(pdfPath, FileAttributes.Normal);
            }

            var fs = new FileStream(pdfPath, FileMode.Create);
            fs.Write(bytes, 0, bytes.Length);
            fs.Close();
            Process.Start(path);
            Process.Start(pdfPath);

Regards,
Ranjith
0
Runjith
Top achievements
Rank 2
answered on 16 Sep 2014, 02:13 PM
Data coming from Different XSL's.It 's looking like between one xsl data to another xsl data having space,how to remove that?

Regards,
Ranjith
0
Runjith
Top achievements
Rank 2
answered on 17 Sep 2014, 03:02 PM
Hi,

When i open PDF document,i can see the zoom percentage of the document is 139(%).
I want to set(Default) 100%.
Find the attached document.
Please help me how can i fix this.

Regards,
Ranjith
0
Petya
Telerik team
answered on 19 Sep 2014, 10:02 AM
Hello Runjith,

Without the actual HTML, we would be guessing what is causing the empty space in your document. You could try showing the document in RadRichTextBox prior the export and enabling the formatting symbols to see whether they are additional paragraphs in that place. Alternatively, send us your HTML document so that we can look into the cause.

Regarding the font size, you can reduce it by selecting the desired content and calling the ChangeFontSize() method of RadRichTextBox or RadDocumentEditor. This article provides more details on document selection.

As to the scale factor when showing a document, such settings are not supported by the PdfFormatProvider so this is not information that is exported in the PDF file. The scale factor with which a document is loaded depends on the software that shows the PDF.

Regards,
Petya
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
0
Runjith
Top achievements
Rank 2
answered on 22 Sep 2014, 05:04 AM
Hi,

If i give border="2" for tables in html doc,used to display border for tables in PDF doc.

after applying below code i am not getting any borders for my table.please find the bellow code and help me how can i get borders.

 HtmlDataProvider htmlDataProvider = new HtmlDataProvider();
  htmlDataProvider.SetupDocument += htmlDataProvider_SetupDocument; 

 void htmlDataProvider_SetupDocument(object sender, Telerik.Windows.Documents.FormatProviders.SetupDocumentEventArgs e)
        {
            foreach (Telerik.Windows.Documents.Model.Span span in e.Document.EnumerateChildrenOfType<Telerik.Windows.Documents.Model.Span>())
            {
                span.ClearValue(Telerik.Windows.Documents.Model.Span.FontSizeProperty);
                span.ClearValue(Telerik.Windows.Documents.Model.Span.FontFamilyProperty);
                span.ClearValue(Telerik.Windows.Documents.Model.Span.FontStyleProperty);
                span.ClearValue(Telerik.Windows.Documents.Model.Span.FontWeightProperty);
            }
        }

Regards,
Ranjith
0
Runjith
Top achievements
Rank 2
answered on 22 Sep 2014, 06:43 AM
I Commented and tried,still i am not getting? What will be the problem please help me...................


Regards,
Ranjith
0
Runjith
Top achievements
Rank 2
answered on 22 Sep 2014, 07:20 AM
Done,Its working fine.I changed the name of the PDF.
Tags
RichTextBox
Asked by
Runjith
Top achievements
Rank 2
Answers by
Petya
Telerik team
Runjith
Top achievements
Rank 2
Share this question
or