Telerik Forums
Telerik Document Processing Forum
1 answer
528 views

Hi Team,

I am using asp.net webforms.

I want to generate pdf from scratch.

pdf pages size should be A4.

and based on content length i need to generate multiple pages in the PDF.

I am using below code.

protected void btn2_Click(object sender, EventArgs e)
    {
List<string> contents = new List<string>();
        contents.Add("is a document processing library that enables your application to " +
                         "import and export files to and from PDF format. The document model is " +
                         "entirely independent from UI and allows you to generate sleek documents " +
                         "with differently formatted text, images, shapes and more.");
 
        contents.Add("is a document processing library that enables your application to " +
                         "import and export files to and from PDF format. The document model is " +
                         "entirely independent from UI and allows you to generate sleek documents " +
                         "with differently formatted text, images, shapes and more.");
 
 
        contents.Add("is a document processing library that enables your application to " +
                         "import and export files to and from PDF format. The document model is " +
                         "entirely" +
                         "with differently formatted text, images, shapes and more.");
 
        contents.Add("is a document processing library that enables your application to " +
                         "import and export files to and from PDF format. " +
                         "with differently formatted text, images, shapes and more.");
 
        contents.Add("The document model is " +
                         "entirely independent from UI and allows you to generate sleek documents " +
                         "with differently formatted text, images, shapes and more.");
 
        contents.Add("is a application to " +
                         "import and export files to and from PDF format. The document model is " +
                         "entirely independent from UI and allows " +
                         "with differently formatted text, images, shapes and more.");
 
        contents.Add("The document model is111 " +
                         "entirely independent from UI and allows you to generate sleek documents " +
                         "with differently formatted text, images, shapes and more.");
 
        contents.Add("The document model is222 " +
                         "entirely independent from UI and allows you to generate sleek documents " +
                         "with differently formatted text, images, shapes and more.");
 
        contents.Add("The document model is " +
                         "entirely independent from UI and allows you to generate sleek documents " +
                         "with differently formatted text, images, shapes and more.");
 
        contents.Add("The document model is " +
                         "entirely independent from UI and allows you to generate sleek documents " +
                         "with differently formatted text, images, shapes and more.");
 
        contents.Add("The document model is " +
                         "entirely independent from UI and allows you to generate sleek documents " +
                         "with differently formatted text, images, shapes and more.");
 
        contents.Add("The document model is " +
                         "entirely independent from UI and allows you to generate sleek documents " +
                         "with differently formatted text, images, shapes and more.");
 
        contents.Add("The document model is " +
                         "entirely independent from UI and allows you to generate sleek documents " +
                         "with differently formatted text, images, shapes and more.");
 
var document = new RadFixedDocument();
        var page = document.Pages.AddPage();
FixedContentEditor editor = new FixedContentEditor(page);
 var x = 50;
        var y = 50;
 
        foreach (var item in contents)
        {
            editor.Position.Translate(x, y); //Start Position(x,y)
            Block block = new Block();
            block.GraphicProperties.FillColor = RgbColors.Black;
            block.HorizontalAlignment = HorizontalAlignment.Left;
            block.TextProperties.Font = FontsRepository.HelveticaBoldOblique;
            block.TextProperties.FontSize = 20;
            block.InsertText("RadPdfProcessing");
 
            block.TextProperties.Font = FontsRepository.Helvetica;
            block.TextProperties.FontSize = 20;
            block.InsertText(item);
            editor.DrawBlock(block, new System.Windows.Size(700, double.PositiveInfinity));
            //x = x + 50;
           // y = y + 150;
        }
 
 
        var pdfProvider = new PdfFormatProvider();
        byte[] renderedBytes = null;
        using (MemoryStream ms = new MemoryStream())
        {
            pdfProvider.Export(document, ms);
            renderedBytes = ms.ToArray();
        }
        Response.Clear();
        Response.AppendHeader("Content-Disposition:", "attachment; filename=PdfDocument.pdf");
        Response.ContentType = "application/pdf";
        Response.BinaryWrite(renderedBytes);
        Response.End();
    }

but the above code generating only single page.

how can i generate multiple pages based on content. and provide me any examples.

 

Martin
Telerik team
 answered on 31 Oct 2018
2 answers
659 views

Good morning,

 

I am trying to finish off a project and I am having trouble getting the PDF assemblies and namespaces sorted out.

 

I am using VS 2015, and the Telerik UI for WinForms version2018.3.2016

I wanted to export a RadPanel that has a few controls. But I can't seem to find the RadFixedDocument class, or the Telerik.Windows.Pdf namespace at all.

I was following documentation at Getting Started and RadFixedDocument Class and I have all the named assemblies referenced, but I still cannot see the Telerik.Windows.Pdf namespace at all. Much less the sought after RadFixedDocument object.

At this point I am sure I have more assemblies referenced that I actually need, I have attached a screenshot of what I have included so far.

Can anyone help me find what I am missing??

 

Thank you, 

Mike

 

 

Tanya
Telerik team
 answered on 26 Oct 2018
1 answer
646 views

How can I set the line spacing in all table cells contained in one section equal to 0?

 

Regards

Tanya
Telerik team
 answered on 17 Oct 2018
1 answer
161 views

Hello All,

 

I Have a RadButton and on click event, I am generating PDF File.   Response.BinaryWrite is used so that user can save the file to desk.

The user shouldn't be clicking the button twice for which I have enabled the option SingleClick to True. The issue is that I have to Enable back the button once the user has completed the download of the file. 

 

Need help with this. 

 

 

Regards,

JP

Peter Milchev
Telerik team
 answered on 15 Oct 2018
1 answer
128 views

Do you have any way to export to HTML?. I need to display the preview of a Spreadsheet in the browser. I can do It for Word documents but for Spreadsheets there is not a direct way.

Do you have any example about this?, I need the preview to display properly the Styles of the Spreadsheet. I suggested to my client to use the PDF export but he didn't like.

Thanks.

Tanya
Telerik team
 answered on 05 Oct 2018
4 answers
1.2K+ views

We recently upgraded Sitefinity 9.1 to Sitefinity 11.0.

We process excel spreadsheets using "Telerik.Windows.Documents.Spreadsheet.Model" which references Telerik.Windows (2015.1.225.45) nuget package with .Net Framework 4.5

Sitefinity 11 uses .Net Framework 4.7.1 and seems like "Telerik.Windows.Documents.Spreadsheet.for.Net40" is the replacement for "Telerik.Windows.Documents.Spreadsheet.Model"? Is this true? If so I'm trying to download ...for.Net40 from Telerik nuget and I get an following error-

 

Unable to resolve dependency 'Telerik.Windows.Zip.for.Net40'.

I could not find this from Telerik's nuget package. Am I heading in the right direction? Appreciate help in advance.

 

 

Polya
Telerik team
 answered on 02 Oct 2018
1 answer
902 views

I want to create the RadFlowDocument in Landscape.  I used the Section.  But I don't know how to use Section to insert text and insert line.  Is there  a easy way to change the whole document to Landscape mode?

Currently, I only find a full example of using editor.InsertText and editor.InsertLine.  So, I am using the same method.  Adding section could only change the margin, not the page orientation for whole document.

Section section = new Section(doc);
doc.Sections.Add(section);
section.PageMargins = new Telerik.Windows.Documents.Primitives.Padding(40, 40, 40, 40);
section.PageOrientation = PageOrientation.Landscape;
section.Rotate(PageOrientation.Landscape);

editor.InsertLine...

Thanks.

 

 

 

Georgi
Telerik team
 answered on 27 Sep 2018
6 answers
1.1K+ views

Hi, 

I have data in IList and i am trying to export the same to excel(.xls or .xlsx any one). But i am getting the exception.  So if any one can put a light on it.
                                for (var i = 0; i < this.RowList.Count; i++)
                                {
                                    for (var j = 0; j < this.Columns.Count; j++)
                                    {
                                          worksheet.Cells[i, j].SetValue("Test");
                                    }
                                }                          
                        if (workbook != null)
                        {                           
                            XlsxFormatProvider formatProvider = new XlsxFormatProvider();                         
                            formatProvider.Export(workbook, stream);                           // Exception  here                   
                        }

 

