簡體   English   中英

C#/ XAML winRT應用導出PDF

[英]C#/XAML winRT apps export PDF

如何在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();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM