Blog

  • C#: convert document to PDF

    Today I wrote small code to convert the document (.doc, .rtf etc) ionto PDF format using MS Word 12/2007 automation:

    using Word = Microsoft.Office.Interop.Word;
    
    private void SaveRTFToPDF(string RTFFileName, string PDFFileName)
    		{
    			object oMissing = System.Reflection.Missing.Value;
    			Object oTrue = true;
    			Object oFalse = false;
    			object ReadOnly = false;
    			object IsVisible = true;
    
    			object RTFFile = RTFFileName;
    			object PDFFile = PDFFileName;
    
    			Word._Application oWord = new Word.Application();
    
    			Word._Document oDoc = oWord.Documents.Open(ref RTFFile,
    				ref oMissing, ref ReadOnly,
    			ref oMissing, ref oMissing,
    				ref oMissing, ref oMissing,
    				ref oMissing, ref oMissing,
    				ref oMissing, ref oMissing,
    				ref IsVisible, ref oMissing,
    				ref oMissing, ref oMissing,
    				ref oMissing);
    
    
    			object FileFormat = Word.WdSaveFormat.wdFormatPDF;
    			object LockComments = false;
    			object AddToRecentFiles = true;
    			object ReadOnlyRecommended = false;
    			object EmbedTrueTypeFonts = false;
    			object SaveNativePictureFormat = true;
    			object SaveFormsData = true;
    			object SaveAsAOCELetter = false;
    			object InsertLineBreaks = false;
    			object AllowSubstitutions = false;
    			object LineEnding = Word.WdLineEndingType.wdCRLF;
    			object AddBiDiMarks = false;
    
    			oDoc.SaveAs(ref PDFFile, ref FileFormat, ref LockComments,
    				ref oMissing, ref AddToRecentFiles, ref oMissing,
    				ref ReadOnlyRecommended, ref EmbedTrueTypeFonts,
    				ref SaveNativePictureFormat, ref SaveFormsData,
    				ref SaveAsAOCELetter, ref oMissing, ref InsertLineBreaks,
    				ref AllowSubstitutions, ref LineEnding, ref AddBiDiMarks);
    
    			oDoc.Close(ref oFalse, ref oMissing, ref oMissing);
    			oWord.Quit(ref oMissing, ref oMissing, ref oMissing);
    		}
    

    Sample to use:

    			SaveRTFToPDF(@"d:\C#\rtf2pdf\rtf\10-052561_1.RTF", @"d:\C#\rtf2pdf\rtf\10-052561_1.pdf");
    			SaveRTFToPDF(@"d:\C#\rtf2pdf\rtf\10-052561_2.RTF", @"d:\C#\rtf2pdf\rtf\10-052561_2.pdf");
    			SaveRTFToPDF(@"d:\C#\rtf2pdf\rtf\10-072410.RTF", @"d:\C#\rtf2pdf\rtf\10-072410.pdf");
    			SaveRTFToPDF(@"d:\C#\rtf2pdf\rtf\10-080976.RTF", @"d:\C#\rtf2pdf\rtf\10-080976.pdf");
    			SaveRTFToPDF(@"d:\C#\rtf2pdf\rtf\10-087077.RTF", @"d:\C#\rtf2pdf\rtf\10-087077.pdf");
    

    I tried to convert the rtf into PDF using Crystal Reports. Just to generate the report form on fly from code and print there the RichTextBox.
    But unfortunatelly only simple rtf-files exported as PDF in such way because Crystal Reports supports the limited syntax of rtf-format.
    For example, header/footer of rtf-files is not converted correctly and images are not saved at all.

  • В субботу купили новый аккумулятор Bosch S4 Silver для машины:

    Bosch S4 Silver

    Брали в АТЛ

  • affiliates from ShareIt

    In last few days I got a lot of requests to approve the new affiliates via ShareIt control panel. I added only the BetaNews, DownloadPipe and Lockergnome. All others are not added and not declined.

    Do not know why they want to add my products because the affiliates do not work for me. Seems like ShareIt sent the mails to own large affiliates with list of products and I’m there.

  • formating number

    function GetFormattedNumber(Value: Double): string; 
    
      function GetLastPos(const s: string): Integer; 
      begin 
        Result := Pos(DecimalSeparator, s)-1; 
        if (Result < 1) then 
          Result := Length(s) 
      end; 
    
    var 
      i: Integer; 
    begin 
      Result := FloatToStr(Value); 
      i := 3; 
      while (i < GetLastPos(Result)) do 
      begin 
        Insert(' ', Result, GetLastPos(Result)-i+1); 
        Inc(i, 4) 
      end; 
    end;

    Sample to use:

      lblTotal.Caption := GetFormattedNumber(123456.789);
    

    Why I wrote this function? In Delphi I could use the FormatFloat(‘,###’, dbl) but FormatFloat uses the thousand separator which is defined in MS Windows (#160 by default). I need the space char always

  • Viewer for Crystal Reports (*.rpt)

    Today I wrote for Ethan the small tool – viewer for .rpt files.
    User need select the directory with saved report forms, specify the logon info for MS SQL and view/save as pdf the any report:

    Main form for rptview

    There I used the C# because viewer requires the Crystal Reports runtime library and I have the merge modules (for setup/install) only in MS Visual Studio 2003. Didn’t find in CodeGear/Embacadero disks.
    The setup (.msi) created in MS Visual Studio 2003 too

  • C#: enable XP theming for application

    1. use the manifest (compile as resource or as external file)
    2. call the EnableVisualStyles method for Application in Main():

     	static void Main() 
     	{ 
     		Application.EnableVisualStyles(); 
     		Application.Run(new frmMain()); 
     	}
    
  • Zalman NC2000 (black)

    Скоро лето, а мой лаптоп жару плохо переносит:-) Вернее он ее сам производит:-)

    Решил, что хватит сидеть под вентилятором, а пора купить уже какую-то подставку с охлаждением. Остановился на Zalman NC2000 черного цвета. В принципе мне больше подходила Zalman NC1000, т.к. она для 15″-вых ноутбуков, а на NC2000 можно ставить даже 20″. Решил брать “на вырост”:-)

    Zalman NC2000 (black)

    В понедельник вечером (около 23:00) заказал в Розетке
    Вчера около 12:00 они перезвонили и подтвердили заказ. Доставку обещали сегодня в течении рабочего дня (я на заказываю все на рабочий адрес).
    Сегодня с утра перезвонили (трижды – один раз менеджер, второй раз водитель на подъезде и через минут 10 этот же водитель у проходной).

    В общем сейчас я уже с подставкой. Надеюсь она подойдет к лаптопу и снизит температуру.

    Хотя для меня немаловажно еще и удобство для меня. Дело в том, что я обычно наклоняю лаптоп с уклоном “от меня”, а все подставки имеют уклон “ко мне”. Не знаю как я к этому привыкну.

  • abadev server

    Paid now for the next year of server hosting in Canada datacenter.

  • +1

    19 марта 2010б 19:00

    Изабелла, 3275кг

    Пусть растет  здоровенькая и счастливая!