Creating custom size PDF document with Debenu Quick PDF - c#

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.

Related

c#, check area of pdf

I need to enter a text to existing pdf (in top or bottom of the page) in c#.
I need to make sure that I dont overwrite any visible text or image.
Is there any way I could check an area in pdf if it contains text, image, control etc? I understand it will not be 100% accurate
You're going to need a full PDF consumer at the very least, because the only way to find out where the marks are on the page is to parse (and possibly render) the PDF.
There are complications which you haven't covered (possibly they have not occurred to you); what do you consider to be the area of the PDF file ? The MediaBox ? CropBox, TrimBox, ArtBox, BleedBox ? What if the PDF file contains, for example, a rectangular fill with white which covers the page ? What about a /Separation space called /White ? is that white (it generally gets rendered that way on the output) or not ? And yes, this is a widely used ink in the T-shirt printing industry amongst others.
To me the simplest solution would seem to be to use a tool which will give you the BoundingBox of marks on the page. I know the Ghostscript bbox device can do this, I imagine there are other tools which can do so. But note (for Ghostscript at least); if there are any marks in white (whatever the colour space), these are considered as marking the page and will be counted into the bbox.
The same tool ought to be able to give the size of the various Boxes in the PDF file (you'd need the pdf_info.ps program for Ghostscript to get this, currently). You can then quickly calculate which areas are unmarked.
But 'unmarked' isn't the same things as 'white'. If you want to not count areas which are painted in 'white' then the problem becomes greater. You really need to render the content and then look at each image sample in the output to see if its white or not, recording the maxima and minima of the x and y co-ordinates to determine the 'non-white' area of the page.
This is because there are complications like transfer functions, transparency blending, colour management, and image masking, any or all of which might cause an area which is marked with a non-white colour to be rendered white (a transparency SMask for example) or an area marked with white to be rendered non-white (eg a transfer function).
Your question is unclear because you haven't defined whether any of these issues are important to you, and how you want to treat them.

Copy and resize a document and fit it into box

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.

PDF doesn't wrap text lines automatically & respect line position

I'm trying to generate a PDF via code because not all actual PDF .NET libraries support the new Windows Runtime for Windows/Windows Phone 8.1.
The PDF is saved correctly, with only a bug of stream position count that I can fix easily, but, as you can see, the text doesn't wrap if line is too long.
I tried with PDF NewLine char (\n), but C# automatically convert it in the input string
Also, I can't understand the position of lines or objects to put into the document, because I follow this guide online that talk about a reversing axis disposition (x for height and y for width), but seems I didn't catch the right methodology (I put in my code a constant left position, at 40, and a variable top descreasing value (from 600, I'm not manage now the multipage if the value is less than 0).
This is the code of PDF generated:
http://pastebin.com/ZkZmbJdM
(Sorry if I use Pastebin, but using this editor Code function the code seems to be unformatted for special characters used for it)
Where am I doing wrong?
PDF is a graphical format trying to make you think it's a document format. But nope, it's just like drawing with GDI+ for instance. This is the reason why it can achieve the same rendered output across many platforms/programs/etc as opposed to text flow formats like doc/docx. And also, this is why it can really render anything.
So, as opposed to document formats, it is the responsibility of the program that generates the PDF to get the layout right. Think of it just as if you'd draw with GDI+.
In documents like docx or html, it's the rendering program that has to do the layout work. With such document, you just write text and the viewer will take care of laying it out.
Your PDF library certainly has the necessary code to measure the text length. Maybe even it has some code to provide some layout capabilities. You'll have to use these functions to do the layout.

How can I find the pixel per inch value in a JPG image?

I am trying to validate certain images to not allow images lower than 300 pixels per inch, is there a way to find it on ASP.NET using C#?
You've got to read EXIF data from the image.
Here you have an example of how you can do it, using ExifLib
ExifLib - A Fast Exif Data Extractor for .NET 2.0+
Be warned that not all jpeg images have the resolution information. And, that even if they have it, you can print them using a completely different resolution. I.e. a pic 200px wide can be printed using 1 inch width is 200dpi. This same image printed using 2 inches is 100dpi, and using 1/2 inch is 400dpi.
EDIT: It's even possible to get this info with native .NET framework Image.PropertyItems Property
The Image object of the .NET Framework will give you the PPI of a Bitmap (including a JPG).
Image image = new Bitmap(#"C:\myimage.jgp");
float ppi = image.HorizontalResolution; // the image's pixels per inch
float widthInInches = image.PhysicalDimension.Width / ppi;
Seems to work for me. I was able to discern that a specific image I am using in a PDF is 90 ppi.

PDF footer at the bottom using iTextSharp

I am trying to create a pdf document in c# using iTextSharp 5.0.6. I want to add header and footer to every page in OnStartPage and OnEndPage events respectively.
In case of footer there is a problem that the footer is created right where the page ends whereas I would like to be at the bottom of page.
Is there a way in iTextSharp to specify page height so that footer is always created at the bottom.
Thanks!
The page's height is always defined:
document.PageSize.Height // document.getPageSize().getHeight() in Java
Keep in mind that in PDF 0,0 is the lower left corner, and coordinates increase as you go right and UP.
Within a PdfPageEvent you need to use absolute coordinates. It sounds like you're either getting the current Y from the document, or Just Drawing Stuff at the current location. Don't do that.
Also, if you want to use the same exact footer on every page, you can draw everything into a PdfTemplate, then draw that template into the various pages on which you want it.
PdfTemplate footerTmpl = writer.getDirectContent().createTemplate( 0, 0, pageWidth, footerHeight );
footerTmpl.setFontAndSize( someFont, someSize );
footerTmpl.setTextMatrix( x, y );
footer.showText("blah");
// etc
Then in your PdfPageEvent, you can just add footerTempl at the bottom of your page:
writer.getDirectContent().addTemplateSimple( footerTmpl, 0, 0 );
Even if most of your footer is the same, you can use this technique to save memory, execution time, and file size.
Furthermore, if you don't want to mess with PdfContentByte drawing commands directly, you can avoid them to some extent via ColumnText. There are several SO questions tagged with iText or iTextSharp dealing with that class. Poke around, you'll find them.

Categories