C#/XAML winRT 应用导出 PDF

标签 c# xaml winapi windows-runtime

如何在 winRT 应用程序中生成 pdf?我正在使用 iTextSharp 在 Windows 应用商店应用程序中生成 pdf,但 winRT 没有文件流、文件模式或文件目录。帮助

这是我的代码:

iTextSharp.text.pdf.PdfWriter writer = 
    iTextSharp.text.pdf.PdfWriter.GetInstance(
        doc, new System.IO.FileStream(System.IO.Directory.GetCurrentDirectory() +
                                      "\\ScienceReport.pdf", System.IO.FileMode.Create
        )
    );

最佳答案

我可以在winrt中生成PDF文件

        string path = @"ExportPDF.pdf";
        var storageFolder = Windows.Storage.ApplicationData.Current.LocalFolder;

        // Create empty PDF file.
        var file = await storageFolder.CreateFileAsync(path, CreationCollisionOption.ReplaceExisting);
        if (file != null)
        {
            await FileIO.WriteTextAsync(file, string.Empty);
        }

        // Open to PDF file for read/write.
        StorageFile sampleFile = await storageFolder.GetFileAsync(path);
        var stream = await sampleFile.OpenAsync(Windows.Storage.FileAccessMode.ReadWrite);

        // Create an instance of the document class which represents the PDF document itself.
        Document document = new Document(PageSize.A4, 25, 25, 30, 30);

        // Create an instance to the PDF file by creating an instance of the PDF 
        // Writer class using the document and the filestrem in the constructor.
        PdfWriter writer = PdfWriter.GetInstance(document, stream.AsStream());

        // Add meta information to the document
        document.AddAuthor("Jigs");
        document.AddCreator("Sample application");
        document.AddKeywords("PDF App");
        document.AddSubject("Document subject - Describing the steps creating a PDF document");
        document.AddTitle("The document title - PDF creation");

        // Open the document to enable you to write to the document
        document.Open();
        // Add a simple and wellknown phrase to the document in a flow layout manner
        document.Add(new Paragraph("Hello!"));

        // Close the document
        document.Close();
        // Close the writer instance
        writer.Close();

关于C#/XAML winRT 应用导出 PDF,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23667893/

相关文章:

c# - LINQ 到 SQL : How to Insert record into a view?

c# - DateTimePicker 日历默认为上次选择的月份/年份

winapi - 如何调用和使用 UnregisterClass?

c++ - Windows API 作业对象 : Don't pass on to grandchildren

delphi - Windows Server 2003 和 Windows7 中的 MessageBox 外观

c# 没有参数的谓词

c# - Dispose() 如何在我的 Controller 和 Repository 类中工作

wpf - 如何绑定(bind)到 ControlTemplate 中的 SelectedItem 属性?

c# - namespace "ImageViewModel"中不存在名称 "clr-namespace:AdminControlCenter.ViewModel"

C# 到 VB.net 项目转换