Detect if PDF is colored [DATALOGICS][APDFL] - pdf

I am using APDFL 10.1.0 to convert PDF to images. This is how I am loading the PDF file and saving a specific page as image:
Document pdfdocument = null;
pdfdocument = new Document(docpath);
Page docpage = pdfdocument.GetPage(pagelist[0]);
Image pageimage = docpage.GetImage(PageRect);
Is there a way to detect from either the docpage variable or the pageimage variable if the specific page is colored or is grayscale?

You can use pageImage.NumberComponents to determine this. Color Images will have 3 or 4 components (depending on whether it is an RGB Image or a CMYK Image) while grayscale Images will have 1 component.

Related

How to rotate an Image using Itex7 and C#?

I am using the C#SDK for iText . As a simple test I'm creating a PDF with an Image in it. What I want to do is to rotate this Image in the PDF. This is the code I'm using
PdfWriter writer = new PdfWriter("./test.pdf", new WriterProperties().SetPdfVersion(PdfVersion.PDF_2_0));
PdfDocument pdfDocument = new PdfDocument(writer);
pdfDocument.SetTagged();
Document document = new Document(pdfDocument);
Image image = new Image(ImageDataFactory.Create("google-logo.png")).SetRotationAngle(90).SetAutoScale(true);
document.Add(image);
document.Close();
However, in the generated file, the Image shows like this
So how can I rotate the Image by 90 degrees?
The documentation of Image#SetRotationAngle says that the value must be passed in radians, not in angles.
So just replacing image.SetRotationAngle(90) with image.SetRotationAngle(Math.PI / 2) should do the trick

MigraDoc Rotate Image (vb.net)

I am trying to create a PDF using MigraDoc Library. I can add an image, but unable to rotate images. I am creating a MigraDoc.DocumentObjectModel.Shapes.Image object to add the image to a section. Is it possible to rotate the image or do I have to add the image another way?
Public Sub AddImageToPDFFile(sec As Section)
Dim image As Image
Dim strImagePath = "image.jpg"
image = sec.AddImage(strImagePath)
image.Height = "10cm"
image.LockAspectRatio = True
image.RelativeVertical = RelativeVertical.Line
image.RelativeHorizontal = RelativeHorizontal.Margin
image.Top = ShapePosition.Top
image.Left = ShapePosition.Left
image.WrapFormat.Style = WrapStyle.Through
End Sub
I'm afraid MigraDoc cannot rotate the image.
Maybe rotate the image with code before adding it to MigraDoc.
It might also be possible, depending on your requirements, to add the image later using PDFsharp. MigraDoc uses PDFsharp to create the PDF and thus you can use PDFsharp for modifications without adding an additional tool to the process.

PDFBox converting colorspace of existing pdf

Problem:
I have a existing pdf which have some images and text. This pdf has mixed color space RGB and CMYK. I want to convert it into single color-space pdf preferably into CMYK.
Using : PDFBox 2.0.4
PDFBox has PDPageContentStream which can used to change the add color-space when adding data to the existing pdf like below:
PDDocument document = PDDocument.load(myPdfWithMixColorSpace);
PDPage pdPage = document.getPage(0);
PDPageContentStream imageContentStream = new PDPageContentStream(document, page);
imageContentStream.setNonStrokingColor(0, 0, 0, 255); // for cmyk color space
imageContentStream.beginText();
imageContentStream.setFont(PDType1Font.TIMES_ROMAN, 20.15f);
imageContentStream.newLineAtOffset(13.55f, 50f);
imageContentStream.showText("this is test");
imageContentStream.endText();
imageContentStream.close();
document.save("D:\\newPDF.pdf");
document.close();
newPDF.pdf has the text added to it in CMYK color, But I don't want to add text or image in CMYK color on the existing pdf, but to convert the color-space of all the content of the input pdf itself.
In summary what I want is:
Given a pdf having mix color space for image and text in it.
Then using pdfbox
Create a new pdf or update the existing pdf with cmyk color space for all its content.

