Embed fonts

PDF-XChange Drivers API (only) V4/V5
This Forum is for the use of Software Developers requiring help and assistance for Tracker Software's PDF-XChange Printer Drivers SDK (only) - VERSION 4 & 5 - Please use the PDF-Tools SDK Forum for Library DLL assistance.

Moderators: TrackerSupp-Daniel, Tracker Support, Vasyl-Tracker Dev Team, Sean - Tracker, Chris - Tracker Supp, Tracker Supp-Stefan

Post Reply
HELID
User
Posts: 20
Joined: Wed Feb 24, 2010 11:40 am

Embed fonts

Post by HELID » Mon Oct 22, 2012 7:17 am

Hi!
I´m trying to embed fonts in a pdf-document but nothing happens. I have a registered version and I´ve tried in different ways to do this in my Delphi XE code:
InitPrinterSettings;
mPDFPrinter.Option['Save.File'] := sPathSaveAsPDF;
mPDFPrinter.Option['Paper.SheetSizeIndex'] := -2;
mPDFPrinter.Option['Paper.SheetWidth'] := 1480;
mPDFPrinter.Option['Paper.SheetHeight'] := 2100;
mPDFPrinter.Option['Fonts.AlwaysEmbed.Enable'] := 1;
mPDFPrinter.Option['Fonts.AlwaysEmbed.Fonts'] := 'Helvetica;Monospace821BT-Bold;Monospace821BT-Roman;';
// mPDFPrinter.Option['Fonts.EmbedAll'] := 1;

What can be wrong? I´ve also tried to embed fonts in the PDFXChange Viewer v 2.5 without success!!

I have attatched a file with the fonts I would like to Embed in my document, I can´t find the attatchment in my post, maybe you can see it?! Otherwise the fonts I would like to embed is: Helvetica;Helvetica-Bold;Monospace821BT-Bold;Monospace821BT-Roman;. I´ve opened a pdf-document with correctly embedded fonts with PDFXChange viewer. I choose the Document properties in the menu. Then I look in the fonts-category and there I´ve found the names of the fonts i would like to embed.

Best regards/
Helena Lidén

User avatar
Tracker Supp-Stefan
Site Admin
Posts: 14159
Joined: Mon Jan 12, 2009 8:07 am
Location: London
Contact:

Re: Embed fonts

Post by Tracker Supp-Stefan » Mon Oct 22, 2012 10:53 am

Hello Helena,

Please zip/rar any non PDF files you want to attach to the forums and try again.

Also is your source document utilizing those fonts you want to force to be embedded in the resulting PDF?
Maybe you could provide us a compilable sample showing your whole print routine?
(Please make sure to remove any licensing information from the project before uploading it in these public forums!)


Best,
Stefan

HELID
User
Posts: 20
Joined: Wed Feb 24, 2010 11:40 am

Re: Embed fonts

Post by HELID » Tue Oct 23, 2012 12:31 pm

Hi!
Here comes the code I use in Delphi XE. The constructor calls Initprinter. Then I call SavePDFAsPDFA5. The parameter to the function sPathPDF = the source pdf document with the fonts in the attachment. sPathSaveAsPDF = the filename of the pdf created by PDFXChange. I just want to use PDFXChange to get the source document in a different sheet size. The source document is an A4 and the output pdf created by PDFXChange is an A5.

procedure TGENPDFXChangePrinter.InitPrinter;
var
prnt : OleVariant;
begin
mPDFPFactory := CoCPXCControlEx.create;

if mPDFPFactory = nil then
begin
ShowMessage('PDF-XChange 4.0 SDK not installed or not properly registered. Application will quit.');
Halt(0);
end;
prnt := mPDFPFactory.Printer['', 'PDF-XChange 4.0', 'XXXXX-xxxxx-xxxxx-xxxxx-xxxxx-xxxxx', 'PDFX3XXXXXXXXXXXX'];
mPDFPrinter := IDispatch(prnt) as CPXCPrinter;

msPrinterName := mPDFPrinter.Name;
mbIsPXCPrinterDefault := False;

end;

procedure TGENPDFXChangePrinter.InitPrinterSettings;
begin
mPDFPrinter.SetAsDefaultPrinter;
mbIsPXCPrinterDefault := true;
mPDFPrinter.Option['Save.RunApp'] := false;
mPDFPrinter.Option['Save.SaveType'] := 'Save';
mPDFPrinter.Option['Save.ShowSaveDialog'] := 'No';
mPDFPrinter.Option['Save.WhenExists'] := 'Overwrite';
mPDFPrinter.Option['Compression.Graphics'] := 'No';
mPDFPrinter.Option['Compression.Text'] := 'No';
mPDFPrinter.Option['Saver.ShowProgress'] := True;
end;

