Change image object on template using Brother print Android SDK - java

I have set up label printing from our app using the b-PAC Android SDK (Java). Using the code below I can replace the text from my template with what I want.
// Start creating P-touch Template command print data
Boolean val= myPrinter.startPTTPrint(6, null);
Log.i("print", "startPTTPrint "+val);
// Replace text
myPrinter.replaceText("abcde");
// Trasmit P-touch Template command print data
PrinterStatus status=myPrinter.flushPTTPrint();
I am now trying to replace an image object within the template. I know it can be done in VBScript using:
bpac.Object ob = doc.GetObject("Photo");
ob.SetData(0, #"C:\Photo\635466380534236711.png", 4);
I can't find any Java examples of this within the b-PAC 3.1 SDK help guide and I have only just began coding in Java so I am very much a novice.
Does anyone have experience with the Brother SDK/Java who can point me in the right direction?
Thanks!

I got this working
Basically I have a template that I copy to an new file on which I make the changes
The image object in the template is called imgPart, the other objects are textblocks
Dim m_partNum As String = "12345"
Dim m_PartName As String = "Plate Special 1 x 2" & vbCrLf & "4 Studs"
Dim m_PartImage As String = "c:\Danny\myLego\Labels\PartImages\3033.png"
Dim m_template As String = "c:\Danny\myLego\Templates\PRINTME.lbx"
Dim m_target As String = "c:\Danny\myLego\Templates\" & m_partNum & ".lbx"
Dim doc As bpac.DocumentClass = New bpac.DocumentClass
Try
File.Copy(m_template, m_target, vbTrue)
If doc.Open(m_target) <> False Then
doc.GetObject("imgPart").SetData(0, m_PartImage, 4)
doc.GetObject("txtPartName").Text = m_PartName
doc.GetObject("txtPartNum").Text = m_partNum
doc.Save()
doc.Close()
Else
MsgBox("Open Error on Receipt with error")
End If
Catch ex As Exception
MsgBox("Error occurred : " & ex.ToString)
End Try

Related

Text Outlines in iText

I'm attempting to save a PDF converting the text to outlines (as required by the printer) but cannot seem to make it work. I found a reference to an example on iText's site, but they have changed their site since then and I can't seem to find it now. I am currently embedding the font and that works great, but have no idea how to flatten it so that the text is converted to outlines. I'm using iText 5.5.11 for Java.
If you are using acrobat and .Net,
you can use acrobat iac to invoke javescript to save it to eps which is font outlined.
See JSObjectControlCS sample and javascript SaveAs Reference
JSObjectControlCS
SaveAs
Below is my working sample
///fsharp codes
let saveToEPS src dest =
let avDoc = new AcroAVDocClass()
avDoc.Open(src,"") |> ignore
let pdDoc = avDoc.GetPDDoc() :?> CAcroPDDoc
let jsObj = pdDoc.GetJSObject()
let t = jsObj.GetType()
t.InvokeMember(
"saveAs",
BindingFlags.InvokeMethod ||| BindingFlags.Public ||| BindingFlags.Instance,
null,
jsObj,
[|box dest; box "com.adobe.acrobat.eps"|]
)
|> ignore
Update:
before save to eps, we must add a using convert fonts to outlines preflight
let convertToOutlinesScript = """
var oProfile = Preflight.getProfileByName("Convert fonts to outlines");
var oThermometer = app.thermometer;
var myPreflightResult = this.preflight( oProfile, false, oThermometer);
if( myPreflightResult.numErrors > 0 ) {
console.println( "Preflight found " + myPreflightResult.numErrors + " Errors.");
} """
t.InvokeMember(
"setAction",
BindingFlags.InvokeMethod ||| BindingFlags.Public ||| BindingFlags.Instance,
null,
jsObj,
[|box "WillSave"; box convertToOutlinesScript|]
) |> ignore

How to restart page number from 1 in different group of BIRT report

Backgroud:
Use Java + BIRT to generate report.
Generate report in viewer and allow user to choose to export it to different format (pdf, xls, word...).
All program are in "Layout", no program in "Master Page".
Have 1 "Data Set". The fields in "Layout" refer to this DS.
There is Group in "Layout", gropu by one field.
In "Group Header", I create one cell to use as page number. "Page : MyPageNumber".
"MyPageNumber" is a field I define which would +1 in Group Header.
Problem:
When I use 1st method to generate report, "MyPageNumber" could not show correctly. Because group header only load one time for each group. It would always show 1.
Question:
As I know there is "restart page number in group" in Crystal report. How to restart page in BIRT?
I want to show data of different group in 1 report file, and the page number start from 1 for each group.
You can do it with BIRT reports using page variables. For example:
Add 2 page variables... Group_page, Group_name.
Add 1 report variable... Group_total_page.
In the report beforeFactory add the script:
prevGroupKey = "";
groupPageNumber = 1;
reportContext.setGlobalVariable("gGROUP_NAME", "");
reportContext.setGlobalVariable("gGROUP_PAGE", 1);
In the report onPageEnd add the script:
var groupKey = currGroup;
var prevGroupKey = reportContext.getGlobalVariable("gGROUP_NAME");
var groupPageNumber = reportContext.getGlobalVariable("gGROUP_PAGE");
if( prevGroupKey == null ){
prevGroupKey = "";
}
if (prevGroupKey == groupKey)
{
if (groupPageNumber != null)
{
groupPageNumber = parseInt(groupPageNumber) + 1;
}
else {
groupPageNumber = 1;
}
}
else {
groupPageNumber = 1;
prevGroupKey = groupKey;
}
reportContext.setPageVariable("GROUP_NAME", groupKey);
reportContext.setPageVariable("GROUP_PAGE", groupPageNumber);
reportContext.setGlobalVariable("gGROUP_NAME", groupKey);
reportContext.setGlobalVariable("gGROUP_PAGE", groupPageNumber);
var groupTotalPage = reportContext.getPageVariable("GROUP_TOTAL_PAGE");
if (groupTotalPage == null)
{
groupTotalPage = new java.util.HashMap();
reportContext.setPageVariable("GROUP_TOTAL_PAGE", groupTotalPage);
}
groupTotalPage.put(groupKey, groupPageNumber);
In a master page onRender script add the following script:
var totalPage = reportContext.getPageVariable("GROUP_TOTAL_PAGE");
var groupName = reportContext.getPageVariable("GROUP_NAME");
if (totalPage != null)
{
this.text = java.lang.Integer.toString(totalPage.get(groupName));
}
In the table group header onCreate event, add the following script, replacing 'COUNTRY' with the name of the column that you are grouping on:
currGroup = this.getRowData().getColumnValue("COUNTRY");
In the master page add a grid to the header or footer and add an autotext variable for Group_page and Group_total_page. Optionally add the page variable for the Group_name as well.
Check out these links for more information about BIRT page variables:
https://books.google.ch/books?id=aIjZ4FYJOQkC&pg=PA85&lpg=PA85&dq=birt+change+autotext&source=bl&ots=K0nCmF2hrD&sig=CBOr_otRW0B72sZoFS7LC_1Mrz4&hl=en&sa=X&ei=ZKNAVcnuLYLHsAXRmIHoCw&ved=0CEoQ6AEwBQ#v=onepage&q=birt%20change%20autotext&f=false
https://www.youtube.com/watch?v=lw_k1qHY_gU
http://www.eclipse.org/birt/phoenix/project/notable2.5.php#jump_4
https://bugs.eclipse.org/bugs/show_bug.cgi?id=316173
http://www.eclipse.org/forums/index.php/t/575172/
Alas, this is not supported with BIRT.
That's probably not the answer you've hoped for, but it's the truth.
This is one of the very few aspects where BIRT is way behind other report generator tools.
However, depending on how you have BIRT integrated into your environment, a workaround approach is possible for PDF export that we use in our solution with great success.
The idea is to let BIRT generate a PDF outline based on the grouping.
And the BIRT report creates information in the ReportContext about where and how it wants the page numbers to be displayed.
After BIRT generated the PDF, a custom PDFPostProcessor uses the PDF outline and the information from the ReportContext to add the page numbers with iText.
If this work-around is viable for you, feel free to contact me.

Is it possible to display text on a rich text item in a DocumentContext?

I have a form that runs a java agent on the WebQueryOpen event. This agent pulls data from a DB2 database and then puts them into the computed text fields I have placed on the form and are displayed whenever I open the form in the browser. This is working for me. However, when I try to use RichTextFields I get a ClassCastException error. No document is actually saved, I just open the form in the browser using this domino URL - https://company.com/database.nsf/sampleform?OpenForm
Sample code of simple text field - Displayed with w/o problems
Document sampledoc = agentContext.getDocumentContext();
String samplestr = "sample data from db2";
sampledoc.replaceItemValue("sampletextfield", samplestr);
When I tried using rich text field
Document sampledoc = agentContext.getDocumentContext();
String samplestr = "sample data from db2";
RichTextItem rtsample = (RichTextItem)sampledoc.getFirstItem('samplerichtextfield');
rtsample.appendText(samplestr); // ClassCastException error
Basically, I wanted to use rich text field so that it could accommodate more characters in case I pull a very long string data.
Screenshot of the field (As you can see it's a RichText)
The problem is that you're trying to access a regular Item as a RichTextItem.
The RichTextItem are special fields that are created with its own method just like this:
RichTextItem rtsample = (RichTextItem)sampledoc.createRichTextItem('samplerichtextfield');
It's different to the regular Items that can be created with a simple sampledoc.replaceItemValue(etc).
So, if you want to know if a item is RichTextItem and if it does not exist, create it, you can do this:
RichTextItem rti = null;
Item item = doc.getFirstItem("somefield");
if (item != null) {
if (item instanceof RichTextItem) {
//Yay!
rti = (RichTextItem) item;
} else {
//:-(
}
} else {
rti = doc.createRichTextItem("somefield");
//etc.
}

How to add PPT notes using docx4j

I am creating PPT files using the library docx4j. I have been able to create slides with text and images, but I have not been able to add notes to them.
I am creating the slide like this:
MainPresentationPart pp = (MainPresentationPart)presentationParts.get(new PartName("/ppt/presentation.xml"));
SlideLayoutPart layoutPart = (SlideLayoutPart)presentationParts.get(new PartName("/ppt/slideLayouts/slideLayout1.xml"));
SlidePart slidePart = PresentationMLPackage.createSlidePart(pp, layoutPart, new PartName("/ppt/slides/slide" + ++slideNumber + ".xml"));
so I can add text or images to the body, but when I try to access the field slidePart.notes it is null. I have tried to initialize it
slidePart.setPartShortcut(new NotesSlidePart());
but then everything inside notes is null and I have not achieved anything.
So, does anyone have a working example of how to add notes to a PPT file?
Many thanks
Its not enough to do:
slidePart.setPartShortcut(new NotesSlidePart());
You need to explicitly add the notes slide part to your slide part (so that the relationships get set up correctly), by invoking addTargetPart.
But there's more you have to do given the way the pptx format works. To see what parts are required, upload a pptx to the docx4j webapp. Here's the code I wrote just now based on doing that:
// Now add notes slide.
// 1. Notes master
NotesMasterPart nmp = new NotesMasterPart();
NotesMaster notesmaster = (NotesMaster)XmlUtils.unmarshalString(notesMasterXml, Context.jcPML);
nmp.setJaxbElement(notesmaster);
// .. connect it to /ppt/presentation.xml
Relationship ppRelNmp = pp.addTargetPart(nmp);
/*
* <p:notesMasterIdLst>
<p:notesMasterId r:id="rId3"/>
</p:notesMasterIdLst>
*/
pp.getJaxbElement().setNotesMasterIdLst(createNotesMasterIdListPlusEntry(ppRelNmp.getId()));
// .. NotesMasterPart typically has a rel to a theme
// .. can we get away without it?
// Nope .. read this in from a file
ThemePart themePart = new ThemePart(new PartName("/ppt/theme/theme2.xml"));
// TODO: read it from a string instead
themePart.unmarshal(
FileUtils.openInputStream(new File(System.getProperty("user.dir") + "/theme2.xml"))
);
nmp.addTargetPart(themePart);
// 2. Notes slide
NotesSlidePart nsp = new NotesSlidePart();
Notes notes = (Notes)XmlUtils.unmarshalString(notesXML, Context.jcPML);
nsp.setJaxbElement(notes);
// .. connect it to the slide
slidePart.addTargetPart(nsp);
// .. it also has a rel to the slide
nsp.addTargetPart(slidePart);
// .. and the slide master
nsp.addTargetPart(nmp);
You can find the complete example at https://github.com/plutext/docx4j/blob/master/src/samples/pptx4j/org/pptx4j/samples/SlideNotes.java

jericho Html parser error in jsp page

I have write code as
String sourceUrlString="http://some url";
Source source=new Source(new URL(sourceUrlString));
Element INFORM = source.getElementById("main").getAllElementsByClass("game").get(i-1);
String INFORM = INFORM.replaceAll("\\s",""); //shows error here
sendResponse(resp,+INFORM);
Now i want the text fetch from Element INFORM is Neglect white space how can i do so? above mentioned String INFORM Show error Duplicate local variable INFORM);
e.g
text fetch by Element INFORM is "my name is satish"
but it must send response as
"mynameissatish"
You have the name INFORM used twice - and thats not possible!
String sourceUrlString = "http://some url";
Source source = new Source(new URL(sourceUrlString));
Element INFORM = source.getElementById("main").getAllElementsByClass("game").get(i-1);
String response = INFORM.replaceAll("\\s",""); // ! Use another name here !
sendResponse(resp, respone); // or use '+' - not shure if 1 or 2 args

Categories

Resources