How to load an image in active document? (Photoshop Scripting)

I am new to photoshop scripting.
I want to load an image image (from my hard disk) into the active document as a new layer with positioning. How can this be done? Can somebody please share the code?
Thanks
You can open Photoshop File Dialog for searching your image and adding that into a layer
file = app.openDialog();//opens dialog,choose one image
if(file[0]){ //if you have chosen an image
app.load(file[0]); //load it into documents
backFile= app.activeDocument; //prepare your image layer as active document
backFile.resizeImage(width,height); //resize image into given size i.e 640x480
backFile.selection.selectAll();
backFile.selection.copy(); //copy image into clipboard
backFile.close(SaveOptions.DONOTSAVECHANGES); //close image without saving changes
doc.paste(); //paste selection into your document
doc.layers[0].name = "BackgroundImage"; //set your layer's name
}
There is a good example of making a calendar with photoshop javascript extension (.jsx).
Please check that here

Adding a dynamic image to a PDF using ColdFusion and iText

I pieced together some code to insert a dynamic image into a PDF using both ColdFusion and iText, while filling in some form fields as well. After I got it working and blogged about it, I couldn't help but think that there might be a better way to accomplish this. I'm using the basic idea of this in a production app right now so any comments or suggestion would be most welcomed.
<cfscript>
// full path to PDF you want to add image to
readPDF = expandpath(”your.pdf”);
// full path to the PDF we will output. Using creatUUID() to create
// a unique file name so we can delete it afterwards
writePDF = expandpath(”#createUUID()#.pdf”);
// full path to the image you want to add
yourimage = expandpath(”dynamic_image.jpg”);
// JAVA STUFF!!!
// output buffer to write PDF
fileIO = createObject(”java”,”java.io.FileOutputStream”).init(writePDF);
// reader to read our PDF
reader = createObject(”java”,”com.lowagie.text.pdf.PdfReader”).init(readPDF);
// stamper so we can modify our existing PDF
stamper = createObject(”java”,”com.lowagie.text.pdf.PdfStamper”).init(reader, fileIO);
// get the content of our existing PDF
content = stamper.getOverContent(reader.getNumberOfPages());
// create an image object so we can add our dynamic image to our PDF
image = createobject(”java”, “com.lowagie.text.Image”);
// get the form fields
pdfForm = stamper.getAcroFields();
// setting a value to our form field
pdfForm.setField(”our_field”, “whatever you want to put here”);
// initalize our image
img = image.getInstance(yourimage);
// centering our image top center of our existing PDF with a little margin from the top
x = (reader.getPageSize(1).width() - img.scaledWidth()) - 50;
y = (reader.getPageSize(1).height() - img.scaledHeight()) / 2 ;
// now we assign the position to our image
img.setAbsolutePosition(javacast(”float”, y),javacast(”float”, x));
// add our image to the existing PDF
content.addImage(img);
// flattern our form so our values show
stamper.setFormFlattening(true);
// close the stamper and output our new PDF
stamper.close();
// close the reader
reader.close();
</cfscript>
<!— write out new PDF to the browser —>
<cfcontent type=”application/pdf” file = “#writePDF#” deleteFile = “yes”>
<cfpdf> + DDX seems possible.
See http://forums.adobe.com/thread/332697
I have made it in another way with itext library
I don´t want overwrite my existing pdf with the image to insert, so just modify the original pdf inserting the image, just insert with itext doesn´t work for me.
So, I have to insert the image into a blank pdf (http://itextpdf.com/examples/iia.php?id=59)
And then join my original pdf and the new pdf-image. Obtaining one pdf with several pages.
(http://itextpdf.com/examples/iia.php?id=110)
After that you can overlay the pdf pages with this cool concept
http://itextpdf.com/examples/iia.php?id=113