1-) C# RMOS - devexpress ile docx veya doc to pdf convert çevirme kullanımı word to pdf
1- 1.yol word docx doc dan pdf e çevirir
private void button1_Click(object sender, EventArgs e) { string docxPath = @"C:\cc\dikey.docx"; string pdfPath = @"C:\cc\dikey_sonuc.pdf"; bool result = ConvertDocxToPdf(docxPath, pdfPath);
} private bool ConvertDocxToPdf(string docxPath, string pdfPath) { if (!File.Exists(docxPath)) { MessageBox.Show("DOCX dosyası bulunamadı.", "Hata", MessageBoxButtons.OK, MessageBoxIcon.Error); return false; }
using (RichEditDocumentServer documentServer = new RichEditDocumentServer()) { documentServer.LoadDocument(docxPath); documentServer.ExportToPdf(pdfPath); return File.Exists(pdfPath); } }
|
2- 2.yol word docx doc dan pdf e çevirir
2- docx to Xtrareport to pdf sayfa sayfa
using DevExpress.XtraRichEdit; using DevExpress.XtraRichEdit.API.Layout; using DevExpress.XtraRichEdit.API.Native; using KaliteApi.ReportPk; using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Windows.Forms; namespace Deneme_1 { public partial class Form4 : Form { public Form4() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { string docxPath = @"C:\cc\55.docx"; string outputPath = @"C:\cc\Document_PDF22_yeni.pdf"; using (RichEditDocumentServer wordProcessor = new RichEditDocumentServer()) { wordProcessor.LoadDocument(docxPath); List<byte[]> pdfFiles = new List<byte[]>(); for (int pageNumber = 0; pageNumber < wordProcessor.DocumentLayout.GetPageCount(); pageNumber++) { string pageRtfText = GetPageRtfText(wordProcessor, pageNumber); byte[] pdfBytes = GeneratePdfFromRtf(pageRtfText); pdfFiles.Add(pdfBytes); } MergePdfFiles(pdfFiles, outputPath); } Process.Start("explorer.exe", outputPath); MessageBox.Show("işlem bitti"); } private string GetPageRtfText(RichEditDocumentServer documentServer, int pageNumber) { Document document = documentServer.Document; LayoutPage page = documentServer.DocumentLayout.GetPage(pageNumber); if (page != null) { LayoutPageArea pageArea = page.PageAreas[0]; FixedRange pageRange = pageArea.Range; DocumentRange range = document.CreateRange(pageRange.Start, pageRange.Length); return document.GetRtfText(range); } return string.Empty; } private byte[] GeneratePdfFromRtf(string rtfText) { using (MemoryStream pdfStream = new MemoryStream()) { Report1 report = new Report1(); report.xrRichText1.Rtf = rtfText; report.ExportToPdf(pdfStream); return pdfStream.ToArray(); } } private void MergePdfFiles(List<byte[]> pdfFiles, string outputPath) { using (PdfDocumentProcessor pdfProcessor = new PdfDocumentProcessor()) { pdfProcessor.CreateEmptyDocument(); foreach (byte[] pdfBytes in pdfFiles) { using (MemoryStream pdfStream = new MemoryStream(pdfBytes)) { pdfProcessor.AppendDocument(pdfStream); } } pdfProcessor.SaveDocument(outputPath); } } } }
|
FileContentResult api tarafında dönmek için