function TGENPDFXChangePrinter.SavePDFAsPDFA5(sPathPDF: string; sPathSaveAsPDF: string): Boolean;
var
bCstatus : Boolean;
iWstatus : integer;
bTstatus : boolean;
bWait : boolean;
oInfo : TShellExecuteInfo;
opInfo : PShellExecuteInfo;
begin
InitPrinterSettings;
mPDFPrinter.Option['Save.File'] := sPathSaveAsPDF;
mPDFPrinter.Option['Paper.SheetSizeIndex'] := -2;
mPDFPrinter.Option['Paper.SheetWidth'] := 1480;
mPDFPrinter.Option['Paper.SheetHeight'] := 2100;
mPDFPrinter.Option['Fonts.AlwaysEmbed.Enable'] := 1;
mPDFPrinter.Option['Fonts.AlwaysEmbed.Fonts'] := 'Helvetica;Monospace821BT-Bold;Monospace821BT-Roman;';
// mPDFPrinter.Option['Fonts.EmbedAll'] := 1;


opInfo := @oInfo;
if FileExists(sPathPDF) then
begin
With oInfo do
begin
cbSize := SizeOf(oInfo);
Wnd := HWND(nil);
fMask := SEE_MASK_NOCLOSEPROCESS;
lpVerb := 'printto';
lpFile := PChar(sPathPDF);
lpParameters := Pchar('"' + msPrinterName + '"');
lpDirectory := nil;
nShow := SW_MINIMIZE;
hInstApp := 0;
end;
try
//Exekvera
bCstatus := ShellExecuteEx(opInfo);
iWstatus := WaitForSingleObject(oInfo.hProcess, INFINITE);
if iWstatus <> 0 then
begin
bTstatus := TerminateProcess(oInfo.hProcess, 11 ); // Terminera processen efter timeout i wait
if bTstatus then
begin
end
else
begin
bCstatus := False;
end;
end;
Result := bCstatus;
except
Result := false;
end;
end;
Attachments
Fonts.zip
Here is a sample of the font properties of the source document.
(31.89 KiB) Downloaded 215 times

Ivan - Tracker Software
Site Admin
Posts: 3630
Joined: Thu Jul 08, 2004 10:36 pm
Location: Vancouver Island - Canada
Contact:

Re: Embed fonts

Post by Ivan - Tracker Software » Tue Oct 23, 2012 10:24 pm

if you set

Code: Select all

mPDFPrinter.Option['Fonts.EmbedAll'] := 1;
the problem still exists? which application are you using for the printing? can you send us a sample PDF file where the fonts are not embedded ?
Tracker Software (Project Director)

When attaching files to any message - please ensure they are archived and posted as a .ZIP, .RAR or .7z format - or they will not be posted - thanks.

HELID
User
Posts: 20
Joined: Wed Feb 24, 2010 11:40 am

Re: Embed fonts

Post by HELID » Wed Oct 24, 2012 8:16 am

Hi!
Yes the problem still remains when I set
mPDFPrinter.Option['Fonts.EmbedAll'] := 1;

I attatch a sample of the source pdf which contains the fonts, the filename of this pdf is:
Katalog-Source document.pdf.

I also attatch a sample of the output pdf where the fonts from the source pdf is not embedded. This pdf is created by pdfxchangeprinter 4, the filename of this pdf is:
Katalog-Output document from PDFXChangePrinter.pdf.

Best regards/
Helena
Attachments
PDF.zip
(69.64 KiB) Downloaded 218 times

User avatar
Tracker Supp-Stefan
Site Admin
Posts: 14159
Joined: Mon Jan 12, 2009 8:07 am
Location: London
Contact:

Re: Embed fonts

Post by Tracker Supp-Stefan » Wed Oct 24, 2012 8:59 am

Hello Helena,

Thanks for the sample, but which is the application you are using to initiate the print of the original document? Is is e.g. our Viewer or Adobe's reader? If it's our Viewer - it will usually print fonts as curves - and that's why you end up with no fonts embedded in the result document.

Please test with e.g. a source MS Office Word document - and see if fonts are embedded in this case.

Best,
Stefan

