I want to create a cover page that has text over a background image. Is this possible in MigraDoc / PDFsharp?
Yes.
Background image can be a page from a PDF file or a "real" image (JPEG, BMP, ...).
Add the background image first at an absolute position. Following text will be rendered above the image.
See members Left, Top, RelativeVertical, RelativeHorizontal, etc.
See also here (Images and TextFrames are both Shapes):
http://forum.pdfsharp.net/viewtopic.php?p=3133#p3133
Related
I'm using PDFsharp to create a PDF.
I am trying to copy another document/image (PDF format with A3 size) and paste it within the image box, in the new document (A4 size).
In the new document, there would be an image details box and an image box.
So, how do I copy the image from another PDF into the image box in the new document?
Below is the sample I need to create using PDFsharp.
You can draw pages from other PDF files like you draw images - draw them anywhere at any angle and any size.
You may have to do some calculations to maintain the aspect ratio.
See the Two Pages on One sample:
http://pdfsharp.net/wiki/TwoPagesOnOne-sample.ashx
Lines 40 and 54 draw PDF pages. Check the lines above for prerequisites.
Question
How can I scale an image in XAML quickly without anti-aliasing applied?
Background
I am trying to make a pixel editor as a Windows 8 XAML/C# app. I'm using c#/XAML because most of my experience is with c#/WPF.
Method 1: WriteableBitmap + Image control. Originally, I used a WriteableBitmap to store and edit an image. That image is displayed in a resized XAML Image control. The problem is that the image does not get scaled properly because of anti-aliasing. (XAML does not seem to provide the BitmapScalingOptions that are available in WPF)
Method 2: Redrawn WriteableBitmap + Image control. Next I tried writing my own scaling, where I take my original image and write to a larger WriteableBitmap so that the scaled image is pixelated. The scaled image is then presented inside a XAML Image control. This process is slow and inefficient.
Method 3: SharpDX + Direct2d ?? I am pretty sure a solution exists somewhere between SharpDx, SurfaceImageSource, and Direct2d. Event still, I can't quite figure out how to display a SharpDx.WIC.Bitmap inside a Windows.UI.Xaml Image control, and am generally getting lost in the documentation.
What exactly is a recommended setup for achieving my desired end? Are there c# samples available which might point me in the right direction?
I don't know if you mean by scaling it by resizing it with the mouse or just with a button click to auto scale to a predetermined size.
But the thing you can do is to use an Image panel and then, just set it to image.Stretch = Stretch.Fill; so if you override and create a method for the Resize event of the Image Panel, your image will take the size to fill the Image panel.
I have a logo image that I need to embed in the signature. The logo is such like, a square with 4 parts & each of different part. I want to set watermark on the image, so the text is visible clearly. The code that I use is :
sap.Image = logoSign;
sap.ImageScale = 0.40f;
sap.Image.SetAbsolutePosition(100, 100);
//sap.Image.Transparency.SetValue(50, 0); // Only half image is visible
sap.GetAppearance().AddImage(logoSign);
It is scaled & placed properly. To achieve watermark effect, I add Transparency. When I made its value as (30,0) top left part of the square logo was visible. On making it 50, left half is visible, then I tried with 80, 100, 120, but the full logo is never visible. Elther 1/4th or 1/2 is only visible. The right part that is not showing up has Pink & yellow shades. Surprising is, when I comment the Transparency line, whole logo is visible.
Can anyone help me know, why is it acting like this. And ya, the logo with GIF is only working. PNG &/or JPG logo doesn't show up. Why so ?? I tried other image of jpg also, but no success.
#mkl, RESULTS shown in screenshots
Thanks
My advice would be to edit the image itself to a particular transparency level with the help of an editor and then use it. why do it in the code.
I need to Export some PNG Images with Transparent Background from a C# Application .
But that is not a Huge Concern .
What make's it complicated and beyond my knowledge is ,how am i able to Export to PNG Image File With Transparent Background with Some Text in it,like a Label only without Background so in that way i can export as many images i want with Different Text into it.
And that PNG should had the Size of the Label ,or if there is a way it should FIT the Font Size and Text Length ,so it Height and Width should be same as Font one .
Bests.
You're looking for the Bitmap and Graphics classes, along with the Font class and the TextRenderer.MeasureText method.
Given a PDF file with color and black & white pages, is there any way with C# to find out among the given pages which are color and which are black & white?
My recommendation is to render each page to an image and then check each pixel for RGB values not equal to each other. If R=G=B for each pixel then it's a grayscale image.
You could then perform actions (such as extracting a page to another document or printing the page) on the pages based on whether they are color pages or black and white pages, etc.
This can be achieved by using my companies PDF developer library, Quick PDF, or potentially by one of the open source PDF libraries that Kenneth suggested.
Short of parsing all the postscript content, probably not. There's no flag on a PDF page that says it is or is not b&w or color. So you'd have to check the color of every element placed on the page to figure out if it was color or not. I'm not sure what libraries exist for reading PDFs on C# but you would need one that will read all the elements.
Similarly, any images you have on the page would need to be checked for color and that is not simple. Color image formats can hold b&w images.
Check out:
PDF-Analyser
I use his tools for text extraction and pdf analysis. Very inexpensive, royalty free, and work well. I think GetPDFColourStyle as part of the PDFLayoutPlus library should do the trick.
Convert each page into bitmap image and then look through each pixel in the image you would be able to catch colours and then differentiate color pages.
refer this Post for more details.
Note: If your are detecting this colors for printing sake, then you have to detect CMYK colors not RGB, CMYK is the printer standard color mode, and RGB is a display color mode.
There is a solution.
You can parse each page content bytes and look for color operators like 'rg, RG, k, K, sc, SC, scn, SCN' and read out all the color values and color spaces defined in each page.
Take a look at this example: http://habjan.blogspot.com/2013/09/proof-of-concept-converting-pdf-files.html
It implements / parses all color operators and I think it will be a good start point and reference to help you code what you need.