Insert graphic/vector drawing from PDF into different PDF using iTextSharp - c#

I'm hitting brick walls trying to see if this is possible.
My current scenario is that we have a process (out of our control) that generates PDFs with an image logo in the top left. The image resolution is very low and looks bad. I'm trying to replace it with a vector based version of the logo and I can't seem to figure out how to do this using iTextSharp. I know that I could insert a higher resolution image, but I want a graphic/vector drawing to be there instead (scales with zoom, for the challenge, etc.)
I've tried to figure out if I can copy the PDF draw operands + content for the graphic into a new PDF but this doesn't seem easily doable.
Is there a way to just insert an SVG at a specific position and size using iTextSharp? Or some other way I can insert this vector graphic?

Related

Create a way in .NET to determine X,Y locations on a PDF for printing

I have a PDF that is a template I will use to print onto special paper stock in a printer. I want to create a way to use the mouse to capture x,y locations when i click on certain areas of the pdf. The pdf template is based on an 8 1/2 x 11 piece of paper.
One of my ideas was to convert the page in the pdf to a jpg and load it into a picturebox using c# and a windows forms application. Then I can capture the x,y when i click the mouse but I'm not sure how that will translate to the pdf.
I'm open to opensource suggestions but I also have both the Aspose Words and Aspose PDF products. I'd also prefer a .NET solution.
Rather than storing a direct X/Y pixel co-ordinate then, you could store them as a % of the page.
So go down your jpeg idea, get the pixel X,Y of your location, then divide those by the Width,Height of the Jpeg to give you X%,Y%
When you come to do your printing, get the paper size and multiply that by your X%,Y% to get your offset within the print document
In the end what worked for me was finding out that 1 inch = 72 points. So as far as the Aspose library was concerned that conversion factor worked for me. THEN I created a jpeg that was 1 pixel by 1 pixel and would stamp that on the PDF using the XIndent and the YIndent. This allowed me to stamp a pixel in the upper left corner of pdf and then using the width and height of the page and the conversion factor I was able to deduce the other 3 corners!

Winforms: Capture part of PDF image to OCR

This is a C# winforms question.
The process I am trying to achieve is the following:
Using AxAcroPDFLib I'm loading a pdf file to the form
I want the user to be able to specify a square on that PDF and create a bmp from it
That bmp will then be loaded to a OCR to become text
What is my issue:
Step 1 and 3 are easy to do, the problem is how to allow the user to draw a square on top of the AxAcroPDFLib for a screenshot.
I already got different ways to draw squares on native winform components, but AxAcroPDFLib does not support mouse down, up, move, etc and paint events.
There is the option to convert the PDF to bitmap and display it on a picturebox and deal with events for drawing the square. Problem with that approach is that my PDF's are usually more than two pages, and I would like to avoid the conversion pdf to bmp due to changes to image quality that will impact on OCR.
I came to think that maybe something that works as the windows snippingtool would do the the job. My application would get the screenshot, temporarily save the image on disk (must be a file for OCR), I would then pass it to the OCR and done. Hard part, I could not think on how to take the screenshot of part of the PDF.
Do anyone here have any suggestion to different components or workarounds to deal with the requirement above? I am using Adobe just because it is simple, but maybe there are other components better suited to handle my requirements? I googled but haven't found any free ones, trying to avoid paid options.
Thanks
At some point in this process, the PDF is going to have to be rasterized in order to be passed to the OCR, so I don't totally understand your objection to converting it to a bitmap. If you're okay with Snipping Tool's behavior, then you must be OK with the quality of the PDF control's PDF->screen rasterization. If that resolution is acceptable, why not just capture the control's content to a Bitmap and let the user draw the selection marquee over that Bitmap?
Here is code I'm using to capture a control's contents to a Bitmap in Windows Forms. One caveat is that this is really a screen capture, so any windows or controls that overlap the control's visible area will be captured in the image.
using (Bitmap b = new Bitmap(width, height))
{
using (Graphics g = Graphics.FromImage(b))
{
Point p1 = myControl.PointToScreen(new Point(0, 0));
g.CopyFromScreen(p1.X, p1.Y, 0, 0, size);
}
// do stuff here with your Bitmap
}

