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.
Related
I am writing program to generate PDF from pictures. I want to my pictures will be in normal size foreach page.For example i have image 2000px width and 10000px height and I don`t want to scalling this image. I want his natural size in PDF and not constant A3, A4 or A0. How can I solved that?
Thanks for helps.
If you know the dpi it's just a matter of creating a page with the correct size.
For example with 300dpi and 2000px the size would be (2000/300)*72=480.
I'm working on a project which generally is collecting data and drawing results in charts. (Using C#) I need to save my charts in a PDF file. My question is, how to save charts in a PDF file without loosing resolution? My point is how to draw vector graphics instead of raster graphics?
I tried iTextSharp to create PDF file but the result is not satisfying at all!
I'm new here, so I'm not able to upload pictures.
Here is the result after saving my file:
https://www.dropbox.com/s/ruwtc82hfosxk6y/Test.pdf?dl=0
Here is the PDF that I need to create:
https://www.dropbox.com/s/jvu5uu069imo9xc/nir%20well%20abfar.pdf?dl=0
There are two ways I know of to get high-quality images from your Chart into a PDF.
One is by using vector formats:
Use chart.SaveImage with one of the three emf formats.
Convert the resulting emf file to wmf
Insert the wmf file into your iTextSharp document.
1 and 3 are one-liners. But step 2 is not. In fact I haven't found a working c# solution at all. The best was a weird reference to an edit that has disappeared here ..
If you can use some other program to do the conversion you will get nice results like this demo pdf file.. I used Illustrator for the conversion.
Two: If you can't get step 2 to work, you can still get nice results, if you use raster images with a nice and high resolution. Here is how to do it:
First we hide the Chart, so we don't scare the user. Then we make it as large as we want the output to be. Then we DrawToBitmap and finally we reset the chart again..:
Size s = chart1.Size;
chart1.Hide();
// pick your size in pixels
// I simply multiply my screen size..:
chart1.Size = new System.Drawing.Size(s.Width * 5, s.Height * 5);
using (Bitmap bmp = new Bitmap(chart1.ClientSize.Width, chart1.ClientSize.Height))
{
// you should set the resolution,
// although I didn't find a way for iTextSharp to use it visually
bmp.SetResolution(600, 600);
using (Graphics G = Graphics.FromImage(bmp))
{
G.SmoothingMode = SmoothingMode.HighQuality;
G.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
chart1.DrawToBitmap(bmp, chart1.ClientRectangle);
bmp.Save(yourImageFile, ImageFormat.Png);
}
}
chart1.Size = s;
chart1.Show();
You could also use SaveImage and save a few lines, but you can't set the resolution of the png file there and it will be saved at the currnt screen resolution, which is 96dpi here..
Now you have a large image and will probably have to scale it down in iTextSharp:
iTextSharp.text.Image img = iTextSharp.text.Image.GetInstance(yourImageFile);
img .ScalePercent(15); // scale to fit your needs..
doc.Add(img );
Note that the legend and the labels get very small this way, so you may have to enlarge them before saving. I also found that, when scaling down, the image is rather bright until you zoom in..
Here are two screenshots, one from the chart, the other from the pdf documnet after zooming in a lot (300%)..:
Hi I am using Debenu Quick PDF Lib.
I couldn't see any sample or info about creating custom size PDF document.
For example I want to create a new document in size of 80mm x 100mm in 300 dpi. Is that possible with QP ?
Thank you .
user3253797,
QP.SetMeasurementUnits(1); // Set the measurement units to mm
QP.SetPageDimensions(80.0, 100.0); // Set the page size to 80mm x 100mm
In a PDF file there is no DPI value as nearly all the values in a PDF are based on floating point numbers.
When SetMeasurementUnits is set to 1 then all values you use for drawing are assumed to be in millimetres. ie. QP.DrawLine(0, 0, 25.4, 25.4); will draw a diagonal line from the bottom left corner (0,0) to a point 1 inch up and 1 inch to the right of the bottom corner of the page. If you need the Origin to be based a the top right then you need to call QP.SetOrigin(1); first.
Also, the "Debenu Quick PDF Library 10 Developer Guide.pdf" is the perfect place to start to learn about Debenu Quick PDF Library. It explains the basics of creating PDF files using the library and some of the fundamentals of PDF files.
Andrew.
Disclaimer: I work for Debenu.
I have a richtextbox and by far, i have been successful in converting plain text into pdf using iTextsharp. Now, the situation is, when i copy some text from any source let's say a website and along text, it contains images. Now when i try to convert the content (text + images) into pdf, resulting pdf doesn't show images. I know that there would be some property to be set for the richtextbox or using itextsharp so to have images as well. I also know that we can insert images by giving path to that image but this is not what i want. I want to have plain text along with images while direct conversion from richtextbox to pdf. Forexample i have,![Im resulting pdf i want the same as in richtextbox][1]: http://i.stack.imgur.com/ts0ec.jpg
How can i have the same as in richtextbox? How can i specify orientation for text and image to be justified?
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