{System.TypeInitializationException: The type initializer for 'Telerik.Windows.Documents.Spreadsheet.Measurement.FontManager' threw an exception. ---> System.UnauthorizedAccessException: Invalid cross-thread access.
   at MS.Internal.XcpImports.CheckThread()
   at MS.Internal.XcpImports.Font_GetSystemGlyphTypefaces()
   at System.Windows.Media.Fonts.get_SystemTypefaces()
   at Telerik.Windows.Documents.Spreadsheet.Measurement.FontManager..cctor()
   --- End of inner exception stack trace ---
   at Telerik.Windows.Documents.Spreadsheet.Measurement.FontManager.IsMonospaced(String fontFamily)
   at Telerik.Windows.Documents.Spreadsheet.Model.FontProperties.get_IsMonospaced()
   at Telerik.Windows.Documents.Spreadsheet.Measurement.RadTextMeasurer.Measure(String text, FontProperties fontProperties, Nullable`1 wrappingWidth)
   at Telerik.Windows.Documents.Spreadsheet.Measurement.RadTextMeasurer.MeasureMultiline(String text, FontProperties fontProperties, Nullable`1 wrappingWidth)
   at Telerik.Windows.Documents.Spreadsheet.Layout.LayoutHelper.CalculateCellContentSize(ICellValue cellValue, CellValueFormat format, FontProperties fontProperties, Int32 indentFactor, Nullable`1 wrappingWidth)
   at Telerik.Windows.Documents.Spreadsheet.Layout.LayoutHelper.CalculateAutoColumnWidth(Worksheet worksheet, Int32 columnIndex, Int32 fromRowIndex, Int32 toRowIndex, Boolean respectNumberValuesOnly)
   at Telerik.Windows.Documents.Spreadsheet.Model.ColumnSelection.<>c__DisplayClass8.<AutoFitWidth>b__7(CellRange cellRange)
   at Telerik.Windows.Documents.Spreadsheet.Model.SelectionBase.ExecuteForEachRange(IEnumerable`1 cellRanges, Action`1 action, Predicate`1 canExecute)
   at Telerik.Windows.Documents.Spreadsheet.Model.SelectionBase.ExecuteForEachRangeInsideBeginEndUpdate(IEnumerable`1 cellRanges, Action`1 action, Predicate`1 canExecute)
   at Telerik.Windows.Documents.Spreadsheet.Model.ColumnSelection.AutoFitWidth(Boolean expandOnly)
   at Telerik.Windows.Documents.Spreadsheet.Model.CellSelection.<>c__DisplayClass1`1.<SetPropertyValue>b__0(CellRange cellRange)
   at Telerik.Windows.Documents.Spreadsheet.Model.SelectionBase.ExecuteForEachRange(IEnumerable`1 cellRanges, Action`1 action, Predicate`1 canExecute)
   at Telerik.Windows.Documents.Spreadsheet.Model.SelectionBase.ExecuteForEachRangeInsideBeginEndUpdate(IEnumerable`1 cellRanges, Action`1 action, Predicate`1 canExecute)
   at Telerik.Windows.Documents.Spreadsheet.Model.CellSelection.SetPropertyValue[T](ICellProperty`1 property, T value)
   at Telerik.Windows.Documents.Spreadsheet.Model.CellSelection.SetValueInternal(ICellValue cellValue, CellValueFormat newFormat)
   at Telerik.Windows.Documents.Spreadsheet.Model.CellSelection.SetValue(String value)
   at OnGuard.Connext.FrontEnd.Library.SL.ViewModel.ExportOptionsViewModel.ExportToFile()}

Zim
Top achievements
Rank 1
 answered on 20 Sep 2018
4 answers
244 views

Hello,

 

We have been trying to use create a service for automatic document signing.

Right now we have two problems:

1) When you sign a document through acrobat, it gives you an option of locking the document. If you do this, on the signature properties you can read something like: "The certifier has specified that no changes are allowed to be made to this document."

Do we have access to any variable that grants control over this behaviour?

2) When signing a pdf with a digital certificate, the signing time includes the time zone for example: "2018/09/11 12:07:20 + 01'00'". Is there any way to retrieve the same format so we can put it on the appearance? (If we just use the signatureField.Signature.Properties.TimeOfSigning.toString(), it does not include the timezone)

 

I'll be willing to supply any other code necessary.

Thank you in advance.

Inelcis
Top achievements
Rank 1
 answered on 20 Sep 2018
5 answers
174 views
Hi.

I have recently started using the ZipLibrary and I am facing an issue when adding streams to a ZipPackage.  I am trying to add two streams to the ZipPackage, one for a PowerPoint file and the other for a Excel file.  Once it is packaged, I want to write it to the OutputStream.  Before I add the streams to the package, their size is significantly larger and have data because when I export them as individual streams (outside of a zip) it works just fine.  Once added it looks like they lose all of their data and when it outputs, the PPTX and XLSX files are empty and corrupt respectively.

Here is my code below as well as the SendZipToClient snippet from another forum post, is there anything wrong with it or is it an issue from the ZipLibrary?

Additional Info:
.NET version: 4.5
Current Browser: FireFox 21.0
Telerik version for ASP.NET AJAX: 2013.1.417.45
Language: C#


private void StreamReports(Dictionary<int, MemoryStream> ReportStreams)
{
      string destPPTXFile = string.Format("{0}.pptx", txtPresentationName.Text);
      string destXLSXFile = string.Format("{0}.xlsx", txtPresentationName.Text);
 
      MemoryStream outputStream = new MemoryStream();
      ZipPackage zipPackage = ZipPackage.Create(outputStream);
 
      MemoryStream powerpointStream = ReportStreams[0];
      MemoryStream excelStream = ReportStreams[1];
 
      zipPackage.AddStream(powerpointStream, destPPTXFile);
      zipPackage.AddStream(excelStream, destXLSXFile);
 
      SendZipToClient(outputStream, zipPackage);
 
 }

private void SendZipToClient(MemoryStream memStream, ZipPackage Package)
        {
            string destFile = string.Format("{0}.zip", txtPresentationName.Text);
            Package.Close(false);
            memStream.Position = 0;
            if (memStream != null && memStream.Length > 0)
            {
                Response.Clear();
                Response.AddHeader("content-disposition", "attachment; filename=\"" + destFile);
                Response.ContentType = "application/zip";
                Response.BufferOutput = false;   // to prevent buffering
                byte[] buffer = new byte[1024];
                int bytesRead = 0;
                while ((bytesRead = memStream.Read(buffer, 0, buffer.Length)) > 0)
                {
                    Response.OutputStream.Write(buffer, 0, bytesRead);
                }
 
                Response.End();
            }
        }
Tom
Top achievements
Rank 1
 answered on 18 Sep 2018
Narrow your results
Selected tags
Tags
+? more
Top users last month
Jay
Top achievements
Rank 3
Iron
Iron
Iron
Benjamin
Top achievements
Rank 3
Bronze
Iron
Veteran
Radek
Top achievements
Rank 2
Iron
Iron
Iron
Bohdan
Top achievements
Rank 2
Iron
Iron
Richard
Top achievements
Rank 4
Bronze
Bronze
Iron
Want to show your ninja superpower to fellow developers?
Top users last month
Jay
Top achievements
Rank 3
Iron
Iron
Iron
Benjamin
Top achievements
Rank 3
Bronze
Iron
Veteran
Radek
Top achievements
Rank 2
Iron
Iron
Iron
Bohdan
Top achievements
Rank 2
Iron
Iron
Richard
Top achievements
Rank 4
Bronze
Bronze
Iron
Want to show your ninja superpower to fellow developers?
Want to show your ninja superpower to fellow developers?