Convert two images into a pdf

I want to convert 2 images into a single pdf file.One image is big in size and small image on the top of the big image.
So In generated pdf also I need to show the small image on the top of the big image and also in the same position where it is in case of image.
I use pdfSharp to convert image to pdf.It will convert the images into pdf file but not able to position the second image on the top of the first image.
Can any one help me on that.Thanks in advance.
Check out the sample below and see if it's what you need:
http://pdfsharp.com/PDFsharp/index.php?option=com_content&task=view&id=34&Itemid=45

Bitmaps in WPF - give watermarking effect and then recover images individually

I am working on a project where I need to play with two bitmaps. I am putting them in a grid one over the other with reduced opacity (to give a watermark effect).
I am rendering the grid to a bitmap using RenderTargetBitmap and saving the bitmap to a file.
Now my requirement is to load the rendered bitmap again and recover the original pictures separately. Is there any way to recover the original images again. I am not able to think any algorithm to implement this.
My aim is to give a watermarking effect and then recover the images individually.
No. The information is lost during "flattening" of the image.
You need to save both images and information about their properties (position, opacity) into single file. And restore it on load.
If your goal is to simulate watermarking and allow later 'dewatermarking', then assuming that you have your watermarking bitmap present at decoding time, you probably can do that. Sure you cannot use your initial approach - just simple merging of two layers is not reversible.
You need to use some reversible transformation, like rotating source image pixel RGB values vector, using watermark image pixel RGB values as parameters. While dewatermarking you just use negative values from watermark image.
Well, RGB vector is not ideal - you can go out of RGB space while rotating it. Probably you can find color space (or some other transformation in RGB space), better suited to your goal.
(English is not my first or even second language, thereby I apologize if you can't understand my idea - just ask over.)
Why don't you try to make it two layers of bitmap?
i wonder if you can use TIFF format, where you can store multiple images. that way on display you can choose to show with/without watermark.

Problem with coordinate system and displaced Text in different PDFs using iTextSharp

I'm working with iTextSharp and .NET 3.5 SP1 (in C#, as you can guess) and modify some existing PDFs using the PdfStamper class. Now I've got two problems:
Transforming the coordinate system
As I see it, iTextSharp is using (postscript?) points as unit of measurement, but I'd like to transform these coordinates to millimeter. Now, how's the best way to achieve this?
Taking a look in the documentation revealed the following approach:
PdfContentByte cb = new PdfContentByte();
System.Drawing.Drawing2D.Matrix scale = new System.Drawing.Drawing2D.Matrix(
0.352777778, 0, 0.352777778, 0, 0, 0); // 1 point = 0.352777778 mm
cb.Transform(scale);
I hope I got the transformation matrix right. But the problem is: There is no System.Drawing.Drawing2D Assembly! Was this assembly dropped or what happened to it? What can I do to transform the coordinates of iTextSharp to millimeter. Am I on the wrong way here?
Text in PDF gets displaced in a different PDF using the same coordinates
I noticed that while modifying two different PDF files with the same content, that the same coordinates got displaced and the text is not being placed at the exact same positions. What is causing this and how can I prevent it?
This is the first PDF:
This is the second PDF, created using the exact same coordinates in iTextSharp:
Any help is appreciated.
But the problem is: There is no
System.Drawing.Drawing2D Assembly! Was
this assembly dropped or what happened
to it? What can I do to transform the
coordinates of iTextSharp to
millimeter. Am I on the wrong way
here?
http://msdn.microsoft.com/en-us/library/system.drawing.drawing2d.matrix.aspx (in System.Drawing.dll)
Okay, I solved the second problem with the text being displaced despite the same coordinates being used.
As it turned out, the first PDF included some non-visible trimming space, the second didn't. The trimming space isn't visible 'cause the view space was cropped using the PDF creator, but as it appears the trimming space was still there and counted for the coordinates.

Categories

Resources