We have purchased and are using your software.
- aspose-pdf for java version: ‘24.1’
[ Purchased Information ]
LicenseType : Developer OEM
UserID : 969024
Product : Aspose.Total for Java
[ The problem ]
Problem # 1.
I’m using Aspose.PDF for Java and converting it to pdf in X_1A format via document.convert(saveFile, PdfFormat.PDF_X_1A, ConvertErrorAction.Delete).
However, I need to be able to save the text, rectangular box, etc. as a pdf with only k among the cmyk values, but so far I can’t find that feature in Aspose.PDF for Java.
Even if I use the Color.fromCmyk(0, 0, 0, 1) function, it seems to save as RGB in the end, and if I check the converted cmyk values after pdfDocument.convert() using Adobe Acrobat Pro DC’s Output Preview, I can see that C, M, and Y are also set in addition to K.
How can I set the values to 0 for C, M, and Y and assign a value of 1 to K only?
image.png (54.6 KB)
- ref #1. CMYK layers are recognized
image.png (107.1 KB)
- ref #2. The color is black, but it can also be seen on CMY layers.
Problem # 2.
When using real code rather than the sample code, after converting to cmyk format using pdfDocument.convert() and saving, the size more than doubled (300 KB → about 800 KB).
Just one line of CMYK conversion code increased the size from before.
document.convert(saveFile, PdfFormat.PDF_X_1A, ConvertErrorAction.Delete)
I need to create a large number of PDFs, is there any way to work around the increase in size?
[ Sample Source ]
import com.aspose.pdf.BorderInfo;
import com.aspose.pdf.BorderSide;
import com.aspose.pdf.Color;
import com.aspose.pdf.ConvertErrorAction;
import com.aspose.pdf.Document;
import com.aspose.pdf.FloatingBox;
import com.aspose.pdf.FontStyles;
import com.aspose.pdf.HorizontalAlignment;
import com.aspose.pdf.License;
import com.aspose.pdf.MarginInfo;
import com.aspose.pdf.Page;
import com.aspose.pdf.PdfFormat;
import com.aspose.pdf.TextFormattingOptions;
import com.aspose.pdf.TextFragment;
import com.aspose.pdf.VerticalAlignment;
import com.aspose.pdf.drawing.Graph;
import com.aspose.pdf.drawing.Rectangle;
import org.junit.jupiter.api.Test;
import org.springframework.util.StringUtils;
import java.io.FileInputStream;
public class AsposeTest {
@Test
void asposeCmykTest() throws Exception {
FileInputStream fstream = new FileInputStream("Aspose.lic");
License license = new License();
license.setLicense(fstream);
String saveFile = "asposeCMYKTest.pdf";
Document document = new Document();
Page page = document.getPages().add();
Color blackColor = Color.fromCmyk(0, 0, 0, 1);
String text = "Black Color Convert";
drawRect(page, 5, 5 ,10, 10, blackColor, 0);
drawTextBox(page, 5, 20 ,100, 20, 4, null, text, blackColor, 10, FontStyles.Bold, HorizontalAlignment.Left.getValue(), VerticalAlignment.Top.getValue());
document.convert(saveFile, PdfFormat.PDF_X_1A, ConvertErrorAction.Delete);
document.save(saveFile);
}
static double mmToPixel(double value) {
return (value / 10 / 2.54 * 72);
}
void drawRect(Page page, float x, float y, float width, float height, Color color, int zindex) {
// create graph object with dimensions same as specified for Rectangle object
Graph graph = new Graph(mmToPixel(width), mmToPixel(height));
// can we change the position of graph instance
graph.setChangePosition(false);
// set Left coordinate position for Graph instance
graph.setLeft(mmToPixel(x));
// set Top coordinate position for Graph object
graph.setTop(mmToPixel(y));
// Add a rectangle inside the "graph"
Rectangle rect = new Rectangle(0, 0, (float) mmToPixel(width), (float) mmToPixel(height));
// set rectangle fill color
rect.getGraphInfo().setFillColor(color);
// color of graph object
rect.getGraphInfo().setColor(color);
// add rectangle to shapes collection of graph instance
graph.getShapes().add(rect);
// set Z-Index for rectangle object
graph.setZIndex(zindex);
// add graph to paragraphs collection of page object
page.getParagraphs().add(graph);
}
void drawTextBox(Page page,float x,float y,float width,float height, float circleSize,Color fillColor,String text,Color textColor,float fontSize,int fontStyle,int hAlignment,int vAlignment){
FloatingBox box=new FloatingBox((float) mmToPixel(width), (float) mmToPixel(height));
box.setLeft(mmToPixel(x));
box.setTop(mmToPixel(y));
box.setHeight(mmToPixel(height));
box.setWidth(mmToPixel(width));
box.setBorder(new BorderInfo(BorderSide.All,(float)0.5,textColor));
box.setVerticalAlignment(VerticalAlignment.valueOf(vAlignment));
if(fillColor!=null){
box.setBackgroundColor(fillColor);
}
box.setPadding(new MarginInfo(0, 0, 0, 0));
box.setMargin(new MarginInfo(0,0,0,0));
box.setNeedRepeating(false);
TextFragment textFragment;
if(!StringUtils.isEmpty(text)){
textFragment = new TextFragment(text);
} else {
textFragment = new TextFragment("");
}
// set text properties
textFragment.getTextState().setFontSize(fontSize);
textFragment.getTextState().setForegroundColor(Color.getBlack());
textFragment.getTextState().setFontStyle(fontStyle);
textFragment.getTextState().setHorizontalAlignment(HorizontalAlignment.valueOf(hAlignment));
textFragment.getTextState().setHorizontalScaling(88); // 100 default
TextFormattingOptions textFormattingOptions = new TextFormattingOptions();
textFormattingOptions.setWrapMode(TextFormattingOptions.WordWrapMode.DiscretionaryHyphenation);
textFragment.getTextState().setFormattingOptions(textFormattingOptions);
box.getParagraphs().add(textFragment);
page.getParagraphs().add(box);
}
}
[ PDFs created with Sample sources ]
asposeCMYKTest.pdf (550.6 KB)
I look forward to hearing back from Aspose.
Thank you.