Telerik Forums
Telerik Document Processing Forum
8 answers
2.1K+ views
Hello,

I'd like to use the new RadWordProcessing (2014 Q1) to create generic report documents for my customers.
The documents should preferably be saved in PDF format.

As far as I've seen, there is currently no PdfFormatProvider which supports RadFlowDocuments. Instead it expects a RadDocument as export parameter.
Is it possible to convert RadFlowDocuments to RadDocuments to use the available PdfFormatProvider with the RadDocument?
Or just create PDF files from RadFlowDocuments?
Is this a planned feature in the near future?

Thanks and kind regards
Timo Bohl





mozell
Top achievements
Rank 1
 answered on 07 Mar 2016
1 answer
459 views

HI


I use the RadPdfProcessing API to generate Pdf document and preview the pdf file in WinForm App.
The pdf previewed by Acrobat Reader then the chinese char displayed normally, 
but not works for Telerik.WinControls.UI.RadPdfViewer in WinForm
(same as http://www.telerik.com/clientsfiles/445045_Wrong.jpg?sfvrsn=0)

Generate pdf file c:\Hello1.pdf :

// Reference :
//
// FontsRepository.RegisterFont data Parameter
 
Telerik.Windows.Documents.Fixed.Model.Fonts.FontsRepository.RegisterFont(new FontFamily("標楷體"),
    System.Windows.FontStyles.Normal,
    System.Windows.FontWeights.Normal,
    File.ReadAllBytes("C:\\Windows\\Fonts\\kaiu.ttf"));
 
Telerik.Windows.Documents.Fixed.Model.Fonts.FontBase NewCreateFont;
 
Telerik.Windows.Documents.Fixed.Model.Fonts.FontsRepository.TryCreateFont(
   new FontFamily("標楷體"),
   System.Windows.FontStyles.Normal,
   System.Windows.FontWeights.Normal,
   out NewCreateFont);
 
 
  // Reference :
  //
  // CREATING A PDF DOCUMENT
 
  Telerik.Windows.Documents.Fixed.Model.RadFixedDocument document2 = new Telerik.Windows.Documents.Fixed.Model.RadFixedDocument();
  Telerik.Windows.Documents.Fixed.Model.RadFixedPage page2 = document2.Pages.AddPage();
  Telerik.Windows.Documents.Fixed.Model.Editing.FixedContentEditor editor = new Telerik.Windows.Documents.Fixed.Model.Editing.FixedContentEditor(page2);
  editor.Position.Translate(50, 50);
  Telerik.Windows.Documents.Fixed.Model.Editing.Block block = new Telerik.Windows.Documents.Fixed.Model.Editing.Block();
  block.GraphicProperties.FillColor = Telerik.Windows.Documents.Fixed.Model.ColorSpaces.RgbColors.Black;
  block.HorizontalAlignment = Telerik.Windows.Documents.Fixed.Model.Editing.Flow.HorizontalAlignment.Left;
  block.TextProperties.Font = Telerik.Windows.Documents.Fixed.Model.Fonts.FontsRepository.HelveticaBoldOblique;
  block.TextProperties.FontSize = 40;
  block.InsertText("RadPdfProcessing");
  block.TextProperties.Font = NewCreateFont; // Telerik.Windows.Documents.Fixed.Model.Fonts.FontsRepository.Helvetica;
  block.TextProperties.FontSize = 12;
  block.InsertText(" 中文字 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.");
  editor.DrawBlock(block, new System.Windows.Size(500, double.PositiveInfinity));
 
  Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.PdfFormatProvider provider2 = new Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.PdfFormatProvider();
  using (Stream output2 = File.OpenWrite("c:\\Hello1.pdf"))
  {
    provider2.Export(document2, output2);
  }

 

 



Preview the pdf file c:\Hello1.pdf :

private void button1_Click(object sender, EventArgs e)
{
  radPdfViewer1.LoadDocument("c:\\Hello1.pdf");
}


I have reference the forums and posts then embed the fonts into pdf file but the code still not works :

Chinese characters support ?
http://www.telerik.com/forums/chinese-characters-support#bA9YpXuJGk6Fz9yDbs8wmA

How can I generate and preview pdf file  normally in WinForm App? 


Tools :

Telerik DevCraft Q1 2016 SP1
Windows 7
Visual Studio 2015 Ultimate and .NET Framework 4.0

Best regards

Chris



 

Deyan
Telerik team
 answered on 03 Mar 2016
6 answers
1.7K+ views

My company decided to move from Infragistics to Telerik .

For PDF development I am using Telerik.Windows.Documents.Flow.FormatProviders.Pdf and Telerik.Windows.Documents.Flow.Model.RadFlowDocument to create PDF.PDF is complex with tables/images etc but I did not have any issue there.Everything was as in Telerik online spec.

Now I have different issue that was almost stopover for me.PDF that I got with Telerik is 10 times bigger in size then with Infragistics.
Example bellow will create the simplest PDF doc with only one line of text, and that document is 245 kb.Same example with Infragistic is 14 kb.
Exact same relations is also when I add images in..I can see that Telerik document is much higher in quality [when I put images] but we prefer size/performance then quality of PDF.

Can you point what I have to change? Is any FormatProviders.Pdf settings that I can use to create smaller size document ?Or ?

 

class TEST
    {
        public void ExportToPdf(string PdfURL)
        {
            Telerik.Windows.Documents.Flow.FormatProviders.Pdf.PdfFormatProvider provider =
                new Telerik.Windows.Documents.Flow.FormatProviders.Pdf.PdfFormatProvider();
            using (Stream output = File.OpenWrite(PdfURL))
            {
                Telerik.Windows.Documents.Flow.Model.RadFlowDocument document = CreateRadFlowDocument();
                provider.Export(document, output);
            }
        }
        private Telerik.Windows.Documents.Flow.Model.RadFlowDocument CreateRadFlowDocument()
        {
            RadFlowDocument document = new RadFlowDocument();
            RadFlowDocumentEditor editor = new RadFlowDocumentEditor(document);
            editor.ParagraphFormatting.TextAlignment.LocalValue = Alignment.Justified;
            Section section = editor.InsertSection();
            section.PageMargins = new Telerik.Windows.Documents.Primitives.Padding(4);
            section.PageOrientation = Telerik.Windows.Documents.Model.PageOrientation.Landscape;
           
            //test text
            editor.InsertText("TEST Telerik.Windows.Documents.Flow.Model.RadFlowDocument PDF ");

            return document;
        }
       
    }

 

 


Deyan
Telerik team
 answered on 01 Mar 2016
1 answer
348 views

Hi Team,

I need to automate a scenario of comparing 2 PDF files based on the content, format, alignment, etc. Is it possible to do it using Telerik Test Studio or any other telerik products.

--

Thanks,

Siva.

Tanya
Telerik team
 answered on 01 Mar 2016
3 answers
558 views
Why does the following code return a transparent image?
The WHITE is transparent.

PdfFormatProvider provider = new PdfFormatProvider(file, FormatProviderSettings.ReadOnDemand);
RadFixedDocument document = provider.Import();
ThumbnailFactory factory = new ThumbnailFactory();
RadFixedPage page = document.Pages[0];
System.Windows.Media.ImageSource source = factory.CreateThumbnail(page, page.Size);

var image = (BitmapSource)source;
BitmapEncoder encoder = new PngBitmapEncoder();
encoder.Frames.Add(BitmapFrame.Create(image));
using (var ms = new MemoryStream())
{
   encoder.Save(ms);
   ms.Position = 0;
   return ms;
}

Thankx, Harry

Tanya
Telerik team
 answered on 25 Feb 2016
8 answers
368 views
I am very exciting for this new function, but it is seem not support chinese as well. I convert a xlsx file that contain chinese to the pdf. the chinese word disappeared.....
Fredrik
Top achievements
Rank 2
 answered on 24 Feb 2016
2 answers
989 views

I figured out this solution [code bellow] but is any other solution [probably it is] that I can use ?
Can use directly somehow System.Drawing.Font :
System.Drawing.Font fArialB  = new System.Drawing.Font("Arial", 18, System.Drawing.FontStyle.Bold);
instead to use Run object for every cell as bellow ?


        private void SetCellStyle(ref Telerik.Windows.Documents.Flow.Model.TableCell cell, string CellTxt, double CellSize)
        {
            cell.Shading.BackgroundColor = new ThemableColor(System.Windows.Media.Colors.White);
            cell.PreferredWidth = new TableWidthUnit(CellSize);
            Paragraph cellPar = cell.Blocks.AddParagraph();
            cellPar.TextAlignment = Alignment.Right;
            Run runCellTextFormat = cellPar.Inlines.AddRun(CellTxt);
            runCellTextFormat.FontSize = 18;
            runCellTextFormat.FontWeight = FontWeights.Bold;
            runCellTextFormat.FontFamily = new ThemableFontFamily(new System.Windows.Media.FontFamily("Arial"));
        }
Sorry to bother you guys with such probably simple questions, but I am in some short time frame to move stuff from Infagistic to Telerik.
Neven
Top achievements
Rank 2
 answered on 19 Feb 2016
3 answers
798 views

I have to put 2 tif images on same page, one is regular "check" size,  other is "T4" doc size ...
Page orientation is landscape I did calculation , resizes images, everything works great ... BUT
"check image" position is on the bottom of page ?

I need it on top of page. Tried all alignments etc but did not figure out .

 I attached PDF page [as JPG] .

This is simple class that produced PDF.

 

 using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Telerik.Windows.Documents.Flow.FormatProviders.Pdf;
using Telerik.Windows.Documents.Flow.Model;
using Telerik.Windows.Documents.Flow.Model.Editing;
using Telerik.Windows.Documents.Flow.Model.Styles;
using Telerik.Windows.Documents.Spreadsheet.Model;
using Telerik.Windows.Documents.Fixed.FormatProviders.Pdf;
using System.IO;

 namespace TEST{

class TELERIK_WordProcessing_PDFTest
{

public void ExportToPdf(string PdfURL)
{
Telerik.Windows.Documents.Flow.FormatProviders.Pdf.PdfFormatProvider provider =
new Telerik.Windows.Documents.Flow.FormatProviders.Pdf.PdfFormatProvider();
using (Stream output = File.OpenWrite(PdfURL))
{
Telerik.Windows.Documents.Flow.Model.RadFlowDocument document = CreateRadFlowDocument();
provider.Export(document, output);
}
}
private Telerik.Windows.Documents.Flow.Model.RadFlowDocument CreateRadFlowDocument()
{
RadFlowDocument document = new RadFlowDocument();
RadFlowDocumentEditor editor = new RadFlowDocumentEditor(document);
editor.ParagraphFormatting.TextAlignment.LocalValue = Alignment.Justified;
Section section = editor.InsertSection();
section.PageMargins = new Telerik.Windows.Documents.Primitives.Padding(4);
//LANDSCAPE format 11 x 8.5 inches
double landscapeWidth = 11 * 96; //1056.00 pixels
double landscapeHeith = 8.5 * 96; //816.00 pixels
section.PageSize = new System.Windows.Size(landscapeWidth, landscapeHeith);
section.PageOrientation = Telerik.Windows.Documents.Model.PageOrientation.Landscape;
section.VerticalAlignment = Telerik.Windows.Documents.Flow.Model.Styles.VerticalAlignment.Top;
//insert 2 images , regular check and T4 in row, one one page
string imageBackCheck = @"C:\temp\test\BACK.tif";
string imageT4 = @"C:\temp\test\FrontA4Page.tif";
//open image to find size
int width = 0;
int height = 0;
SingleImageSize(imageT4, out width, out height);
using (FileStream fileStream = File.OpenRead(imageT4))
{
editor.InsertImageInline(fileStream, "tif", new System.Windows.Size(width, height));
}
SingleImageSize(imageBackCheck, out width, out height);
using (FileStream fileStream = File.OpenRead(imageBackCheck))
{
editor.InsertImageInline(fileStream, "tif", new System.Windows.Size(width, height));
}
return document;
}
private void SingleImageSize(string URL, out int destWidthFirst, out int destHeightFirst)
{
//need to shrink tif image to fit page [ 2 images in row ]
destWidthFirst = 0;
destHeightFirst = 0;
System.Drawing.Image FrontImage = System.Drawing.Image.FromFile(URL);
int sourceWidthFirst = FrontImage.Width;
int sourceHeightFirst = FrontImage.Height;
float nPercent = GetPercentShrink(sourceWidthFirst);
destWidthFirst = (int)(sourceWidthFirst * nPercent);
destHeightFirst = (int)(sourceHeightFirst * nPercent);
}
private float GetPercentShrink(int SourceWidth)
{
//some custom size calculation for lanscape mode [note margin is 4], 523 is half of page
int nConstWidth = 523;// 527;
return (float)nConstWidth / (float)SourceWidth;
}
}

 

}

Neven
Top achievements
Rank 2
 answered on 17 Feb 2016
1 answer
280 views

Hi,

 

I create several documents using word processing and finally merge them into a single one using RadFlowDocument.Merge method. When you open that document in Word and insert a header, the header will only be set for single merged documents and not consistently across the whole document.

To repro:

- Create 2 RadFlowDocuments, with a single page and some simple demo text

- Merge them into a single one

- Export the merged document as docx.

- Open the exported document in word and add some text to the header on page 1.

- Scroll down to page 2 and confirm that the header is not there.

 

I can't tell whether this is a bug or a feature, but is there a way to workaround this? Ultimately I just want to merge several documents into one and have consistent headers and footers across the whole document.

Thanks in advance

Florian

Tanya
Telerik team
 answered on 16 Feb 2016
1 answer
195 views
I am using the RadSpreadsheet component and I am filling it with data from code behind. I would like to resize only the 'used' columns to a width that fits the content from each column. Something like the AutoFitWidth(). 

I tried to use this method (AutoFitWidth()) in a ColumnSelection, however I could only use in all columns, not just the ones I used and I took more than 2 minutes to open my window... I don't want this... As I fill my spreadsheet from code behind, I don't know how many columns I am using... It depends on the settings the user chose before the window opens...

Is there any solution for this?
Deyan
Telerik team
 answered on 15 Feb 2016
Narrow your results
Selected tags
Tags
+? more
Top users last month
Rob
Top achievements
Rank 3
Iron
Iron
Iron
Atul
Top achievements
Rank 1
Iron
Iron
Iron
Alexander
Top achievements
Rank 1
Veteran
Iron
Serkan
Top achievements
Rank 1
Iron
Shawn
Top achievements
Rank 1
Iron
Iron
Want to show your ninja superpower to fellow developers?
Top users last month
Rob
Top achievements
Rank 3
Iron
Iron
Iron
Atul
Top achievements
Rank 1
Iron
Iron
Iron
Alexander
Top achievements
Rank 1
Veteran
Iron
Serkan
Top achievements
Rank 1
Iron
Shawn
Top achievements
Rank 1
Iron
Iron
Want to show your ninja superpower to fellow developers?
Want to show your ninja superpower to fellow developers?