Using iText to save pdf to ColdFusion Variable - pdf

I need to use iText with ColdFusion (CF) because CFDocument won't do everything I need it to, however I would like to return the result into a CF Variable instead of saving it to a file. It seems that every example out there saves the results to a file.
I'm using the following example code to actually generate a pdf but as I said I need it in a variable (preferably without being a file first) because that variable has to be passed on to code another group has written (and I have no control over).
<cfset var document=createObject("java", "com.lowagie.text.Document") />
<cfset var PageSize = createObject("java","com.lowagie.text.Rectangle") />
<cfset var fileIO = createObject("java","java.io.FileOutputStream") />
<cfset var writer = createObject("java","com.lowagie.text.pdf.PdfWriter") />
<cfset var paragraph = createObject("java", "com.lowagie.text.Paragraph") />
<cfset var FontFactory = createObject("java","com.lowagie.text.FontFactory") />
<cfset var Font = createObject("java", "com.lowagie.text.Font") />
<cfset var Courier = Font.init(Font.COURIER, 8.0) />
<cfset var CourierB = Font.init(Font.COURIER_BOLD, 8.0) />
<cfset PageSize.init(612, 792) />
<cfset document.init(PageSize) />
<cfset fileIO.init("C:\test.pdf") />
<cfset writer.getInstance(document, fileIO) />
<cfset document.open() />
<cfset paragraph.init("Hello world.", Courier) />
<cfset document.add(paragraph) />
<cfset document.close() />
I'm not all that great with Java, just basic knowledge, so this could actually be something simple that I'm not understanding.
Thanks

Leigh's comment about using ByteArrayOutputStream was the correct answer.
Here is the updated code that works placing the generated PDF into a ColdFusion variable:
<cfset var document=createObject("java", "com.lowagie.text.Document") />
<cfset var PageSize=createObject("java","com.lowagie.text.Rectangle") />
<cfset var fileIO=createObject("java","java.io.ByteArrayOutputStream") />
<cfset var writer=createObject("java","com.lowagie.text.pdf.PdfWriter") />
<cfset var paragraph=createObject("java", "com.lowagie.text.Paragraph") />
<cfset var FontFactory=createObject("java","com.lowagie.text.FontFactory") />
<cfset var Font = createObject("java", "com.lowagie.text.Font") />
<cfset var Courier = Font.init(Font.COURIER, 8.0) />
<cfset PageSize.init(612, 792) />
<cfset document.init(PageSize) />
<cfset writer.getInstance(document, fileIO) />
<cfset document.open() />
<cfset paragraph.init("Hello world.", Courier) />
<cfset document.add(paragraph) />
<cfset document.close() />
<cfset var returnVar = fileIO.toByteArray() />

Related

ByBit : API ColdFusion

