Convert Stream to Pdf

199 views
Skip to first unread message

Sarvesh RVN

unread,
Nov 30, 2013, 2:32:16 AM11/30/13
to dot-net-...@googlegroups.com

Hi,
      I am facing problem while converting filesrteam in to pdf in window s8 application,please help me how can I get this.
I am using

                    string localFile = @"Assets\Logo.png";
                    StorageFolder InstallationFolder = Windows.ApplicationModel.Package.Current.InstalledLocation;
                    StorageFile file1 = await InstallationFolder.GetFileAsync(localFile);
                    Stream _stream1;
                    using (Stream stream1 = await file1.OpenStreamForReadAsync())
                    {
                        stream.Position = 0;
                        byte[] buffer = new byte[(int)stream.Length];
                        stream.Read(buffer, 0, (int)stream.Length);
                        _stream1 = new MemoryStream(buffer);
                    }


                    report.Delegates.GetFontDelegate = (source) =>
                    {
                        if (source == "myfont")
                            return arialStream;

                        return null;
                    };


                    report.Load(_stream1);

                    report.Publish(stream, Siberix.Report.FileFormat.PDF);


Thanks.

siberix

unread,
Nov 30, 2013, 5:04:45 AM11/30/13
to dot-net-...@googlegroups.com
Hi Sarvesh,

You cannot convert image stream into PDF document directly. Instead you need to create a new Siberix.Report.Report element add a Section and your image inside that section. Please take a look at the Elements example (available for download with the evaluation package for the Report Writer for WinStore) that shows how to proper use image and other resources while generating PDF reports. In short, it should look something like this:


private async Task GeneratePDFAsync(string fileName)
{
StorageFile file = await KnownFolders.DocumentsLibrary.CreateFileAsync(fileName, CreationCollisionOption.ReplaceExisting);

using (Stream stream = await file.OpenStreamForWriteAsync())
{
await Task.Run(async delegate() // Always run resource loading and report generation in a separate task
{
// Report
Siberix.Report.Report report = new Siberix.Report.Report();

// Section
Siberix.Report.Section.ISection section = report.AddSection();
section.Size = Siberix.Report.PageSize.Letter;
section.Spacings.All = 35;


string localFile = @"Assets\Logo.png";

StorageFolder InstallationFolder = Windows.ApplicationModel.Package.Current.InstalledLocation;
StorageFile file1 = await InstallationFolder.GetFileAsync(localFile);

using (Stream stream = await file1.OpenStreamForReadAsync())
{
stream.Position = 0;
byte[] buffer = new byte[(int)stream.Length];
stream.Read(buffer, 0, (int)stream.Length);

Siberix.Graphics.Image img1 = new Siberix.Graphics.Image(new MemoryStream(buffer)); // This is an image resource that could be used multiple times in your report.

Siberix.Report.IImage image = section.AddImage(img1); // This is an image element that uses the resource for display at particular place in the report
image.Width = new Siberix.Report.DirectWidth(500);
}


report.Publish(stream, Siberix.Report.FileFormat.PDF);
});

await stream.FlushAsync();
}

await Windows.System.Launcher.LaunchFileAsync(file);
}

Please let me know if you were able to resolve the issue.

Thank You,
Victor

Sarvesh RVN

unread,
Nov 30, 2013, 6:53:47 AM11/30/13
to dot-net-...@googlegroups.com
 Hi Victor
                Thank you for your support, actually I want to convert a xaml page in to pdf , please help me how  can I do this.
I want to print pdf of a windows 8 xaml page i.e I will design print preview in xaml page and I want to print this xaml.

Thank you
Sarvesh.

Sarvesh RVN

unread,
Nov 30, 2013, 10:33:13 AM11/30/13
to dot-net-...@googlegroups.com

Hi Victor

                I want to print a list like this

            Name :  XXXX
    Fathers Name :  yyyyyytt
    Mothers Name :  rrrrrrr
    Brother Name :  BBBBBBBBBB                         where xxxx,yyyyytt,rrrr,bbbbb etc bind from object.

please help me how can I achieve this. I checked example but I was confused with grid,rows and cells.

Thank you
Sarvesh.

siberix

unread,
Nov 30, 2013, 5:17:50 PM11/30/13
to dot-net-...@googlegroups.com
Hi Sarvesh,

Siberix Report Writer doesn't provide any methods to directly convert XAML pages into PDF documents. However, you may use Report Writer's API or internal XML format (that is similar to XAML) to recreate the appearance of your XAML pages with the appropriate Report Writer elements.

Thank You,
Victor

siberix

unread,
Nov 30, 2013, 5:27:09 PM11/30/13
to dot-net-...@googlegroups.com
Hi Sarvesh,

The easiest way to accomplish your task is to use the Grid element from the Report Writer's API. As you get a bit more "fluent" with the structure of the API you may move to XML definitions and Data Bindings.

Siberix.Report.Report report = new Siberix.Report.Report();

Siberix.Report.Text.Style style1 = new Siberix.Report.Text.Style(fnt1, Siberix.Graphics.Brushes.Black);

// Grid
Siberix.Report.Grid.IGrid grid = section.AddGrid();
grid.Borders = new Siberix.Report.Borders(Siberix.Graphics.Pens.Black);

Siberix.Report.Grid.IColumn column = grid.AddColumn();
column.Width = new Siberix.Report.RelativeWidth(40);

column = grid.AddColumn();
column.Width = new Siberix.Report.RelativeWidth(60);


// First Row
Siberix.Report.Grid.IRow row = grid.AddRow();

Siberix.Report.Grid.ICell cell = row.AddCell();
cell.Borders = new Siberix.Report.Borders(Siberix.Graphics.Pens.Black);

Siberix.Report.Text.IText text = cell.AddText();
text.Style = style1;
text.AddContent("Name :");

cell = row.AddCell();
cell.Borders = new Siberix.Report.Borders(Siberix.Graphics.Pens.Black);

text = cell.AddText();
text.Style = style1;
text.AddContent(someObject.XXXX); // XXXX should be a string property of someObject


// Second row
row = grid.AddRow();

cell = row.AddCell();
cell.Borders = new Siberix.Report.Borders(Siberix.Graphics.Pens.Black);

Siberix.Report.Text.IText text = cell.AddText();
text.Style = style1;
text.AddContent("Fathers Name :");

cell = row.AddCell();
cell.Borders = new Siberix.Report.Borders(Siberix.Graphics.Pens.Black);

text = cell.AddText();
text.Style = style1;
text.AddContent(someObject.rrrrrrr); // rrrrrrr should be a string property of someObject

...


report.Publish(...);


Thank You,
Victor

Sarvesh RVN

unread,
Dec 1, 2013, 3:11:53 AM12/1/13
to dot-net-...@googlegroups.com
Thank you Victor, got it....

Sarvesh RVN

unread,
Dec 1, 2013, 5:21:10 AM12/1/13
to dot-net-...@googlegroups.com
Hi Victor,
               While continuing with my work using grid , after entring in to second page with number of rows the firstpage data was lost while the second page data was visible, why it is happening what should i do.
Thank You.

siberix

unread,
Dec 1, 2013, 5:03:04 PM12/1/13
to dot-net-...@googlegroups.com
Hi Sarvesh,

It is hard to say what's the issue based only on the description of the problem. Could you please send your report generation (Grid creation) code to in...@siberix.com. I'll take a look at your code and let you know how to resolve the problem.

Thank You,
Victor
Reply all
Reply to author
Forward
0 new messages