I want to crop pdf by given coordinates using c#.
How can I do it? What are API/Libraries I can use? (Doesn't matter commercial or not but I can't spent lot)
PDF4NET has the option to crop pages by manipulating directly the page's CropBox or by extracting the page content and cropping it using a clip region.
Disclaimer: I work for the company that develops PDF4NET.
I don't know if it can do exactly what you want, but PDFsharp is a free and open source library for creating PDF files in .NET. I can recommend it.
iTextSharp http://sourceforge.net/projects/itextsharp/ is one that I've used before that I am pretty sure will do what you need. Will find some source code later if I have time.
Related
Hi I'm looking forward to create a pdf viewer like the one in the syncfusion library, telerik library, I would like to learn the working of pdf viewer as I don't want to use the third party application in my application. After some searches realized that we should have to rasterise the pdf doc into image and draw the each image to a frame. Is this the correct way to start. Are there any other ways? please give suggestions
Thankyou
I would take a look at this (now archived) project. It uses the Pdfium rasterizer which is made by Google and is open source and free. The rest of it is from scratch. It will show you everything you need to use Pdfium for what you're suggesting:
https://github.com/pvginkel/PdfiumViewer
As some of the comments alluded, you're not going to realistically be able to make your own renderer from scratch. But there's no reason to. Pdfium is outstanding and interops with C#/WPF perfectly fine.
I use Open XML SDK tool to parse pptx-files. Now I am going to develop my own .NET library/tool to generate an image from a PowerPoint slide. Open XML SDK in principle is not for such tasks, and I do not know where to start research?.
maybe to solve it better to use another programming language, for example, C++ (I also know it) with some library?
or it may be necessary intermediate convert pptx into some another format, for example, HTML and only then to image?
I also tried to investigate Aspose.Slides and Spire.Presentation libraries' dependencies in NuGet to know what they use to an image generation, but these attempts did not succeed.
This looks like a good starting point: Presentation to image conversion
The cited versions are old, but the syntax is still the same: PPT slides to images
My mistake, I misunderstood the end goal.
Does anyone know a way to render or export a pdf with either the text or the images stripped out?
I noticed a way that uses GhostScript:
https://stackoverflow.com/a/38010769/4437032
Unfortunately it would require me to get a commercial licence (since I intend to distribute).
The renderer I have been using up until now has been Pdfium, but that library has no capability to do this (without modifying the native code).
I also looked into PDFSharp, but it seems to be more for appending things to PDFs rather than removing things.
I cannot expect any kind of pdf editing software to be installed on machines that run my program, so ideally I'm looking for some free library.
Does anyone know of any solutions?
I ended up using the free version of Spire.Pdf to accomplish my goal, using it to create pdfs with either text or images. The free version limits you to a max of 10 pages in processed pdfs, but that is acceptable for me.
No images: delete all the images using Spire.Pdf
No text: extract all the images using Spire.Pdf, draw them onto a blank pdf.
then display the modified pdfs.
I want the code for Print the image in pdf.I am having one image and one "Print" button in my form. When i click on that print then image should print in pdf.
We've used PDFSharp pretty heavily and had pretty good luck with it. I would start there and the documentation should allow you to get to your goal pretty quickly.
I've had good results with the open-source iTextSharp, which can easily add images to PDF files. Here is an article from Mike's DotNetting: iTextSharp - Working With Images
I'm using itextsharp to generate the PDFs, but I need to change some text dynamically.
I know that it's possible to change if there's any AcroField, but my PDF doen's have any of it. It just has some pure texts and I need to change some of them.
Does anyone know how to do it?
Actually, I have a blog post on how to do it! But like IanGilham said, it depends on whether you have control over the original PDF. The basic idea is you setup a form on the page and replace the form fields with the text you want. (You can style the form so it doesn't look like a form)
If you don't have control over the PDF, let me know how to do it!
Here is a link to the full post:
Using a template to programmatically create PDFs with C# and iTextSharp
I haven't used itextsharp, but I have been using PDFNet SDK to explore the content of a large pile of PDFs for localisation over the last few weeks.
I would say that what you require is absolutely achievable, but how difficult it is will depend entirely on how much control you have over the quality of the files. In my case, the files can be constructed from any combination of images, text in any random order, tables, forms, paths, single pixel graphics and scanned pages, some of which are composed from hundreds of smaller images. Let's just say we're having fun with it.
In the PDFTron way of doing things, you would have to implement a viewer (sample available), and add some code over a text selection. Given the complexities of the format, it may be necessary to implement a simple editor in a secondary dialog with the ability to expand the selection to the next line (or whatever other fundamental object is used to make up text). The string could then be edited and applied by copying the entire page of the document into a new page, replacing the selected elements with your new string. You would probably have to do some mathematics to get this to work well though, as just about everything in PDF is located on the page by means of an affine transform.
Good luck. I'm sure there are people on here with some experience of itextsharp and PDF in general.
This question comes up from time to time on the mailing list. The same answer is given time and time again - NO. See this thread for the official answer from the person who created iText.
This question should be a FAQ on the itextsharp tag wiki.