Having trouble with ByBit By/Sell API. ColdFusion any help appreciated.
https://bybit-exchange.github.io/docs/spot/v3/?console#t-authenticationparameters
Authentication for POST
POST
rule: timestamp + api_key + recv_window + raw_request_body
param_str =
"1659073093578T0d98KyVamQ62YBzN85000{
"symbol": "BTCUSDT",
"orderQty":"0.05",
"side": "Sell",
"orderType": "LIMITT",
"timeInForce": "GTC",
"orderPrice": "24500",
"orderLinkId": "spotA0008"
}"
curl --location --request POST 'https://api-testnet.bybit.com/spot/v3/private/order' \
--header 'X-BAPI-API-KEY: {api key}'
--header 'X-BAPI-TIMESTAMP: 1659067662307'
--header 'X-BAPI-RECV-WINDOW: 5000'
--header 'X-BAPI-SIGN: cc63fb44be4a87f4b7bbd42db012ddacc1c935c3d3ae3e01c3b4be393522c213'
--header 'Content-Type: application/json'
--data-raw '{
"symbol": "BTCUSDT",
"orderQty":"0.01",
"side": "Buy",
"orderType": "LIMIT",
"timeInForce": "GTC",
"orderPrice": "21300",
"orderLinkId": "spotx006",
"orderCategory": 1,
"triggerPrice": "21700"
}'
This is the Post Example.
For Account - my signature works fine.
<cfscript>
apiKey = "#_key#";
apiSecret = "#_s#";
newbody = serializeJSON({
"symbol": "#symb#",
"orderQty":"#qty#",
"side": "#side#",
"orderType": "#type#"
});
ts_key_str = #unixdatetimeNow.getTime()# & '#apikey#' & '5000';
str_to_sign = #unixdatetimeNow.getTime()# & '#apikey#' & '5000' & '#newbody#';
HMAC = hmac(str_to_sign, apiSecret, "HMACSHA256");
</cfscript>
<cfhttp url="#base_api##req_path#" method="POST" result="result" charset="utf-8">
<cfhttpparam type="body" value="#newbody#">
<cfhttpparam type="HEADER" name="Content_Type" value="application/json">
<cfhttpparam type="header" name="X-BAPI-SIGN-TYPE" value="2">
<cfhttpparam type="header" name="X-BAPI-API-KEY" value="#_key#">
<cfhttpparam type="header" name="X-BAPI-RECV-WINDOW" value="5000">
<cfhttpparam type="header" name="X-BAPI-SIGN" value="#lhmac#">
<cfhttpparam type="header" name="X-BAPI-TIMESTAMP" value="#unixdatetimeNow.getTime()#">
</cfhttp>
Even adding the ts_key_str in front of new body does not work either.
I get bad signature. When getting account data I using this it works fine cfhttpparam type="body" value=""
Any help appreciated.
It was a timestamp issue.
Set one timestamp, and use that timestamp. So it doesn't maybe pull different timestamp on a delayed call.
Updated code.
<!--- MARKET --->
<cfset b_body = '{"symbol": "#pair#","orderQty":"#size#","side": "#side#","orderType": "MARKET"}'>
<cfset unixdatetimeNow = dateConvert( "local2Utc", now() )>
<cfset timestamp = #unixdatetimeNow.getTime()#>
<cfscript>
apiKey = "#_key#";
apiSecret = "#_s#";
str_to_sign = #timestamp# & '#apikey#' & '5000' & '#b_body#';
HMAC = hmac(str_to_sign, apiSecret, "HMACSHA256");
</cfscript>
<cfset lhmac = lCase(#hmac#)>
<cfhttp url="#base_api##req_path#" method="POST" result="result" charset="utf-8">
<cfhttpparam type="body" value="#b_body#">
<cfhttpparam type="header" name="X-BAPI-SIGN-TYPE" value="2">
<cfhttpparam type="header" name="X-BAPI-SIGN" value="#lhmac#">
<cfhttpparam type="header" name="X-BAPI-API-KEY" value="#_key#">
<cfhttpparam type="header" name="X-BAPI-TIMESTAMP" value="#timestamp#">
<cfhttpparam type="header" name="X-BAPI-RECV-WINDOW" value="5000">
<cfhttpparam type="HEADER" name="Content_Type" value="application/json">
</cfhttp>

Vue-props: can i use type props with $t{{}}

This is similar to the code that i have
<component
type="example" />
but i want to use it like this
<component
type="{{ $t('common.forms.search') }}" />
problem is that its not working
You bind properties in Vue like this:
<component :type="$t('common.forms.search')" />
or verbose:
<component v-bind:type="$t('common.forms.search')" />
See https://v2.vuejs.org/v2/guide/syntax.html#Attributes

change default icon outlook-addin

I try to change the defaut icon of y outlook add-in. By defaut it's blue icon
I changed every logo in my images folder. When I would like add my add-in I see the correct logo
But on Outlook, I have again the old logo []
3
I tried to clean and rebuild the solution, but it didn't change anything. I don't understand why I have always the old logo. I don't know where this old logo come from
Try to add in your manifest file this:
<IconUrl DefaultValue="your URL to image"/>
<HighResolutionIconUrl DefaultValue="your URL to image" />
The image have to be 128x128 .
If you have compose and read tags you need also have this:
<Icon>
<bt:Image size="16" resid="icon16" />
<bt:Image size="32" resid="icon32" />
<bt:Image size="80" resid="icon80" />
</Icon>
When icon16,icon32,icon80 is inside the source tag:
<Resources>
<bt:Images>
<bt:Image id="icon16" DefaultValue="your URL to image"/>
</bt:Images>
</Resources>
You can see full example and explanation here:
https://learn.microsoft.com/en-us/outlook/add-ins/manifests

Primefaces autocorrect option in selenium

Tried to select autocomplete textbox , i'm getting an exception.
WebElement autoOptions = driver.findElement(By.id("form:mat_input"));
autoOptions.sendKeys("b");
html snap :-
<p:autoComplete id="mat" required="true"
value="#{vCreateSupplyRequest._RequestMaterial}"
completeMethod="#{vCreateSupplyRequest.getMaterials}"
var="item" itemLabel="#{item.materialName}" itemValue="#{item}"
converter="materialConverter" forceSelection="true">
<p:ajax event="itemSelect"
listener="#{vCreateSupplyRequest.onMaterialSelection}"
update="mainGrid,mainGrid1" />
<p:column headerText="Material">
<h:outputText value="#{item.materialName}" />
</p:column>
<p:column headerText="Category">
<h:outputText value="#{item.materialCategory.categoryName}" />
</p:column>
</p:autoComplete>

show pdf file in a icefaces modalpopup

Is it possible to show a pdf file in modalpopup with icefaces. Tried this but does not seem to work. Am new to icefaces too.
<ice:panelPopup autoCentre="true" visible="#{popup.visible}" modal="true">
<f:facet name="header"/>
<f:facet name="body">
<OBJECT DATA="/ICEfacesDevelopersGuide.pdf" TYPE="application/pdf" WIDTH="100%" HEIGHT="100%" />
<ice:commandButton value="Close" action="#{popup.close}" />
</f:facet>
</ice:panelPopup>
I ended up doing it the old way opening it on a new window or tab using output link and target attribute.