I have problem with SAS ODF PDF.
In macro loop according to specific variable I need create a lot of pdfs.
But, once with security password, another time without security password.
My problem:
When I first time set options as:
options nodate nonumber nocenter papersize="A4" orientation=PORTRAIT pdfsecurity=high pdfpassword=(open=&&pass);
my macro remember these options even I'll set new options like:
options nodate nonumber nocenter papersize="A4" orientation=PORTRAIT pdfsecurity=none;
New pdf should be create without password, but macro created new pdf with password, and it is from the previous iteration.
How I can dynamic sets new options depending on the need?
data base_of_cust;
input lp check_MAIL $ ID_CONTRACT ID_CUSTOMER;
datalines;
1 ok 123 1234
2 error 124 1235
3 ok 125 1236
4 ok 126 1237
5 error 127 1238
;run;
%macro Create_pdfs(n);
%do i = 1 %to &n.; /* start loop */
proc sql noprint;
select
ID_CONTRACT, ID_CUSTOMER, check_MAIL into :nrref, :nrcust, :validmail
from base_of_cust c where c.lp=&i.;
Quit;
/* IF check_MAIL is 'ok' then create pdf with password*/
%IF &validmail. = ok %then %do;
options nodate nonumber nocenter papersize="A4" orientation=PORTRAIT pdfsecurity=high pdfpassword=(open=&&nrref);
ods pdf file = "xx\email\%sysfunc(today(),ddmmyyp10.)_%CMPRES(&nrref.)%CMPRES(&nrcust.).pdf"
STARTPAGE =no bookmarklist = none color=yes
style=tfs;
title;
ODS escapechar="^";
ods pdf title="^S={just=l font_size=2pt font_face=Arial}aa";
ODS PDF text= "^S={just=l font_weight=bold font_size=12pt font_face=Arial} ";
ODS PDF text= "^S={just=l font_size=12pt font_face=Arial}fake test text ";
ODS _ALL_ CLOSE;
%end;
/* if error create in another location pdf without password */
%IF &validmail. = error %then %do;
options nodate nonumber nocenter papersize="A4" orientation=PORTRAIT pdfsecurity=none;
ods pdf file = "xx\poczta\%sysfunc(today(),ddmmyyp10.)_%CMPRES(&nrref.)%CMPRES(&nrcust.).pdf"
STARTPAGE =no bookmarklist = none color=yes
style=tfs;
title;
ODS escapechar="^";
ods pdf title="^S={just=l font_size=2pt font_face=Arial}aa";
ODS PDF text= "^S={just=l font_weight=bold font_size=12pt font_face=Arial} ";
ODS PDF text= "^S={just=l font_size=12pt font_face=Arial}fake test text ";
ODS _ALL_ CLOSE;
%end;
%end; /* end loop */
%mend;
%Create_pdfs(5);
Best regards
Related
How can I put 2 chunks of code side by side in the output file of RMarkdown or Quarto ?
Code
library(dplyr)
mtcars %>% select(gear)
library(dplyr)
select(mtcars, gear)
Desired layout in the PDF or HTML file
The canonical way for something like this is to use column divs:
::::: columns
::: column
```r
library(dplyr)
mtcars %>% select(gear)
```
:::
::: column
```r
library(dplyr)
select(mtcars, gear)
```
:::
:::::
This will work with HTML, reveal.js, Beamer, and Powerpoint. The default result looks a bit ugly in HTML, as there is no space between the two blocks, but we can fix that with a tiny bit of CSS. We can put it directly into the document:
<style>
.column { padding-right: 1ex }
.column + .column { padding-left: 1ex }
</style>
Things get more complicated if we wish to do the same for PDF. We'll need convert the divs into a table, as that's the most effective way to get elements side-by-side. But that requires some heavier tools. In the YAML header, add
output:
pdf_document:
pandoc_args:
- "--lua-filter=columns-to-table.lua"
Then save the below code into a file column-to-table.lua.
function Div (div)
if div.classes:includes 'columns' then
local columns = div.content
:filter(function (x)
return x.classes and x.classes[1] == 'column'
end)
:map(function (x)
return x.content
end)
local aligns = {}
local widths = {}
local headers = {}
for i, k in ipairs(columns) do
aligns[i] = 'AlignDefault'
widths[i] = 0.98/ #columns
end
return pandoc.utils.from_simple_table(
pandoc.SimpleTable('', aligns, widths, headers, {columns})
)
end
end
You can get rid of the lines around the table by adding
\renewcommand\toprule[2]\relax
\renewcommand\bottomrule[2]\relax
at the beginning of your document.
---
title: "Untitled"
output: html_document
---
:::::::::::::: {.columns}
::: {.column width="50%"}
```{r warning=FALSE,message=FALSE}
library(dplyr)
mtcars %>% select(gear)
```
:::
::: {.column width="50%"}
```{r warning=FALSE,message=FALSE}
library(dplyr)
select(mtcars, gear)
```
:::
::::::::::::::
used This SO question as a resource. This is using pandoc to format the document in Rmarkdown HTML output
I am using sample exel code and add using PDO to add data export excel
if (PHP_SAPI == 'cli')
die('This example should only be run from a Web Browser');
/** Include PHPExcel */
require_once dirname(__FILE__) . '/Classes/PHPExcel.php';
// Create new PHPExcel object
$objPHPExcel = new PHPExcel();
i am edit some properties
// Set document properties
$objPHPExcel->getProperties()->setCreator("Team IT KSP PRIMADANA")
->setLastModifiedBy("Team IT KSP PRIMADANA")
->setTitle("DATA NASABAH")
->setSubject("KSP PRIMADANA")
->setDescription("Data Perusahaan.")
->setKeywords("office 2007 openxml php")
->setCategory("Penting");
i am also add some data for header excel, until this code, when try download is okay an not error.
// Add some data
$objPHPExcel->setActiveSheetIndex(0)
->setCellValue('A1', 'Tanggal Masuk')
->setCellValue('B1', 'Nomor Register')
->setCellValue('C1', 'Cabang');
then when add looping PDO to add data content table and download it, value from this database make symbol data excel
$host = 'localhost';
$username = 'root';
$password = 'server';
$dbname = 'primadana';
// Create your database query
this is my PDO for print data from database to excel which make text to symbol
try{
$conn = new PDO("mysql:host=$host;dbname=$dbname",$username,$password);
//$stmt = $conn->prepare('select * from tblpdo where age=:age');
$stmt = $conn->prepare('SELECT * FROM data_berkas_masuk where user_id = 6 order by user_id');
$result=$stmt->fetchAll();
$no=2;
if(count($result))
{
foreach ($result as $row) {
$objPHPExcel->getActiveSheet()->SetCellValue('A'.$no, ($row['in_tgl']));
$no++;
}
}
else{echo "no rows returned";}
}
catch(PDOException $e){
echo 'ERROR: '.$e->getMessage();
}
// Rename worksheet
$objPHPExcel->getActiveSheet()->setTitle('Simple');
// Set active sheet index to the first sheet, so Excel opens this as the first sheet
$objPHPExcel->setActiveSheetIndex(0);
// Redirect output to a client’s web browser (Excel5)
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="01simple.xls"');
header('Cache-Control: max-age=0');
// If you're serving to IE 9, then the following may be needed
header('Cache-Control: max-age=1');
// If you're serving to IE over SSL, then the following may be needed
header ('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past
header ('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); // always modified
header ('Cache-Control: cache, must-revalidate'); // HTTP/1.1
header ('Pragma: public'); // HTTP/1.0
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
$objWriter->save('php://output');
exit;
?>
i find myself lol.
$stmt = $conn->prepare('SELECT * FROM data_berkas_masuk where user_id = 6 order by user_id');
$stmt->execute();
$result=$stmt;
I am Trying to extract the text from the this pdf using the LocationTextExtractionStrategy.class, but for some reason a number of characters are being dropped during the parsing.
On the first page of the original .pdf;
【表紙】
【提出書類】有価証券報告書
【根拠条文】金融商品取引法第24条第1項
【提出先】近畿財務局長
【提出日】平成22年6月28日
【事業年度】第27期(自 平成21年4月1日 至 平成22年3月31日)
【会社名】株式会社カネミツ
【英訳名】KANEMITSU CORPORATION
Resulting text output has numbers such as 22,28 and the english text "KANEMATSU" missing;
【表紙】
【提出書類】 有価証券報告書
【根拠条文】 金融商品取引法第条第1項
【提出先】 近畿財務局長
【提出日】 平成年6月日
【事業年度】 第期(自 平成年4月1日 至 平成年3月日)
【会社名】 株式会社カネミツ
【英訳名】
Here's the code...
PdfReader reader = new PdfReader(sourceFileUrl);
String strategyClass = “com.itextpdf.text.pdf.parser.LocationTextExtractionStrategy.class”
int n = reader.getNumberOfPages();
for(int I = 1; I < n; i++) {
TextExtractionStrategy strategy = (TextExtractionStrategy) Class.forName(strategyClass).newInstance();
String text = PdfTextExtractor.getTextFromPage(reader, i,strategy);
…
}
I have reviewed other questions of a similar nature on SO, this page is similar although i am able to copy the text from the pdf directly so this is probably a different issue.
I have this perl script which takes the data from sqlplus database... this database adds a new entry every time when there is a change in the value of state for a particular serial number. Now we need to pick the entries at every state change and prepare a csv file with old state, new state and other fields. db table sample.
SERIALNUMBER STATE AT OPERATORID SUBSCRIBERID TRANSACTIONID
51223344558899 Available 20081008T10:15:47 vsuser
51223344558857 Available 20081008T10:15:49 vsowner
51223344558899 Used 20081008T10:20:25 vsuser
51223344558860 Stolen 20081008T10:15:49 vsanyone
51223344558857 Damaged 20081008T10:50:49 vsowner
51223344558899 Damaged 20081008T10:50:25 vsuser
51343253335355 Available 20081008T11:15:47 vsindian
my script:
#! /usr/bin/perl
#use warnings;
use strict;
#my $circle =
#my $schema =
my $basePath = "/scripts/Voucher-State-Change";
#my ($sec, $min, $hr, $day, $month, $years) = localtime(time);
#$years_+=1900;$mont_+=1;
#my $timestamp=sprintf("%d%02d%02d",$years,$mont,$moday);
sub getDate {
my $daysago=shift;
$daysago=0 unless ($daysago);
#my #months=qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec);
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time-(86400*$daysago));
# YYYYMMDD, e.g. 20060126
return sprintf("%d%02d%02d",$year+1900,$mon+1,$mday);
}
my $filedate=getDate(1);
#my $startdate="${filedate}T__:__:__";
my $startdate="20081008T__:__:__";
print "$startdate\n";
##### Generating output file---
my $outputFile = "${basePath}/VoucherStateChangeReport.$filedate.csv";
open (WFH, ">", "$outputFile") or die "Can't open output file $outputFile for writing: $!\n";
print WFH "VoucherSerialNumber,Date,Time,OldState,NewState,UserId\n";
##### Generating log file---
my $logfile = "${basePath}/VoucherStateChange.$filedate.log";
open (STDOUT, ">>", "$logfile") or die "Can't open logfile $logfile for writing: $!\n";
open (STDERR, ">>", "$logfile") or die "Can't open logfile $logfile for writing: $!\n";
print "$logfile\n";
##### Now login to sqlplus-----
my $SQLPLUS='/opt/oracle/product/11g/db_1/bin/sqlplus -S system/coolman7#vsdb';
`$SQLPLUS \#${basePath}/VoucherQuery1.sql $startdate> ${basePath}/QueryResult1.txt`;
open (FH1, "${basePath}/QueryResult1.txt");
while (my $serial = <FH1>) {
chomp ($serial);
my $count = `$SQLPLUS \#${basePath}/VoucherQuery2.sql $serial $startdate`;
chomp ($count);
$count =~ s/\s+//g;
#print "$count\n";
next if $count == 1;
`$SQLPLUS \#${basePath}/VoucherQuery3.sql $serial $startdate> ${basePath}/QueryResult3.txt`;
# print "select * from sample where SERIALNUMBER = $serial----\n";
open (FH3, "${basePath}/QueryResult3.txt");
my ($serial_number, $state, $at, $operator_id);
my $count1 = 0;
my $old_state;
while (my $data = <FH3>) {
chomp ($data);
#print $data."\n";
my #data = split (/\s+/, $data);
my ($serial_number, $state, $at, $operator_id) = #data[0..3];
#my $serial_number = $data[0];
#my $state = $data[1];
#my $at = $data[2];
#my $operator_id = $data[3];
$count1++;
if ($count1 == 1) {
$old_state = $data[1];
next;
}
my ($date, $time) = split (/T/, $at);
$date =~ s/(\d{4})(\d{2})(\d{2})/$1-$2-$3/;
print WFH "$serial_number,$date,$time,$old_state,$state,$operator_id\n";
$old_state = $data[1];
}
}
close(WFH);
query in VoucherQuery1.sql:
select distinct SERIALNUMBER from sample where AT like '&1';
query in VoucherQuery2.sql:
select count(*) from sample where SERIALNUMBER = '&1' and AT like '&2';
query in VoucherQuery2.sql:
select * from sample where SERIALNUMBER = '&1' and AT like '&2';
and my sample output:
VoucherSerialNumber,Date,Time,OldState,NewState,UserId
51223344558857,2008-10-08,10:50:49,Available,Damaged,vsowner
51223344558899,2008-10-08,10:20:25,Available,Used,vsuser
51223344558899,2008-10-08,10:50:25,Used,Damaged,vsuser
Script is working pretty fine. But problem is that actual db table has millions of records for a specific day... and therefore it is raising performance issues... could you please advise how can we improve the efficiency of this script in terms of time & load. Only restriction is that I can't use DBI module for this...
Also in case of any error in the sql queries, error msg is coming to QueryResult?.txt files. I want to handle and receive these errors in my log file. how this can be accomplished? thanks
I think you need to tune your query. A good starting point is to use the EXPLAIN PLAN, if it is an Oracle database.
I want to retrieve the email address from the table and using that to send email using perl script.
How to use the query result in mail.
I am new to perl scripting please help.
I have updated as suggested but still there are some issues.
Please tell me where I am going wrong.
Thanks in advance.
#!/usr/bin/perl
# $Id: outofstockmail.pl,v 1.0 2012/03/01 21:35:24 isha Exp $
require '/usr/home/fnmugly/main.cfg';
use DBI;
my $dbh = DBI->connect($CFG{'mysql_dsn'},$CFG{'mysql_user'},
$CFG{'mysql_password'})
or &PrintError("Could not connect to the MySQL Database.\nFile could not be made!\n");
$dbh->{RaiseError} = 1; # save having to check each method call
print "<H1>Hello World</H1>\n";
$sql = "Select OS.name, OS.customer_email, OS.product, OS.salesperson,
OS.salesperson_email
from products AS P
LEFT JOIN outofstock_sku AS OS ON OS.product = P.sku
LEFT JOIN tech4less.inventory AS I ON (I.sku = P.sku AND I.status = 'A')
WHERE mail_sent='0'
GROUP BY OS.product";
#$sth = $dbh->do($sql);
my $sth1 = $dbh->prepare($sql);
$sth1->execute;
while ( my #row = $sth1->fetchrow_array ) {
# email
open MAIL, "| $mail_prog -t" || die "Could not connect to sendmail.";
print MAIL "To: $row[1]";
print MAIL "From: $row[4]";
print MAIL "Reply-To:$row[4]";
print MAIL "CC: $row[4]";
print MAIL "Subject: Product requested is back in inventory\n";
print MAIL "\n";
print MAIL "Hi $row[0] , The product $row[2] is available in the stock.\n";
print MAIL "\n";
close MAIL;
$sql = "Update outofstock_sku SET mail_sent='0' WHERE mail_sent='1'";
$sth2 = $dbh->do($sql);
}
$sth = $dbh->do($sql);
$dbh->disconnect();
exit;
This script has too many problems to address question specifically:
1) Use use strict; use warnings;. It will help you to be more accurate.
2) DBI->connect() takes options as last argument, so you can set RaiseError there:
my $dbh = DBI->connect($dsn, $user, $pwd, { RaiseError => 1 });
3) $dbh->do doesn't return sth object. You need prepare and execute:
my $sth = $dbh->prepare($sql);
$sth->execute;
while ( my #row = $sth->fetchrow_array ) {
...
print MAIL "Hi $row[0]. We're happy to ... $row[1]...\n";
...
}
4) To send mail use a module, for example Email::Sender::Simple.
Scary to think how much old code like this is still in use out there.
You don't actually say what your question is. Just saying that the code has "some issues" doesn't really help us to help you.
Some suggestions...
Use strict and warnings
Pass RaiseError as an argument to the connect call
Print out the contents of #row so you can be sure that the SQL is correct
Use Email::Simple to create your email and Email::Sender to send it
(Far less important) Consider using DBIx::Class to talk to the database
#!/usr/bin/perl
require '/main.cfg';
# use DBI interface for MySQL
use DBI;
# connect to MySQL
$dbh = DBI->connect($CFG{'mysql_dsn'},$CFG{'mysql_user'},$CFG{'mysql_password'}) or
&PrintError("Could not connect to the MySQL Database.\nFile could not be made!\n");
$dbh->{RaiseError} = 1; # save having to check each method call
$mailprog = $CFG{'mail_prog'};
$sql = "Select OS.name,OS.customer_email,OS.product,OS.salesperson_email from products AS P LEFT JOIN outofstock_sku AS OS ON OS.product = P.sku LEFT JOIN inventory AS I ON (I.sku = P.sku AND I.status = 'A') WHERE mail_sent='0' GROUP BY OS.product";
$sth = $dbh->prepare($sql);
$sth->execute();
while($ref = $sth->fetchrow_hashref())
{
open MAIL, "| $mailprog -f sssss\#gmail.com -t" || die "Could not connect to sendmail.";
print "Content-Type: text/html\n\n";
print MAIL "To: $ref->{'customer_email'}\n";
print MAIL "From: \"\" <wwwwwwwwww\n>";
# print MAIL "From: \"\" <$ref->{'salesperson_email'}\n>";
print MAIL "Reply-To: ";
# print MAIL "CC: $ref->{'salesperson_email'}\n";
print MAIL "Subject:#$ref->{'product'}\n";
print MAIL "Hi $ref->{'name'},\nThe product $ref->{'product'} is available in the stock.\n";
close MAIL;
}
$sth->finish();
# Close MySQL connection
$dbh->disconnect();
exit;