Watermark...  
       
      Printed From: Debenu Quick PDF Library - PDF SDK Community Forum
        Category:  For Users of the Library
       Forum Name:  Sample Code
       Forum Description:  Share Debenu Quick PDF Library sample code with other forum members
       URL: http://www.quickpdf.org/forum/forum_posts.asp?TID=230
       Printed Date: 04 Nov 25 at 3:54PM Software Version: Web Wiz Forums 11.01 - http://www.webwizforums.com
      
 
  
      Topic: Watermark...
       
      Posted By: Ingo
       Subject: Watermark...
       Date Posted: 29 Dec 05 at 4:42PM
       
      
        
          
	
Hi!
 
 Here a complete routine which can stamp watermarks on pdf-files. A combined text with date, rotated if you want and with transparency. You can choose the corner on the page and the pages itself, too. One thing if you want to do it in a better way: Set a new layer for the watermark - so you can remove it later easier. The routine works together with a form i don't post here. On the form all settings can be activated and selected... and with the start button the routine below runs.
 
 procedure TForm5.SpeedButton2Click(Sender: TObject);
 var seite, ausr : String;
     atf, tl1, tl2 : LongInt;
     transp, drewin, sc1, sc2, xi : Integer;
     rf1, rf2, rfw, rfh, tl, lu, ts, lf, th, tw : Integer;
     verz  : String;
     text  : String;
     cf    : TextFile;
 begin
    Save_Cursor   := Screen.Cursor;
    Screen.Cursor := crHourglass;    // Show hourglass cursor
 
    If Edit3.Text <> '' Then
       Begin
          ComboBox1.Text := Edit3.Text;
          ComboBox1.Items.Add(Edit3.Text);
       end;
 
    text := Trim(ComboBox1.Text);
    If CheckBox1.Checked = True Then //Watermark with date included
       text := text + ' ' + DateToStr(Date);
    If CheckBox2.Checked = True Then //Watermark with actual user included
       text := text + ' ' + GetCurrentUserName;
 
 //I select the position data from combo boxes...
 //You can add for example a combo box with colours...
 
    if cbseite.Text = 'Alle Seiten'           then seite := 'as'; //on all pages
    if cbseite.Text = 'Erste Seite'           then seite := 'es'; //on the first page
    if cbseite.Text = 'Letzte Seite'          then seite := 'ls'; //on the last page
    if cbseite.Text = 'Alle geraden Seiten'   then seite := 'gs'; //all straight pagenumbers
    if cbseite.Text = 'Alle ungeraden Seiten' then seite := 'us'; //all odd pagenumbers
 
    if cbausr.Text = 'Links oben'    then ausr := 'lo'; //top left
    if cbausr.Text = 'Links unten'   then ausr := 'lu'; //bottom left
    if cbausr.Text = 'Rechts oben'   then ausr := 'ro'; //top right
    if cbausr.Text = 'Rechts unten'  then ausr := 'ru'; //bottom right
 
    transp := StrToInt(Edit5.Text); //The transparency as a percent value
    drewin := StrToInt(Edit4.Text); //Angle of rotation... try with values over and below zero... not more than -45 to 45 
 
    If ( ausr = 'ro' ) or ( ausr = 'lu' ) Then
       drewin := 360 - StrToInt(Edit4.Text); //Invers angle of rotation
 
    if tl > 40 Then //The text should have max. 40 characters
       text := System.Copy(text,1,40);
    tl := Length(Trim(text));
    Begin
       QP := TiSEDQuickPDF.Create;
       try     
          QP.UnlockKey('MyLicenceKey');
          QP.LoadFromFile(Edit1.Text);
          QP.SetOrigin(1); //To top left
          QP.SetMeasurementUnits(0); //means pixel
          QP.Unencrypt;
          atf := QP.AddTrueTypeFont('Arial [Bold]', 0); // Font Arial Bold ... But not embedded !
          QP.SelectFont(atf); // Arial Bold
          for xi := 1 to QP.PageCount do
              begin
 //here it begins to be complicated... You must try a bit i think...
                 QP.SelectPage(xi);
                 sc1 := xi div 2;
                 sc2 := sc1 * 2;
                 if   ( seite = 'as' )                            or
                    ( ( seite = 'es' ) and ( xi = 1 ) )            or
                    ( ( seite = 'ls' ) and ( xi = QP.PageCount ) ) or
                    ( ( seite = 'gs' ) and ( xi = sc2 ) )          or
                    ( ( seite = 'us' ) and ( xi > sc2 ) )          Then
                    begin //ts means text size
                       If ( QP.PageWidth < 250 ) Then
                          ts := 8;
                       If ( QP.PageWidth > 249 ) and
                          ( QP.PageWidth < 400 ) Then
                          ts := 12;
                       If ( QP.PageWidth > 399 ) and
                          ( QP.PageWidth < 650 ) Then
                          ts := 18;
                       If ( QP.PageWidth > 649 ) and
                          ( QP.PageWidth < 1500 ) Then
                          ts := 22;
                       If ( QP.PageWidth > 1499 ) and
                          ( QP.PageWidth < 2500 ) Then
                          ts := 30;
                       If ( QP.PageWidth > 2499 ) Then
                          ts := 38;
                       QP.SetTextSize(ts);
                       tw := tl * ts; //Textwidth is the sum from length * size...
                       tw := tw div 2;
                       tw := tw + StrToInt(Edit4.Text);
                       th := ( tw * StrToInt(Edit4.Text) ) div 45;
 
                       QP.SetTransparency(transp);
                       if ausr = 'lo' Then
                          QP.DrawRotatedText( ts, th, drewin, text); // left - top - width - height
                       if ausr = 'lu' Then
                          QP.DrawRotatedText( ts, QP.PageHeight - th, drewin, text ); // left - top - width - height
                       if ausr = 'ro' Then
                          QP.DrawRotatedText( QP.PageWidth - tw, ts, drewin, text ); // left - top - width - height
                       if ausr = 'ru' Then
                          QP.DrawRotatedText( QP.PageWidth - tw, QP.PageHeight - tl, drewin, text ); // left - top - width - height
                    end;
             end;
          QP.CompressContent;
       finally
          Edit3.Text := '';
          If Edit2.Text <> '' Then
             QP.SaveToFile(Edit2.Text);
          QP.Free;
      end;
      Screen.Cursor := Save_Cursor;
   end;
   If CheckBox3.Checked = True Then //Show the result immediately
      ShellExecute(hinstance,'open',PChar(Edit2.Text),nil,nil,SW_SHOWNORMAL);
 
   If CheckBox4.Checked = True Then //Close after function ends
      Form5.Hide;
 
 end;
 
 
 
 
  ------------- Cheers, Ingo
  
          | 
         
        
      
 
  Replies: 
       
      Posted By: nwebster
       
      Date Posted: 26 Mar 09 at 3:53PM
       
      
        
          | 
	
Is there any possible way you could post the C# version of posting a watermark?
          | 
         
        
        
       
      
      Posted By: Ingo
       
      Date Posted: 26 Mar 09 at 6:00PM
       
      
        
          
	
Hi Noah!
  No ;-)    'cause i'm a delphi developer ;-) You're doing the first steps with QuickPDF ... do it slow ... please read the documentation and have a look in the samples. You can try using the search-function (above) with CSharp-syntax ... perhaps there#s something in the samples.
  Cheers, Ingo
  
          | 
         
        
        
       
      
     |