locked
Stamping on pdf using c# for windows 8 metro app RRS feed

  • Question

  • Is there any way to stamp on pdf... I am using third party api ,but it only limited to display pdf in image form.

    so pls suggest me how to insert text on pdf or on image.

    you can also suggest some third party free library(tried itextsharp but not getting needed result).

    Wednesday, January 22, 2014 1:53 PM

Answers

  • The in-box PDF viewer doesn't support editing. You would need a third party library for that. I'm not aware of any good free ones that support Windows Store apps, but there are several commercial ones. If you search the forum you'll find a number of references.

    If you want to add text to an image there are several ways. If you just want it on screen you can place a TextBlock over the image. You can copy that composite to a new bitmap with RenderTargetBitmap and save it off with a BitmapEncoder. If you want to add text directly to the image you'll need to interop to DirectWrite for the font engine. There probably is a 3rd party library which will handle this for you, but I don't know for sure. Check out WriteableBitmapEx or the WinRTToolkit. If you just need a limited bitmap font you can copy the letter glyphs from one WriteableBitmap onto another.

    If you can specify your needs somebody from the community may have other third party suggestions.

    --Rob

    Wednesday, January 22, 2014 2:46 PM
    Moderator
  • The RenderTargetBitmap class is available for Windows Store apps targeting Windows 8.1.

    Here's a quick sample of that technique. The others are more difficult and I'm not aware of samples. Again, you probably will want to find a 3rd party control that already implements this rather than writing your own interop.

            <ScrollViewer HorizontalScrollMode="Disabled">
                <StackPanel>
                    <Grid x:Name="ImageWithText">
                        <Image Source="Assets/test.jpg"  />
                        <TextBlock Text="Sample Text"  Style="{StaticResource HeaderTextBlockStyle}" />
                    </Grid>
                    <Button Click="Button_Click" />
                    <Image x:Name="outputImage" />
                </StackPanel>
            </ScrollViewer>
     

            private async void Button_Click(object sender, RoutedEventArgs e)
            {
                RenderTargetBitmap bmp = new RenderTargetBitmap();
                await bmp.RenderAsync(this.ImageWithText);
                outputImage.Source = bmp;
            }

    --Rob

    Thursday, January 23, 2014 6:22 AM
    Moderator

All replies

  • The in-box PDF viewer doesn't support editing. You would need a third party library for that. I'm not aware of any good free ones that support Windows Store apps, but there are several commercial ones. If you search the forum you'll find a number of references.

    If you want to add text to an image there are several ways. If you just want it on screen you can place a TextBlock over the image. You can copy that composite to a new bitmap with RenderTargetBitmap and save it off with a BitmapEncoder. If you want to add text directly to the image you'll need to interop to DirectWrite for the font engine. There probably is a 3rd party library which will handle this for you, but I don't know for sure. Check out WriteableBitmapEx or the WinRTToolkit. If you just need a limited bitmap font you can copy the letter glyphs from one WriteableBitmap onto another.

    If you can specify your needs somebody from the community may have other third party suggestions.

    --Rob

    Wednesday, January 22, 2014 2:46 PM
    Moderator
  • Thanks Rob for you reply,

    But RenderTargetBitmap class is not available for windows store app. If you can point me to some sample for composing textblock and image  together dynamically than it will be helpful.

    Thursday, January 23, 2014 5:49 AM
  • The RenderTargetBitmap class is available for Windows Store apps targeting Windows 8.1.

    Here's a quick sample of that technique. The others are more difficult and I'm not aware of samples. Again, you probably will want to find a 3rd party control that already implements this rather than writing your own interop.

            <ScrollViewer HorizontalScrollMode="Disabled">
                <StackPanel>
                    <Grid x:Name="ImageWithText">
                        <Image Source="Assets/test.jpg"  />
                        <TextBlock Text="Sample Text"  Style="{StaticResource HeaderTextBlockStyle}" />
                    </Grid>
                    <Button Click="Button_Click" />
                    <Image x:Name="outputImage" />
                </StackPanel>
            </ScrollViewer>
     

            private async void Button_Click(object sender, RoutedEventArgs e)
            {
                RenderTargetBitmap bmp = new RenderTargetBitmap();
                await bmp.RenderAsync(this.ImageWithText);
                outputImage.Source = bmp;
            }

    --Rob

    Thursday, January 23, 2014 6:22 AM
    Moderator