Регистрация  |  Вход

Merge two PDFs

Вот у меня спросили, а можно ли два аттача скрестить воедино?

string parentid = '';
List<Attachment> attachments = [select body from Attachment where parentid = :parentid];
Attachment attachmentPDF = new Attachment();
attachmentPdf.parentId = parentid;
attachmentPdf.name = 'all.pdf';
attachmentPdf.ContentType = 'pdf';
//list<string> unconverted = new List<String>();
string unconverted = '';
string pdfPageBreak = '\n<div id="pagebreak" style="page-break-before:always">&nbsp;</div>\n';
Blob pdfPageBreakEncoded = Blob.toPdf(pdfPageBreak);
for (Attachment att : attachments) {

string s = EncodingUtil.base64Encode(att.Body);
system.debug(s);
//blob b = EncodingUtil.base64Decode(s);
//system.debug(b);
unconverted += s + EncodingUtil.base64Encode(pdfPageBreakEncoded );
//unconverted.add(s + EncodingUtil.base64Encode(pdfPageBreakEncoded));
}

//attachmentPdf.body = blob.topdf('qwerty' + pdfPageBreak + 'asdf');
attachmentPdf.body = EncodingUtil.base64Decode(unconverted);
insert attachmentPDF;


Я развлекался как мог.
В итоге у меня получается содержимое только одного аттача.

Завтра буду пробовать сделать это с помощью Visualforce, выводя все аттачи на страницу, которая renderAs="PDF".

Вот у меня спросили, а можно ли два аттача скрестить воедино?
[code]
string parentid = '';
List<Attachment> attachments = [select body from Attachment where parentid = :parentid];
Attachment attachmentPDF = new Attachment();
attachmentPdf.parentId = parentid;
attachmentPdf.name = 'all.pdf';
attachmentPdf.ContentType = 'pdf';
//list<string> unconverted = new List<String>();
string unconverted = '';
string pdfPageBreak = '\n<div id="pagebreak" style="page-break-before:always">&nbsp;</div>\n';
Blob pdfPageBreakEncoded = Blob.toPdf(pdfPageBreak);
for (Attachment att : attachments) {
  
  string s = EncodingUtil.base64Encode(att.Body);
system.debug(s);
   //blob b = EncodingUtil.base64Decode(s);
//system.debug(b);
  unconverted += s + EncodingUtil.base64Encode(pdfPageBreakEncoded );
  //unconverted.add(s + EncodingUtil.base64Encode(pdfPageBreakEncoded));
}

//attachmentPdf.body = blob.topdf('qwerty' + pdfPageBreak + 'asdf');
attachmentPdf.body = EncodingUtil.base64Decode(unconverted);
insert attachmentPDF;
[/code]
Я развлекался как мог.
В итоге у меня получается содержимое только одного аттача.

Завтра буду пробовать сделать это с помощью Visualforce, выводя все аттачи на страницу, которая renderAs="PDF".

Andrii Muzychuk
Вот у меня спросили, а можно ли два аттача скрестить воедино?
string parentid = '';
List<Attachment> attachments = [select body from Attachment where parentid = :parentid];
Attachment attachmentPDF = new Attachment();
attachmentPdf.parentId = parentid;
attachmentPdf.name = 'all.pdf';
attachmentPdf.ContentType = 'pdf';
//list<string> unconverted = new List<String>();
string unconverted = '';
string pdfPageBreak = '\n<div id="pagebreak" style="page-break-before:always">&nbsp;</div>\n';
Blob pdfPageBreakEncoded = Blob.toPdf(pdfPageBreak);
for (Attachment att : attachments) {

string s = EncodingUtil.base64Encode(att.Body);
system.debug(s);
//blob b = EncodingUtil.base64Decode(s);
//system.debug(b);
unconverted += s + EncodingUtil.base64Encode(pdfPageBreakEncoded );
//unconverted.add(s + EncodingUtil.base64Encode(pdfPageBreakEncoded));
}

//attachmentPdf.body = blob.topdf('qwerty' + pdfPageBreak + 'asdf');
attachmentPdf.body = EncodingUtil.base64Decode(unconverted);
insert attachmentPDF;


Я развлекался как мог.
В итоге у меня получается содержимое только одного аттача.

Завтра буду пробовать сделать это с помощью Visualforce, выводя все аттачи на страницу, которая renderAs="PDF".


привет, скжи пожалуйста, получилось-таки у тебя это сделать?если да - то как?

[quote="Andrii Muzychuk"]Вот у меня спросили, а можно ли два аттача скрестить воедино?
[code]
string parentid = '';
List<Attachment> attachments = [select body from Attachment where parentid = :parentid];
Attachment attachmentPDF = new Attachment();
attachmentPdf.parentId = parentid;
attachmentPdf.name = 'all.pdf';
attachmentPdf.ContentType = 'pdf';
//list<string> unconverted = new List<String>();
string unconverted = '';
string pdfPageBreak = '\n<div id="pagebreak" style="page-break-before:always">&nbsp;</div>\n';
Blob pdfPageBreakEncoded = Blob.toPdf(pdfPageBreak);
for (Attachment att : attachments) {
  
  string s = EncodingUtil.base64Encode(att.Body);
system.debug(s);
   //blob b = EncodingUtil.base64Decode(s);
//system.debug(b);
  unconverted += s + EncodingUtil.base64Encode(pdfPageBreakEncoded );
  //unconverted.add(s + EncodingUtil.base64Encode(pdfPageBreakEncoded));
}

//attachmentPdf.body = blob.topdf('qwerty' + pdfPageBreak + 'asdf');
attachmentPdf.body = EncodingUtil.base64Decode(unconverted);
insert attachmentPDF;
[/code]
Я развлекался как мог.
В итоге у меня получается содержимое только одного аттача.

Завтра буду пробовать сделать это с помощью Visualforce, выводя все аттачи на страницу, которая renderAs="PDF".[/quote]


привет, скжи пожалуйста, получилось-таки у тебя это сделать?если да - то как?

Не подскажу. Не помню, чем дело закончилось.

Не подскажу. Не помню, чем дело закончилось.

Andrii Muzychuk
Не подскажу. Не помню, чем дело закончилось.

Думаю, что ничем не закончилось, если не использовать 3rd party сервисы :)

[quote="Andrii Muzychuk"]Не подскажу. Не помню, чем дело закончилось.[/quote]
Думаю, что ничем не закончилось, если не использовать 3rd party сервисы :)