SORU
3 Mart 2009, Salı


Nasıl PDF programlı Word dosyaları dönüştürebilirim?

Seni dönüştürmek için izin veren bir açık kaynak/ücretsiz birkaç program buldum .doc dosyaları .pdf dosyaları, ancak uygulama/yazıcı sürücüsü çeşitli hayır SDK bağlı tüm bunlar.

Bir SDK dönüştürme için izin var mı birkaç program buldum .doc dosyaları .dosyaları pdf, fakat mülkiyet türü, 2000 $lisans veya oralarda yapıyorlar.

Kimse benim sorunum temiz, ucuz (tercihen ücretsiz) herhangi bir programlama çözüm, C kullanmayı biliyor mu# ya VB.NET?

Teşekkürler!

CEVAP
3 Mart 2009, Salı


For döngüsü yerine foreach döngü kullanmak - benim sorunum çözüldü.

int j = 0;
foreach (Microsoft.Office.Interop.Word.Page p in pane.Pages)
{
    var bits = p.EnhMetaFileBits;
    var target = path1  j.ToString()   "_image.doc";
    try
    {
        using (var ms = new MemoryStream((byte[])(bits)))
        {
            var image = System.Drawing.Image.FromStream(ms);
            var pngTarget = Path.ChangeExtension(target, "png");
            image.Save(pngTarget, System.Drawing.Imaging.ImageFormat.Png);
        }
    }
    catch (System.Exception ex)
    {
        MessageBox.Show(ex.Message);  
    }
    j  ;
}

Burada benim için çalışan bir program bir değişiklik. Save As PDF add-in yüklü Word 2007 kullanır. Bir dizinde arama yapar .doc dosyaları, Word içinde açılır ve sonra bir PDF olarak kaydeder. Microsoft için bir başvuru eklemeniz gerekir unutmayın.Office.Birlikte çalışabilirlik.Çözüm için kelime.

using Microsoft.Office.Interop.Word;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

...

// Create a new Microsoft Word application object
Microsoft.Office.Interop.Word.Application word = new Microsoft.Office.Interop.Word.Application();

// C# doesn't have optional arguments so we'll need a dummy value
object oMissing = System.Reflection.Missing.Value;

// Get list of Word files in specified directory
DirectoryInfo dirInfo = new DirectoryInfo(@"\\server\folder");
FileInfo[] wordFiles = dirInfo.GetFiles("*.doc");

word.Visible = false;
word.ScreenUpdating = false;

foreach (FileInfo wordFile in wordFiles)
{
    // Cast as Object for word Open method
    Object filename = (Object)wordFile.FullName;

    // Use the dummy value as a placeholder for optional arguments
    Document doc = word.Documents.Open(ref filename, ref oMissing,
        ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
        ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
        ref oMissing, ref oMissing, ref oMissing, ref oMissing);
    doc.Activate();

    object outputFileName = wordFile.FullName.Replace(".doc", ".pdf");
    object fileFormat = WdSaveFormat.wdFormatPDF;

    // Save document into PDF Format
    doc.SaveAs(ref outputFileName,
        ref fileFormat, ref oMissing, ref oMissing,
        ref oMissing, ref oMissing, ref oMissing, ref oMissing,
        ref oMissing, ref oMissing, ref oMissing, ref oMissing,
        ref oMissing, ref oMissing, ref oMissing, ref oMissing);

    // Close the Word document, but leave the Word application open.
    // doc has to be cast to type _Document so that it will find the
    // correct Close method.                
    object saveChanges = WdSaveOptions.wdDoNotSaveChanges;
    ((_Document)doc).Close(ref saveChanges, ref oMissing, ref oMissing);
    doc = null;
}

// word has to be cast to type _Application so that it will find
// the correct Quit method.
((_Application)word).Quit(ref oMissing, ref oMissing, ref oMissing);
word = null;

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • Joseph Herscher

    Joseph Hersc

    14 Mart 2007
  • lilstevie89

    lilstevie89

    25 Mart 2011
  • lissaandbeauty

    lissaandbeau

    24 Aralık 2011