HELID
User
Posts: 20
Joined: Wed Feb 24, 2010 11:40 am

Re: Embed fonts

Post by HELID » Wed Oct 24, 2012 10:46 am

Hello again!
The original pdf is created with Apache FOP 1.0 and it is saved to disk. In my application it is also poosible to save this pdf-document as an Image in our database. In the Delphi XE application we use a component named XPDFViewer for viewing or saving the original document to disk! The component XPDFViewer saves this pdf to disk and the pdf looks exactly as it did when Apache FOP 1.0 has created the pdf from the beginning.

I want to use your product for two reasons:
*Directly after Apache FOP 1.0 has saved the pdf to disk I would like to send this pdf document to the PDFXChange printer for changing only the sheet size of the document.
*And I want to use your product when I use our Delphi component XPDFViewer to save a pdf-file to disk. I would like to send the saved pdf document to PDFXChange printer for changing only the sheet size of the document.

I don´t understand what you mean with curves?? The PDFXChangeViewer can properly show the font-properties of the original document, why doesn´t curves become an issue here??

We use PDFXChange (Library dll functions) to add watermarks and insert pages to our pdf-files created by Apache FOP 1.0 and still the fonts remains embedded when we save the new pdf-file to disk.

I can see that the fonts are embedded with Adobe Acrobat Reader or PDFXChange Viewer.

Best regards/
Helena

User avatar
Tracker Supp-Stefan
Site Admin
Posts: 14159
Joined: Mon Jan 12, 2009 8:07 am
Location: London
Contact:

Re: Embed fonts

Post by Tracker Supp-Stefan » Wed Oct 24, 2012 12:31 pm

Hi Helena,

If I understand the scenario correctly - you do have a source PDF, you then open it with some application that can "print" it -> and using that application you pass it to our printing drivers where the watermarks and all is applied - and the result is a new PDF document with watermarks and all - but with the fonts from the original document missing.

So my question is how are you "printing" the original file to pass it to the drivers. If it's using our own Viewer - it will always print all embedded fonts as curves and optionally any non embedded fonts can also be passed as curves to the printing device.

Hence your initial fonts are lost - and only the font used for the watermarks is added in the "reprinted" PDF.

If you just want to e.g. resize the pages or add watermarks to them - it might be more convenient to use our PDF Tools SDK rather than the drivers APi if all your source files are going to be PDFs.

Best,
Stefan

HELID
User
Posts: 20
Joined: Wed Feb 24, 2010 11:40 am

Re: Embed fonts

Post by HELID » Wed Oct 24, 2012 1:22 pm

I don´t use any printer at all I use the PDFXChangeprinter only to SAVE the document with this code:
mPDFPrinter.Option['Save.SaveType'] := 'Save';
mPDFPrinter.Option['Save.ShowSaveDialog'] := 'No';
mPDFPrinter.Option['Save.WhenExists'] := 'Overwrite';

So in my application I press a button named SAVE. No printer involved except from your PDFXChangePrinter which I use for saving the document!!!

I don´t use your Viewer in my code!!

I would love to use your PDF Tools SDK instead of the printer. I didn´t think that the Library Dll contained any function that could do the following:
mPDFPrinter.Option['Paper.SheetSizeIndex'] := -2;
mPDFPrinter.Option['Paper.SheetWidth'] := 1480;
mPDFPrinter.Option['Paper.SheetHeight'] := 2100;

Could you please give me the codesamples??? I have looked in your PDF-ToolsV4SDK.chm. So I hope that you mean that I can use this PXCp-object to set the sheetSizeIndex, SheetWidth and SheetHeight!! I already use the PXCp_Watermark function in my code now!!

Best regards/
Helena

User avatar
Tracker Supp-Stefan
Site Admin
Posts: 14159
Joined: Mon Jan 12, 2009 8:07 am
Location: London
Contact:

Re: Embed fonts

Post by Tracker Supp-Stefan » Wed Oct 24, 2012 1:41 pm

Hi Helena,

You will need to "recreate" the PDF - on the desired page size - please check the PXCp_PlaceContents method.

Best,
Stefan

HELID
User
Posts: 20
Joined: Wed Feb 24, 2010 11:40 am

Re: Embed fonts

Post by HELID » Wed Nov 14, 2012 1:41 pm

Hello again!
I´m a bit confused over the suggestions I have recieved from you :) . I first posted a question on this forum with the subject A4 to A5. My post was:
I have a pdf-document with a sheet size named A4. I want to save this A4 to a sheet size A5 pdf-document. How do I manage this by using the lib-functions?

You responded like this:
The easiest solution would indeed be to "reprint" your pages to A5 sheets - and if you use our Viewer AX SDK, and the drivers API - you can automate the process with very little coding.

I did like this except of the fact that I couldn´t find the Viewer AX SDK but did a solution in my Delphi XE application by using the drivers API.

Then I started a new post in this forum with subject Embed fonts. The result of this discussion became
If you just want to e.g. resize the pages or add watermarks to them - it might be more convenient to use our PDF Tools SDK rather than the drivers APi if all your source files are going to be PDFs.

My first post was about how to resize the pages. And then your tip was to use the drivers API! So my solution is still using the driver API. But can you please help me to finish my mission by resizing a pdf-document in A4 to an A5. I have accepted the fact thad the embedding seems hard to make but I want my code to resize the pdf-document and then completely release the document!! The printer API function seems to hold the created document in A5. Even though I tell it to RunApp = False.

If the driver API can´t silently just resize my document and then release the document. Could you please give me a complete code example of how to do this with PDF Tools SDK instead.

Best Regards/
Helena

User avatar
Tracker Supp-Stefan
Site Admin
Posts: 14159
Joined: Mon Jan 12, 2009 8:07 am
Location: London
Contact:

Re: Embed fonts

Post by Tracker Supp-Stefan » Wed Nov 14, 2012 2:40 pm

Hi Helena,

The two topics were initially discussing different problems - and I've checked them with different members of our team - hence the different approaches and courses of replies.

I am now checking both topics simultaneously with the same person - and we will advise which is the best way to continue from here on taking all your needs in consideration.

Regards,
Stefan

User avatar
Tracker Supp-Stefan
Site Admin
Posts: 14159
Joined: Mon Jan 12, 2009 8:07 am
Location: London
Contact:

Re: Embed fonts

Post by Tracker Supp-Stefan » Wed Nov 14, 2012 5:55 pm

Hello Again Helena,

After speaking with my colleagues the consensus is that the better solution is for you to use our PDF Tools SDK - if annotations are NOT important, otherwise reprint is your only option (with fonts and/or text copying lost in the process).

If using the PDF Tools SDK is acceptable you must create PDF document with blank pages of the required size ant then use PXCp_PlaceContents to place contents from the existing file into the new smaller one.

Best,
Stefan

HELID
User
Posts: 20
Joined: Wed Feb 24, 2010 11:40 am

Re: Embed fonts

Post by HELID » Wed Nov 14, 2012 7:39 pm

Hi again!
Thank you for your reply!

If I understand you correctly you mean that I first initialize the pdf-document in A4 format. And then I create a new empty pdf document with sheets of the size of an A5. What function do I use to set the sheet size with the PDF Tools SDK??

I don´t understand how the content of the pdf document in A4-format is supposed to fit into the smaller sheets of A5-format?? How do I tell the place-content function that??

Have you tested this ?? Is it possible to get an example from you?? I suppose it´s not much code ?? :)

Best regards/
Helena

HELID
User
Posts: 20
Joined: Wed Feb 24, 2010 11:40 am

Re: Embed fonts

Post by HELID » Fri Nov 16, 2012 11:51 am

Hello again!
I have tried to use the placecontents function. I set the alignment flag to CPA_HorFit + CPA_VerFit. But the A4-pdf document doesn´t fit on the A5-pdf document. It doesn´t fit vertically or horizontal!

Can you please try to help me with this problem!

Best regards/
Helena

User avatar
Tracker Supp-Stefan
Site Admin
Posts: 14159
Joined: Mon Jan 12, 2009 8:07 am
Location: London
Contact:

Re: Embed fonts

Post by Tracker Supp-Stefan » Fri Nov 16, 2012 1:52 pm

Hello Helena,

I asked one of my colleagues from the dev team to take a look and he says that what you are doing should work.
Could you please attach a sample project and file (or at least a code snippet + sample) so that we can check this further?

Best,
Stefan

HELID
User
Posts: 20
Joined: Wed Feb 24, 2010 11:40 am

Re: Embed fonts

Post by HELID » Fri Nov 16, 2012 2:02 pm

Hello!
Thank you. I have solved this problem now. It was my dynamic array of PXCp_ContentPlaceInfo in Delphi XE that was the problem.

With my code I get an A5-pdf document from an A4 with embedded fonts. I´m very happy now :-)

