简体   繁体   中英

issue in exporting image to pdf

m having a grid: companysnapshot.. that grid is exported to disk then its again taken from disk and exported to the pdf. Below code is working fine and export with the image is done. bt issues is that..

-->image is saved from UI is black background..when its exported is changing in white background( may be its getting converted to png)

--> i want to align the coordinates of the image in the pdf page

is there any way to either increase the width of the image or pdf page. ma newbie to this ...it would be helpful if someone code me out for this a little.

 private void PrepareDocument(RadDocument document)
    {
        document.SectionDefaultPageOrientation = PageOrientation.Landscape;
        document.LayoutMode = DocumentLayoutMode.Paged;
        document.Measure(RadDocument.MAX_DOCUMENT_SIZE);
        document.Arrange(new RectangleF(PointF.Empty, document.DesiredSize));
    }

chart document part:

private void CreateChartDocumentPart(RadDocument document, Grid whGrid, Grid companysnapshot, Grid chartgridimage)
    {
        Telerik.Windows.Documents.Model.Section section = new Telerik.Windows.Documents.Model.Section();

        Telerik.Windows.Documents.Model.Paragraph paragraph = new Telerik.Windows.Documents.Model.Paragraph();

        Telerik.Windows.Documents.Model.Span span1;

        using (MemoryStream ms = new MemoryStream())
        {
            companysnapshot.Measure(new System.Windows.Size(double.PositiveInfinity, double.PositiveInfinity));
            int companywidth = (int)Math.Round(companysnapshot.ActualWidth);
            int companyheight = (int)Math.Round(companysnapshot.ActualHeight);
            companywidth = companywidth == 0 ? 1 : companywidth;
            companyheight = companyheight == 0 ? 1 : companyheight;
            RenderTargetBitmap rtbmp = new RenderTargetBitmap(companywidth, companyheight, 96d, 96d, PixelFormats.Default);
            rtbmp.Render(companysnapshot);
            BmpBitmapEncoder encoder = new BmpBitmapEncoder();
            encoder.Frames.Add(BitmapFrame.Create(rtbmp));
            FileStream fs1 = File.Create(@"C:\Users\Admin\Desktop\Chart12xx.bmp");
            encoder.Save(fs1);
            fs1.Close();
         //   this.ExportPNGToImage(chart, ms);

            paragraph.LeftIndent = 0;
            paragraph.RightIndent = 0.0;
            FileStream ss = File.Open(@"C:\Users\Admin\Desktop\Chart12xx.bmp", FileMode.Open);
            ImageInline image = new ImageInline(ss, new Size(companywidth, companyheight), "bmp");
            paragraph.FlowDirection = FlowDirection.LeftToRight;
            paragraph.Inlines.Add(image);
            ss.Close();
            //Span spacespan = new Span("  ");
            //paragraph.Inlines.Add(spacespan);
        }

        try
        {
            section1.Blocks.Add(paragraph);
            document.Sections.Add(section1);
        }
        catch (Exception)
        {
        }

      //  paragraph.Inlines.Add(new Span(FormattingSymbolLayoutBox.LINE_BREAK));

    }

通过从telerik导出切换到itextsharp进行pdf导出,解决了问题。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM