Click here to Skip to main content
15,898,222 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Dear All,

Please i have word document and need to use microsoft assemply "Microsoft.Office.Interop.Publisher" to import the this word file and convert it to publisher

any one can help .

Best regards && thanx in advance

Ab Abulubbad
Posted
Updated 20-Feb-11 17:53pm
v2

1 solution

hey all , no one answer me ,
i write this code may be it will be helpfull to any one .

regards
ab abulubbad

string psnames = string.Empty;
         string[] RequestsIDs = ViewState["requestIDs"].ToString().Remove(ViewState["requestIDs"].ToString().LastIndexOf(',')).Split(',');
         try
         {
             Microsoft.Office.Interop.Publisher._Application pub = new Microsoft.Office.Interop.Publisher.ApplicationClass();
             Microsoft.Office.Interop.Publisher.Document doc =
             pub.NewDocument(Microsoft.Office.Interop.Publisher.PbWizard.pbWizardNone, -1);
             Microsoft.Office.Interop.Publisher.PageSizes pageSizes = doc.PageSetup.AvailablePageSizes;
             foreach (Microsoft.Office.Interop.Publisher.PageSize ps in pageSizes)
             {
                 psnames += ps.Name + "\\n";
                 if (ps.Name == "A4 (Portrait)")
                 {
                     doc.PageSetup.PageSize = ps;
                     break;
                 }
             }
             int pageNumber = 0;

             foreach (string reqID in RequestsIDs)
             {
                 doc.Pages.Add(1, pageNumber, -1, false);
                 FillPageData(doc.Pages[pageNumber + 1], reqID);
                 pageNumber++;
             }
             doc.Pages[pageNumber+1].Delete();
             string SaveLink = MapPath("~/PublishingDocs/Announce_") + Guid.NewGuid() + ".pub";
             doc.SaveAs(SaveLink, Microsoft.Office.Interop.Publisher.PbFileFormat.pbFilePublication, true);
             doc.Close();
             pub.Quit();
             FileInfo info = new FileInfo(SaveLink);
             string link = "<a href=\"../PublishingDocs/" + info.Name
                 + "\" target=\"_self\" >" +
                 (Session["lang"].ToString() == "ar" ? "لتحميل الملف اضغط هنا" : "To Download The File Click Here")
                 + "</a>";
             lnkPrintSuccess.Enabled = true;
             RadPopUp(link, popUpTitles.DownloadLink);

<pre lang="midl">page.Shapes.AddTextbox(Microsoft.Office.Interop.Publisher.PbTextOrientation.pbTextOrientationRightToLeft,
          250, "0.373\"", "1.875\"", "0.313\"");
       page.Shapes[1].TextFrame.TextRange.Text = "بسم الله الرحمن الرحيم";
       page.Shapes[1].TextFrame.TextRange.ParagraphFormat.Alignment =
           Microsoft.Office.Interop.Publisher.PbParagraphAlignmentType.pbParagraphAlignmentCenter;
       page.Shapes[1].TextFrame.TextRange.Font.BoldBi = Microsoft.Office.Core.MsoTriState.msoTrue;
       page.Shapes[1].TextFrame.TextRange.Font.SizeBi = 14;
       /**********************************Righ Text**********************************************/
       page.Shapes.AddTextbox(Microsoft.Office.Interop.Publisher.PbTextOrientation.pbTextOrientationRightToLeft,
        450, "0.787\"", "1.875\"", "0.775\"");
       page.Shapes[2].TextFrame.TextRange.Text =
           "المملكة العربية السعودية\nوزارة التجارة والصناعة\nإدارة العلامات التجارية";
       page.Shapes[2].TextFrame.TextRange.ParagraphFormat.Alignment =
           Microsoft.Office.Interop.Publisher.PbParagraphAlignmentType.pbParagraphAlignmentCenter;
       page.Shapes[2].TextFrame.TextRange.Font.BoldBi = Microsoft.Office.Core.MsoTriState.msoTrue;
       page.Shapes[2].TextFrame.TextRange.Font.SizeBi = 14;

       /**********************************Content Text**********************************************/
       page.Shapes.AddTextbox(Microsoft.Office.Interop.Publisher.PbTextOrientation.pbTextOrientationRightToLeft,
       "1.563\"", "3.375\"", "5.097\"", "7.25\"");

       page.Shapes[3].TextFrame.TextRange.Text = GetRequestAnnounceText(reqID);
       page.Shapes[3].TextFrame.TextRange.ParagraphFormat.Alignment =
           Microsoft.Office.Interop.Publisher.PbParagraphAlignmentType.pbParagraphAlignmentRight;
       page.Shapes[3].TextFrame.TextRange.Font.SizeBi = 14;
       /**********************************Image Or Text**********************************************/
       GetRequestTextOrImage(page, reqID);




private void GetRequestTextOrImage(Microsoft.Office.Interop.Publisher.Page page,string reqID)
{
    DataTable dt = ViewState["Requests"] as DataTable;
    DataRow dr = dt.Select("Request_ID=" + reqID)[0];
    if (dr[9].ToString() == "1")
    {
        page.Shapes.AddTextbox(Microsoft.Office.Interop.Publisher.PbTextOrientation.pbTextOrientationRightToLeft,
          "1.563\"", "3.375\"", "5.097\"", "0.25\"");
        page.Shapes[4].TextFrame.TextRange.Text = dr[10].ToString();
        page.Shapes[4].TextFrame.TextRange.ParagraphFormat.Alignment =
            Microsoft.Office.Interop.Publisher.PbParagraphAlignmentType.pbParagraphAlignmentCenter;
        page.Shapes[4].TextFrame.TextRange.Font.SizeBi = 14;
    }
    else
    {
        page.Shapes.AddPicture(Server.MapPath("~/UploadedFiles/RequestMarks/" + dr[10].ToString()), Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoTrue,
            "3.438\"", "2.110\"", "1.251\"", "1.251\"");
    }
}
private string GetRequestAnnounceText(string reqID)
{
    try
    {

    string AnncounceText = AnnounceText;
    req = new Requests();
    req.Request_IDs = ViewState["requestIDs"].ToString();
    DataTable dt = ViewState["Requests"] == null ? req.GetRequestDataForAnnounce() : ViewState["Requests"] as DataTable;
    ViewState["Requests"] = dt;
    DataRow dr = GetDataRow(dt.Select("Request_ID=" + reqID)[0]);
    AnncounceText = string.Format(AnncounceText, dr.ItemArray);
    return Common.arabicNumber( AnncounceText);
    }
    catch (Exception)
    {

        throw;
    }
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900