将图像导出为pdf时出现问题

时间:2014-09-19 05:50:11

标签: c# wpf pdf telerik

m有一个网格:companysnapshot ..网格导出到磁盘然后再从磁盘中取出并导出到pdf。 下面的代码工作正常,导出与图像完成。 bt问题是......

- >图片从UI保存为黑色背景..当导出的内容在白色背景中更改时(可能会将其转换为png)

- >我想在pdf页面中对齐图像的坐标

有没有办法增加图像或pdf页面的宽度。 这是一个新手...如果有人为此编写了一些代码,那将会很有帮助。

 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));
    }

图表文档部分:

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));

    }

1 个答案:

答案 0 :(得分:0)

通过从telerik导出切换到用于pdf导出的itextsharp来解决

问题。