Best regards/
Helena

User avatar
Tracker Supp-Stefan
Site Admin
Posts: 14159
Joined: Mon Jan 12, 2009 8:07 am
Location: London
Contact:

Re: Embed fonts

Post by Tracker Supp-Stefan » Fri Nov 16, 2012 2:06 pm

Glad to hear that Helena!
:)

Cheers,
Stefan

HELID
User
Posts: 20
Joined: Wed Feb 24, 2010 11:40 am

Re: Embed fonts

Post by HELID » Mon Nov 19, 2012 12:28 pm

Hi again!
My happiness didn´t last so long :?

I attach my code to you. The code in TGENProduceraUnit.pas is the code that calls the TGENPDFXChangeUnit.pas. I use Delphi XE.

The following line of code goes wrong now and then, in TGENPDFXChange.CreateWatermark:
pxRC := PXCp_AddWatermark(mhNewPDFDocument, @pxWatermark);.
I often get the errorcode -2113394928 that says that "the document cannot be read". This happens quite often but not always. What can be wrong?

The second problem is that pdfxchange still holds the created pdf-document. So when I try to execute the code in TGENProducera.CreateA6 twice it fails. In TGENPDFXChange.ResizePDFAsPDFA5 it goes wrong on the following line of code:
hr := PXC_WriteDocumentW(hPDFA5, PWChar(WideString(sPathSaveAsPDF)));
I get the errorcode -2081161184 and sometimes the code goes comletely wrong and I get an access violation in xcpro40.dll.
The hPDFA5 document is held by pdfxchange. So how do I properly release the pdf-document. As you can see in my code I both use functions in PXC_ and PXCP_. Write functions and Release seems to be handled differently?? How do I solve this?? I´m back to the problem that was with the PDFXChange printer which held the created document!!

Instead of writing the created hPDFA5 document to disk I first thought that I could use PXC_WriteDocumentToIStream. But this function didn´t exist? I think it only was a comment?!

As you can see in my code in TGENPDFXChange.ResizePDFAsPDFA5 I first have to use the PXC library to create a new document with empty pages and then to use the PXCp_PlaceContents function I have to read the same document again with the PXCP library. Is that the only way to solve my problem?? It seems like I cannot use PXC_NewDocument + PXC_AddPage and then use PXCp_WriteDocumentW?? They don´t work together, is that correct??

Best regards/
Helena
Attachments
Helena.zip
(4.5 KiB) Downloaded 181 times

User avatar
Tracker Supp-Stefan
Site Admin
Posts: 14159
Joined: Mon Jan 12, 2009 8:07 am
Location: London
Contact:

Re: Embed fonts

Post by Tracker Supp-Stefan » Mon Nov 19, 2012 1:22 pm

Hello Helena,

After checkign with my colleagues here's what we can advise:

PXC_ and PXCp_ functions cannot be mixed, so you must save the document after creation and than read it using the xcpro methods.
PXC_WriteDocumentToIStream exist in the pxclib40 library, but I am not sure if it is present in the samples (and the Delphi wrapper). However xcpro40 cannot read document from istream, so saving to disk is required.

Additionally - pxclib40 and xcpro40 have different file release mechanisms (pxclib40 requires a release after write, however it should not lock the destination document).
xcpro40 instead locks the document until it is released (automatically after successful save or manually via code)


Also we are not experts in Delphi (and don't know German), so if you experience further problems we will need a complete sample (with sources but serials removed), test file set and step-by-step instructions how to reproduce the problem.

Best,
Stefan

HELID
User
Posts: 20
Joined: Wed Feb 24, 2010 11:40 am

Re: Embed fonts

Post by HELID » Tue Nov 27, 2012 1:44 pm

Hi again!
Is it possible to watermark a document that has been created with the PXCp_PlaceContents method? I get an error every time I try to watermark.

Best regards/
Helena

User avatar
Tracker Supp-Stefan
Site Admin
Posts: 14159
Joined: Mon Jan 12, 2009 8:07 am
Location: London
Contact:

Re: Embed fonts

Post by Tracker Supp-Stefan » Tue Nov 27, 2012 2:51 pm

Hi Helena,

It definitely should be possible. Can we have a bit more information about the error you are getting when you try to watermark and maybe the code you are trying to use?

Also did you try to place watermark only - to check that the error is not in your code for adding the watermark rather than in interaction with PXCp_PlaceContents ?

Best,
Stefan

Post Reply